mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Richard Purdie <richard.purdie@linuxfoundation.org>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Michal Marek <michal.lkml@markovi.net>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 3/3] kbuild: use bash as the default shell for Make and Kconfig
Date: Fri, 19 Aug 2022 15:56:03 +0900	[thread overview]
Message-ID: <20220819065604.295572-4-masahiroy@kernel.org> (raw)
In-Reply-To: <20220819065604.295572-1-masahiroy@kernel.org>

GNU Make uses /bin/sh by default for running recipe lines and $(shell ),
and so does Kconfig for $(shell,...).

We are sometimes hit by subtle portability issues like [1] because the
code was only tested on systems where /bin/sh is a symlink to bash.

One way is to continue whack-a-mole game as somebody will eventually
notice that the code is not working on their build environments.

Another is a big hammer approach; force bash in the build system so that
it works in the same way for everyone. In fact, there exists such a
guideline that permits only Bash as the shell scripting language. [2]
The kbuild test robot also specifies SHELL=/bin/bash to eliminate the
shell portability issue.

This commit changes the shell for Make and Kconfig to bash. As the GNU
Make manual [3] says, the 'SHELL' is never set from the environment.
You cannot do 'export SHELL:=/bin/bash' to propagate it to sub-makes.
Instead, use MAKEOVERRIDES to make SHELL:=/bin/bash globally effective.

[1]: https://lore.kernel.org/all/20220804190320.262510-1-alexandre.belloni@bootlin.com/
[2]: https://google.github.io/styleguide/shellguide.html
[3]: https://www.gnu.org/software/make/manual/html_node/Choosing-the-Shell.html

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile                | 7 +++++++
 scripts/Kconfig.include | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/Makefile b/Makefile
index f09673b6c11d..cc01987560b3 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,13 @@ __all:
 
 ifneq ($(sub_make_done),1)
 
+# Use /bin/bash for repices and $(shell ) invocations.
+SHELL := /bin/bash
+
+# Unlike the other variables, the 'SHELL' is never set from the environment.
+# Use MAKEOVERRIDES to pass 'SHELL' down to sub-makes.
+MAKEOVERRIDES += SHELL=$(SHELL)
+
 # Do not use make's built-in rules and variables
 # (this increases performance and avoids hard-to-debug behaviour)
 MAKEFLAGS += -rR
diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index a0ccceb22cf8..d37b864ba1f2 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0-only
 # Kconfig helper macros
 
+# Use /bin/bash to evaluate $(shell,) functions
+SHELL := /bin/bash
+
 # Convenient variables
 comma       := ,
 quote       := "
-- 
2.34.1


      parent reply	other threads:[~2022-08-19  6:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-19  6:56 [RFC PATCH 0/3] kbuild: change the default shell to bash Masahiro Yamada
2022-08-19  6:56 ` [RFC PATCH 1/3] kconfig: move declarations for prepossessing to internal.h Masahiro Yamada
2022-08-19  6:56 ` [RFC PATCH 2/3] kconfig: allow to choose the shell for $(shell ) functions Masahiro Yamada
2022-08-19  8:58   ` Bagas Sanjaya
2022-08-19 21:37     ` David Laight
2022-08-19  6:56 ` Masahiro Yamada [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220819065604.295572-4-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=ndesaulniers@google.com \
    --cc=rdunlap@infradead.org \
    --cc=richard.purdie@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome