[Buildroot] [PATCH v3 1/1] toolchain: handle toolchains with multiple ld*.so.* files
Arnout Vandecappelle
arnout at mind.be
Mon Aug 30 09:12:07 UTC 2021
On 30/08/2021 10:45, Yann E. MORIN wrote:
> Jonah, All,
>
> On 2021-08-29 20:25 -0400, Jonah Petri spake thusly:
>> On 8/29/21 1:21 PM, Arnout Vandecappelle wrote:
>>> On 26/08/2021 21:34, Jonah Petri wrote:
>>>> fi ; \
>>>> - if [ ! -e $(STAGING_DIR)/lib/ld*.so.* ]; then \
>>>> - if [ -e $${ARCH_SYSROOT_DIR}/lib/ld*.so.* ]; then \
>>>> - cp -a $${ARCH_SYSROOT_DIR}/lib/ld*.so.* $(STAGING_DIR)/lib/ ; \
>>>> - fi ; \
>>>> + if [[ ! $$(find $(STAGING_DIR)/lib -name 'ld*.so.*' -print -quit) ]]; then \
>>> I was going to say: don't use [[, it's a bashism. However, we already use it in
>>> helpers.mk, so I guess it's OK. It's up to whoever has a problem with it to get
>>> rid of it :-)
>
> He! Don't say such things when I'm around! ;-)
>
>>> Therefore, applied to next, thanks.
>>
>> Thanks! I found it surprisingly hard to find a pleasing shell answer to
>> "does this command succeed *and* output anything to stdout?" without
>> invoking bashisms.
>
> This is a bit less concise (two lines instead of one), but it's still
> pretty easy, e.g. with a script that does not use 'set -e':
>
> output="$( some-command )"
> if [ ${?} -ne 0 -o -z "${output}" ]; then
> echo "Failed or output nothing"
> fi
If you want concise (and covering all set -e cases AFAICS):
if ! output="$(some-command)" || [ -z "$output" ]; then ...
(as always: untested, YMMV)
Regards,
Arnout
>
> If the script is using 'set -e', or one needs to differentiate the
> reason for failure, then it is a bit more involved, but still pretty
> easy and common:
>
> output="$( some-command )" || ret="${?}"
> if [ ${ret:-0} -ne 0 -o -z "${output}" ]; then
> echo "Exited with ${ret:-0}, or output nothing"
> fi
>
> In our case, for Buildroot, we'd need to adapt the first solution:
>
> [...] ; \
> output="$$( some-command )"; \
> if [ $${?} -ne 0 -o -z "$${output}" ]; then \
> echo "Failed or output nothing"; \
> fi; \
> [...]
>
>> I too was wary of using [[ before I saw the same usage
>> lower in the file,
>
> You caught me red-handed... I added that back in 4a5f878946c37... ;-]
>
>> and noted that bash is a prerequisite for buildroot in
>> general.
>
> And even then, I like that we avoid bashisms when possible. But in this
> case, well, it's acceptable and applied, so I won't whine (much). ;-)
>
>> Hopefully some future dev won't curse me too much ☺ Thanks for
>> applying!
>
> Well, TIL that one can do [[ ! $(cmd) ]] to test output and return code
> in one line, so... Thanks! :-)
>
> Regards,
> Yann E. MORIN.
>
More information about the buildroot
mailing list