Skip to contentSkip to conversation

Avoid misleading error output caused by missing shell quotes

PATCH New Jens Stimpfle 3 participants 5 messages Nov 12, 2014 – Dec 8, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Avoid misleading error output caused by missing shell quotes

---

Notes:
When g++ is not installed, a misleading error message turns up because of a bad combination of an unquoted shell variable and control flow.

> ~/buildroot$ make
>
> You may have to install 'g++' on your build machine
> /home/testuser/buildroot/support/dependencies/dependencies.sh: 136: [: -lt: unexpected operator

This is a nonintrusive workaround.

 support/dependencies/dependencies.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
support/dependencies/dependencies.sh +2 -2
index a9c5b31..4b8991d 100755
@@ -118,7 +118,6 @@ CXXCOMPILER=$(which $HOSTCXX_NOCCACHE 2> /dev/null)
 if [ -z "$CXXCOMPILER" ] ; then
 	CXXCOMPILER=$(which c++ 2> /dev/null)
 fi
-
 if [ -z "$CXXCOMPILER" ] ; then
 	echo
 	echo "You may have to install 'g++' on your build machine"
@@ -130,7 +129,8 @@ if [ ! -z "$CXXCOMPILER" ] ; then
 		echo
 		echo "You may have to install 'g++' on your build machine"
 	fi
-
+fi
+if [ ! -z "$CXXCOMPILER_VERSION" ] ; then
 	CXXCOMPILER_MAJOR=$(echo $CXXCOMPILER_VERSION | sed -e "s/\..*//g")
 	CXXCOMPILER_MINOR=$(echo $CXXCOMPILER_VERSION | sed -e "s/^$CXXCOMPILER_MAJOR\.//g" -e "s/\..*//g")
 	if [ $CXXCOMPILER_MAJOR -lt 3 -o $CXXCOMPILER_MAJOR -eq 2 -a $CXXCOMPILER_MINOR -lt 95 ] ; then
Signature · 1 line
2.1.1
#1 lore raw

PATCH 2/2 Unclutter standard error output while feature testing for 32 bit gcc

---

Notes:
The screen is cluttered when we build for 32bit target and 32bit gcc missing.

> ~/buildroot$ make
>
> You may have to install 'g++' on your build machine
> /home/testuser/buildroot/support/dependencies/dependencies.sh: 136: [: -lt: unexpected operator > /usr/bin/ld: cannot find crt1.o: No such file or directory
> /usr/bin/ld: cannot find crti.o: No such file or directory
> /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc.a when searching for -lgcc > /usr/bin/ld: cannot find -lgcc
> /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_s.so when searching for -lgcc_s > /usr/bin/ld: cannot find -lgcc_s
> /usr/bin/ld: cannot find -lc
> /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc.a when searching for -lgcc > /usr/bin/ld: cannot find -lgcc
> /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_s.so when searching for -lgcc_s > /usr/bin/ld: cannot find -lgcc_s
> /usr/bin/ld: cannot find crtn.o: No such file or directory
> collect2: error: ld returned 1 exit status
>
> Your Buildroot configuration needs a compiler capable of building 32 bits binaries.
[...]

The final note is enough, and adding 2>/dev/null to the gcc test invocation is also more consistent with the rest of the script. The patch makes the /usr/bin/ld: and collect2: lines go away.

 support/dependencies/dependencies.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
support/dependencies/dependencies.sh +1 -1
index 4b8991d..dcf37f0 100755
@@ -222,7 +222,7 @@ if grep -q ^BR2_HOSTARCH_NEEDS_IA32_LIBS=y $BR2_CONFIG ; then
 fi
 
 if grep -q ^BR2_HOSTARCH_NEEDS_IA32_COMPILER=y $BR2_CONFIG ; then
-	if ! echo "int main(void) {}" | gcc -m32 -x c - -o /dev/null ; then
+	if ! echo "int main(void) {}" | gcc -m32 -x c - -o /dev/null 2>/dev/null; then
 		echo
 		echo "Your Buildroot configuration needs a compiler capable of building 32 bits binaries."
 		echo "If you're running a Debian/Ubuntu distribution, install the gcc-multilib package."
Signature · 1 line
2.1.1
#2 lore raw

PATCH 2/2 Unclutter standard error output while feature testing for 32 bit gcc

Jens, All,

On 2014-11-12 13:31 +0000, Jens Stimpfle spake thusly:

Quoted 25 lines

---

Notes:
The screen is cluttered when we build for 32bit target and 32bit gcc missing.

> ~/buildroot$ make
>
> You may have to install 'g++' on your build machine
> /home/testuser/buildroot/support/dependencies/dependencies.sh: 136: [: -lt: unexpected operator > /usr/bin/ld: cannot find crt1.o: No such file or directory
> /usr/bin/ld: cannot find crti.o: No such file or directory
> /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc.a when searching for -lgcc > /usr/bin/ld: cannot find -lgcc
> /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_s.so when searching for -lgcc_s > /usr/bin/ld: cannot find -lgcc_s
> /usr/bin/ld: cannot find -lc
> /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc.a when searching for -lgcc > /usr/bin/ld: cannot find -lgcc
> /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc_s.so when searching for -lgcc_s > /usr/bin/ld: cannot find -lgcc_s
> /usr/bin/ld: cannot find crtn.o: No such file or directory
> collect2: error: ld returned 1 exit status
>

Quoted 6 lines

> Your Buildroot configuration needs a compiler capable of building 32 bits binaries. [...]

The final note is enough, and adding 2>/dev/null to the gcc test invocation is also more consistent with the rest of the script. The patch makes the /usr/bin/ld: and collect2: lines go away.

Ditto, keep those explanations in the commit log.

Otherwise, looks good.

We're in feature-freeze for the upcoming release at the end of the month, but I think thos changes could go in. Will you resubmit those patches soon, so they can get applied before the release?

Regards,
Yann E. MORIN.

Quoted 23 lines
 support/dependencies/dependencies.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
support/dependencies/dependencies.sh +1 -1
index 4b8991d..dcf37f0 100755
@@ -222,7 +222,7 @@ if grep -q ^BR2_HOSTARCH_NEEDS_IA32_LIBS=y $BR2_CONFIG ; then
 fi
 
 if grep -q ^BR2_HOSTARCH_NEEDS_IA32_COMPILER=y $BR2_CONFIG ; then
-	if ! echo "int main(void) {}" | gcc -m32 -x c - -o /dev/null ; then
+	if ! echo "int main(void) {}" | gcc -m32 -x c - -o /dev/null 2>/dev/null; then
 		echo
 		echo "Your Buildroot configuration needs a compiler capable of building 32 bits binaries."
 		echo "If you're running a Debian/Ubuntu distribution, install the gcc-multilib package."
Signature · 6 lines
2.1.1

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#3 lore raw

PATCH 1/2 Avoid misleading error output caused by missing shell quotes

In reply to Jens Stimpfle

Jens, All,

On 2014-11-12 13:31 +0000, Jens Stimpfle spake thusly:

Quoted 11 lines

---

Notes:
When g++ is not installed, a misleading error message turns up because of a bad combination of an unquoted shell variable and control flow.

> ~/buildroot$ make
>
> You may have to install 'g++' on your build machine
> /home/testuser/buildroot/support/dependencies/dependencies.sh: 136: [: -lt: unexpected operator

This should have been part of the commit log, above your Signed-off-by line.

Whatever is after the --- line is ignored by git when a patch is applied, but the information you provide is interesting and we want to keep it in the logs.

What about changing your commit log to:

support: avoid spurious error output when checking dependencies

When g++ is not installed, a misleading error message turns up because of a bad combination of an unquoted shell variable and control flow.

$ ~/buildroot$ make
You may have to install 'g++' on your build machine /home/testuser/buildroot/support/dependencies/dependencies.sh: 136: [: -lt: unexpected operator

Signed-off-by You

Otherwise, the change looks sane, but see below...

Quoted 10 lines

This is a nonintrusive workaround.

 support/dependencies/dependencies.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
support/dependencies/dependencies.sh +0 -0
index a9c5b31..4b8991d 100755

support/dependencies/dependencies.sh CXXCOMPILER=$(which $HOSTCXX_NOCCACHE 2> /dev/null) · line 121

Quoted 4 lines
support/dependencies/dependencies.sh +0 -1
@@ -118,7 +118,6 @@ CXXCOMPILER=$(which $HOSTCXX_NOCCACHE 2> /dev/null)
 if [ -z "$CXXCOMPILER" ] ; then
 	CXXCOMPILER=$(which c++ 2> /dev/null)
 fi
-

Spurious empty line removal. Please keep it.

support/dependencies/dependencies.sh if [ ! -z "$CXXCOMPILER" ] ; then · line 133

Quoted 10 lines
support/dependencies/dependencies.sh +2 -1
 if [ -z "$CXXCOMPILER" ] ; then
 	echo
 	echo "You may have to install 'g++' on your build machine"
@@ -130,7 +129,8 @@ if [ ! -z "$CXXCOMPILER" ] ; then
 		echo
 		echo "You may have to install 'g++' on your build machine"
 	fi
-
+fi
+if [ ! -z "$CXXCOMPILER_VERSION" ] ; then

I'd like it if there was an empty line after the 'fi' and before the 'if'.

Also, we prefer positive logic:

if [ -n "$CXXCOMPILER_VERSION" ] ; then

Regards,
Yann E. MORIN.

Quoted 10 lines
support/dependencies/dependencies.sh +0 -0
 	CXXCOMPILER_MAJOR=$(echo $CXXCOMPILER_VERSION | sed -e "s/\..*//g")
 	CXXCOMPILER_MINOR=$(echo $CXXCOMPILER_VERSION | sed -e "s/^$CXXCOMPILER_MAJOR\.//g" -e "s/\..*//g")
 	if [ $CXXCOMPILER_MAJOR -lt 3 -o $CXXCOMPILER_MAJOR -eq 2 -a $CXXCOMPILER_MINOR -lt 95 ] ; then
Signature · 6 lines
2.1.1

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#4 lore raw

PATCH 1/2 Avoid misleading error output caused by missing shell quotes

In reply to Jens Stimpfle

Dear Jens Stimpfle,

Quoted 1 line · Jens Stimpfle

Thanks, both patches applied, with several fixes to the commit log and code, as suggested by Yann E. Morin. See:

http://git.buildroot.net/buildroot/commit/?id=d1607dc7dfc2c5397ff6b67ebd18d25c6184f650
http://git.buildroot.net/buildroot/commit/?id=94c6417e703d7cd923d50e4974ad555a377ffa02

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com