Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v3 1/1] toolchain: handle toolchains with multiple ld*.so.* files
@ 2021-08-26 19:34 Jonah Petri
  2021-08-29 17:21 ` Arnout Vandecappelle
  0 siblings, 1 reply; 5+ messages in thread
From: Jonah Petri @ 2021-08-26 19:34 UTC (permalink / raw)
  To: buildroot
  Cc: Thomas Petazzoni, Giulio Benetti, Jonah Petri, Romain Naour,
	Thomas De Schampheleire

Some 3rd party vendor toolchains have multiple files which match
these glob patterns.  In this case, the shell script failed.
Switching to use find and xargs solves the issue.

Signed-off-by: Jonah Petri <jonah@petri.us>
---
Changes:
  v2: add SOB
  v3: fix usage of `find`
    I moved away from -wholename, which seemed needlessly complex, and
instead I'm using just the base directory and -name.  Tested with
previously-failing ARM aarch64 external toolchain build.

 toolchain/helpers.mk | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
index dfb2581ed5..cb9ff6479b 100644
--- a/toolchain/helpers.mk
+++ b/toolchain/helpers.mk
@@ -135,10 +135,8 @@ copy_toolchain_sysroot = \
 			$(call simplify_symlink,$$i,$(STAGING_DIR)) ; \
 		done ; \
 	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 \
+		find $${ARCH_SYSROOT_DIR}/lib -name 'ld*.so.*' -print0 | xargs -0 -I % cp % $(STAGING_DIR)/lib/; \
 	fi ; \
 	if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \
 		if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \
-- 
2.30.2

_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Buildroot] [PATCH v3 1/1] toolchain: handle toolchains with multiple ld*.so.* files
  2021-08-26 19:34 [Buildroot] [PATCH v3 1/1] toolchain: handle toolchains with multiple ld*.so.* files Jonah Petri
@ 2021-08-29 17:21 ` Arnout Vandecappelle
  2021-08-30  0:25   ` Jonah Petri
  0 siblings, 1 reply; 5+ messages in thread
From: Arnout Vandecappelle @ 2021-08-29 17:21 UTC (permalink / raw)
  To: Jonah Petri, buildroot
  Cc: Thomas De Schampheleire, Giulio Benetti, Romain Naour,
	Thomas Petazzoni



On 26/08/2021 21:34, Jonah Petri wrote:
> Some 3rd party vendor toolchains have multiple files which match
> these glob patterns.  In this case, the shell script failed.
> Switching to use find and xargs solves the issue.
> 
> Signed-off-by: Jonah Petri <jonah@petri.us>
> ---
> Changes:
>   v2: add SOB
>   v3: fix usage of `find`
>     I moved away from -wholename, which seemed needlessly complex, and
> instead I'm using just the base directory and -name.  Tested with
> previously-failing ARM aarch64 external toolchain build.
> 
>  toolchain/helpers.mk | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/toolchain/helpers.mk b/toolchain/helpers.mk
> index dfb2581ed5..cb9ff6479b 100644
> --- a/toolchain/helpers.mk
> +++ b/toolchain/helpers.mk
> @@ -135,10 +135,8 @@ copy_toolchain_sysroot = \
>  			$(call simplify_symlink,$$i,$(STAGING_DIR)) ; \
>  		done ; \
>  	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 :-)

 Therefore, applied to next, thanks.

 Regards,
 Arnout

> +		find $${ARCH_SYSROOT_DIR}/lib -name 'ld*.so.*' -print0 | xargs -0 -I % cp % $(STAGING_DIR)/lib/; \
>  	fi ; \
>  	if [ `readlink -f $${SYSROOT_DIR}` != `readlink -f $${ARCH_SYSROOT_DIR}` ] ; then \
>  		if [ ! -d $${ARCH_SYSROOT_DIR}/usr/include ] ; then \
> 
_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Buildroot] [PATCH v3 1/1] toolchain: handle toolchains with multiple ld*.so.* files
  2021-08-29 17:21 ` Arnout Vandecappelle
@ 2021-08-30  0:25   ` Jonah Petri
  2021-08-30  8:45     ` Yann E. MORIN
  0 siblings, 1 reply; 5+ messages in thread
From: Jonah Petri @ 2021-08-30  0:25 UTC (permalink / raw)
  To: Arnout Vandecappelle, buildroot
  Cc: Thomas De Schampheleire, Giulio Benetti, Romain Naour,
	Thomas Petazzoni


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 :-)
>
>   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.  I too was wary of using [[ before I saw the same 
usage lower in the file, and noted that bash is a prerequisite for 
buildroot in general.  Hopefully some future dev won't curse me too much 
☺ Thanks for applying!

_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Buildroot] [PATCH v3 1/1] toolchain: handle toolchains with multiple ld*.so.* files
  2021-08-30  0:25   ` Jonah Petri
@ 2021-08-30  8:45     ` Yann E. MORIN
  2021-08-30  9:12       ` Arnout Vandecappelle
  0 siblings, 1 reply; 5+ messages in thread
From: Yann E. MORIN @ 2021-08-30  8:45 UTC (permalink / raw)
  To: Jonah Petri
  Cc: Thomas Petazzoni, buildroot, Giulio Benetti, Romain Naour,
	Thomas De Schampheleire

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 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.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Buildroot] [PATCH v3 1/1] toolchain: handle toolchains with multiple ld*.so.* files
  2021-08-30  8:45     ` Yann E. MORIN
@ 2021-08-30  9:12       ` Arnout Vandecappelle
  0 siblings, 0 replies; 5+ messages in thread
From: Arnout Vandecappelle @ 2021-08-30  9:12 UTC (permalink / raw)
  To: Yann E. MORIN, Jonah Petri
  Cc: Thomas Petazzoni, Giulio Benetti, Romain Naour,
	Thomas De Schampheleire, buildroot



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.
> 
_______________________________________________
buildroot mailing list
buildroot@busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-30  9:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-26 19:34 [Buildroot] [PATCH v3 1/1] toolchain: handle toolchains with multiple ld*.so.* files Jonah Petri
2021-08-29 17:21 ` Arnout Vandecappelle
2021-08-30  0:25   ` Jonah Petri
2021-08-30  8:45     ` Yann E. MORIN
2021-08-30  9:12       ` Arnout Vandecappelle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox