Skip to contentSkip to conversation

kbuild: Add a space after `!` to prevent parsing as file pattern

PATCH In review Michael Forney 2 participants 2 messages Aug 16, 2018 – Aug 17, 2018 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: Add a space after `!` to prevent parsing as file pattern

Some shells use !(pattern|...|pattern) to match file names not containing the specified patterns. This may result in output like

  $ ./scripts/clang-version.sh gcc
  ./scripts/clang-version.sh[18]: COPYING: not found
  printf: %d __clang_major__: conversion error
  printf: %d __clang_minor__: conversion error
  printf: %d __clang_patchlevel__: conversion error
  00000
  $

and set CONFIG_CLANG_VERSION to the invalid value '00000'.

POSIX says[0]

If the pipeline begins with the reserved word ! and command1 is a subshell command, the application shall ensure that the ( operator at the beginning of command1 is separated from the ! by one or more <blank> characters. The behavior of the reserved word ! immediately followed by the ( operator is unspecified.

So, just add a <blank> to prevent this.

[0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_02

---
 scripts/clang-version.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/clang-version.sh +1 -1
index dbf0a31eb111..e65fbc3079d4 100755
@@ -12,7 +12,7 @@
 
 compiler="$*"
 
-if !( $compiler --version | grep -q clang) ; then
+if ! ( $compiler --version | grep -q clang) ; then
 	echo 0
 	exit 1
 fi
Signature · 1 line
2.17.1
#1 lore raw

2018-08-16 9:13 GMT+09:00 Michael Forney <[email protected]>:

Quoted 21 lines

Some shells use !(pattern|...|pattern) to match file names not containing the specified patterns. This may result in output like

  $ ./scripts/clang-version.sh gcc
  ./scripts/clang-version.sh[18]: COPYING: not found
  printf: %d __clang_major__: conversion error
  printf: %d __clang_minor__: conversion error
  printf: %d __clang_patchlevel__: conversion error
  00000
  $

and set CONFIG_CLANG_VERSION to the invalid value '00000'.

POSIX says[0]

If the pipeline begins with the reserved word ! and command1 is a subshell command, the application shall ensure that the ( operator at the beginning of command1 is separated from the ! by one or more <blank> characters. The behavior of the reserved word ! immediately followed by the ( operator is unspecified.

Quoted 5 lines

So, just add a <blank> to prevent this.

[0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_02

Applied to linux-kbuild. Thanks!

Quoted 20 lines
---
 scripts/clang-version.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/clang-version.sh +1 -2
index dbf0a31eb111..e65fbc3079d4 100755
@@ -12,7 +12,7 @@
 
 compiler="$*"
 
-if !( $compiler --version | grep -q clang) ; then
+if ! ( $compiler --version | grep -q clang) ; then
        echo 0
        exit 1
 fi
--

2.17.1

Signature · 2 lines
Best Regards
Masahiro Yamada