From 57bb5081d7a901fafb33f0314b4f955db2e84191 Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Thu, 1 Apr 2021 15:51:56 -0700 Subject: [PATCH] Always use /bin/sh to run the command. SHELL environment variable cannot be relied on because the rbcrun can be run as `env - rbcrun ...` Fixes: 184278019 Test: build/soong/soong_ui.bash --make-mode USE_BAZEL=1 TARGET_PRODUCT=aosp_arm64 TARGET_BUILD_VARIANT=userdebug droid dist platform_tests Change-Id: Id8fc7fd1ae8f2e674028ba5ffb3616f87eea6bc4 --- tools/rbcrun/host.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/rbcrun/host.go b/tools/rbcrun/host.go index f1697f1f3b..1e433346a3 100644 --- a/tools/rbcrun/host.go +++ b/tools/rbcrun/host.go @@ -182,7 +182,7 @@ func shell(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, } if shellPath == "" { return starlark.None, - fmt.Errorf("cannot run shell, SHELL environment variable is not set (running on Windows?)") + fmt.Errorf("cannot run shell, /bin/sh is missing (running on Windows?)") } cmd := exec.Command(shellPath, "-c", command) // We ignore command's status @@ -234,8 +234,12 @@ func setup(env []string) { "rblf_wildcard": starlark.NewBuiltin("rblf_wildcard", wildcard), } - // NOTE(asmundak): OS-specific. - shellPath, _ = os.LookupEnv("SHELL") + // NOTE(asmundak): OS-specific. Behave similar to Linux `system` call, + // which always uses /bin/sh to run the command + shellPath = "/bin/sh" + if _, err := os.Stat(shellPath); err != nil { + shellPath = "" + } } // Parses, resolves, and executes a Starlark file.