aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-08-26 12:53:41 -0700
committerTobias Bosch <tbosch@google.com>2019-08-26 20:54:57 +0000
commit5edca5060f78aa51cb2730051f78b9251b1d9d34 (patch)
tree0e0d32b7bfd554630d1a7c5fe003d2694284efaa /compiler_wrapper
parent42235709e88cbb239b9514d888919beb7c4a2c9e (diff)
downloadtoolchain-utils-5edca5060f78aa51cb2730051f78b9251b1d9d34.tar.gz
Only resolve cmd path against $PATH if path does not contain a folder.
BUG=chromium:773875 TEST=unit test Change-Id: I442afcfac00bcdbdfa33b739087af12987c57584 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1772176 Tested-by: Tobias Bosch <tbosch@google.com> Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper')
-rw-r--r--compiler_wrapper/clang_flags_test.go11
-rw-r--r--compiler_wrapper/compiler_wrapper.go4
-rw-r--r--compiler_wrapper/cros_hardened_config_test.go4
-rw-r--r--compiler_wrapper/testdata/cros_clang_host_golden/clang_path.json29
-rw-r--r--compiler_wrapper/testdata/cros_hardened_golden/clang_path.json45
-rw-r--r--compiler_wrapper/testdata/cros_hardened_noccache_golden/clang_path.json38
-rw-r--r--compiler_wrapper/testdata/cros_nonhardened_golden/clang_path.json38
7 files changed, 168 insertions, 1 deletions
diff --git a/compiler_wrapper/clang_flags_test.go b/compiler_wrapper/clang_flags_test.go
index 1d651194..72215386 100644
--- a/compiler_wrapper/clang_flags_test.go
+++ b/compiler_wrapper/clang_flags_test.go
@@ -66,6 +66,17 @@ func TestRelativeClangPathBasedOnRootPath(t *testing.T) {
})
}
+func TestRelativeClangPathWithDirBasedOnRootPath(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ ctx.cfg.rootRelPath = "somepath"
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand("test/x86_64-cros-linux-gnu-clang", mainCc)))
+ if err := verifyPath(cmd, "test/somepath/usr/bin/clang"); err != nil {
+ t.Error(err)
+ }
+ })
+}
+
func TestPathEnvClangPathBasedOnRootPath(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
ctx.cfg.rootRelPath = "somepath"
diff --git a/compiler_wrapper/compiler_wrapper.go b/compiler_wrapper/compiler_wrapper.go
index bbb7434c..c394b769 100644
--- a/compiler_wrapper/compiler_wrapper.go
+++ b/compiler_wrapper/compiler_wrapper.go
@@ -14,7 +14,9 @@ import (
func callCompiler(env env, cfg *config, inputCmd *command) int {
var compilerErr error
- if !filepath.IsAbs(inputCmd.Path) && !strings.HasPrefix(inputCmd.Path, ".") {
+
+ if !filepath.IsAbs(inputCmd.Path) && !strings.HasPrefix(inputCmd.Path, ".") &&
+ !strings.ContainsRune(inputCmd.Path, filepath.Separator) {
if resolvedPath, err := resolveAgainstPathEnv(env, inputCmd.Path); err == nil {
inputCmd = &command{
Path: resolvedPath,
diff --git a/compiler_wrapper/cros_hardened_config_test.go b/compiler_wrapper/cros_hardened_config_test.go
index 0cf995e0..9d5f700a 100644
--- a/compiler_wrapper/cros_hardened_config_test.go
+++ b/compiler_wrapper/cros_hardened_config_test.go
@@ -297,6 +297,10 @@ func createClangPathGoldenInputs(ctx *testContext, gomaEnv string) goldenFile {
Cmds: okResults,
},
{
+ WrapperCmd: newGoldenCmd("somedir/x86_64-cros-linux-gnu-clang", mainCc),
+ Cmds: okResults,
+ },
+ {
Env: []string{"PATH=" + filepath.Join(ctx.tempDir, "/pathenv")},
WrapperCmd: newGoldenCmd("x86_64-cros-linux-gnu-clang", mainCc),
Cmds: okResults,
diff --git a/compiler_wrapper/testdata/cros_clang_host_golden/clang_path.json b/compiler_wrapper/testdata/cros_clang_host_golden/clang_path.json
index ddd4ae9b..668415f1 100644
--- a/compiler_wrapper/testdata/cros_clang_host_golden/clang_path.json
+++ b/compiler_wrapper/testdata/cros_clang_host_golden/clang_path.json
@@ -345,6 +345,35 @@
},
{
"wd": "/tmp/stable",
+ "wrapper": {
+ "cmd": {
+ "path": "somedir/x86_64-cros-linux-gnu-clang",
+ "args": [
+ "main.cc"
+ ]
+ }
+ },
+ "cmds": [
+ {
+ "cmd": {
+ "path": "/tmp/stable/somedir/clang",
+ "args": [
+ "-Qunused-arguments",
+ "-grecord-gcc-switches",
+ "-fno-addrsig",
+ "-Wno-unused-local-typedefs",
+ "-Wno-deprecated-declarations",
+ "-Wno-tautological-constant-compare",
+ "-Wno-tautological-unsigned-enum-zero-compare",
+ "-Wno-unknown-warning-option",
+ "main.cc"
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "wd": "/tmp/stable",
"env": [
"PATH=/tmp/stable/pathenv"
],
diff --git a/compiler_wrapper/testdata/cros_hardened_golden/clang_path.json b/compiler_wrapper/testdata/cros_hardened_golden/clang_path.json
index 944ccbb9..d9754fe7 100644
--- a/compiler_wrapper/testdata/cros_hardened_golden/clang_path.json
+++ b/compiler_wrapper/testdata/cros_hardened_golden/clang_path.json
@@ -499,6 +499,51 @@
},
{
"wd": "/tmp/stable",
+ "wrapper": {
+ "cmd": {
+ "path": "somedir/x86_64-cros-linux-gnu-clang",
+ "args": [
+ "main.cc"
+ ]
+ }
+ },
+ "cmds": [
+ {
+ "cmd": {
+ "path": "/usr/bin/ccache",
+ "args": [
+ "../../usr/bin/clang",
+ "--sysroot=/usr/x86_64-cros-linux-gnu",
+ "-Qunused-arguments",
+ "-grecord-gcc-switches",
+ "-fno-addrsig",
+ "-Wno-tautological-constant-compare",
+ "-Wno-tautological-unsigned-enum-zero-compare",
+ "-Wno-unknown-warning-option",
+ "-Wno-section",
+ "-static-libgcc",
+ "-fstack-protector-strong",
+ "-fPIE",
+ "-pie",
+ "-D_FORTIFY_SOURCE=2",
+ "-fno-omit-frame-pointer",
+ "main.cc",
+ "-B../../bin",
+ "-target",
+ "x86_64-cros-linux-gnu"
+ ],
+ "env_updates": [
+ "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu",
+ "CCACHE_DIR=/var/cache/distfiles/ccache",
+ "CCACHE_UMASK=002",
+ "CCACHE_CPP2=yes"
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "wd": "/tmp/stable",
"env": [
"PATH=/tmp/stable/pathenv"
],
diff --git a/compiler_wrapper/testdata/cros_hardened_noccache_golden/clang_path.json b/compiler_wrapper/testdata/cros_hardened_noccache_golden/clang_path.json
index 5f193151..b1517675 100644
--- a/compiler_wrapper/testdata/cros_hardened_noccache_golden/clang_path.json
+++ b/compiler_wrapper/testdata/cros_hardened_noccache_golden/clang_path.json
@@ -436,6 +436,44 @@
},
{
"wd": "/tmp/stable",
+ "wrapper": {
+ "cmd": {
+ "path": "somedir/x86_64-cros-linux-gnu-clang",
+ "args": [
+ "main.cc"
+ ]
+ }
+ },
+ "cmds": [
+ {
+ "cmd": {
+ "path": "../../usr/bin/clang",
+ "args": [
+ "--sysroot=/usr/x86_64-cros-linux-gnu",
+ "-Qunused-arguments",
+ "-grecord-gcc-switches",
+ "-fno-addrsig",
+ "-Wno-tautological-constant-compare",
+ "-Wno-tautological-unsigned-enum-zero-compare",
+ "-Wno-unknown-warning-option",
+ "-Wno-section",
+ "-static-libgcc",
+ "-fstack-protector-strong",
+ "-fPIE",
+ "-pie",
+ "-D_FORTIFY_SOURCE=2",
+ "-fno-omit-frame-pointer",
+ "main.cc",
+ "-B../../bin",
+ "-target",
+ "x86_64-cros-linux-gnu"
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "wd": "/tmp/stable",
"env": [
"PATH=/tmp/stable/pathenv"
],
diff --git a/compiler_wrapper/testdata/cros_nonhardened_golden/clang_path.json b/compiler_wrapper/testdata/cros_nonhardened_golden/clang_path.json
index 5a489f07..2a30100c 100644
--- a/compiler_wrapper/testdata/cros_nonhardened_golden/clang_path.json
+++ b/compiler_wrapper/testdata/cros_nonhardened_golden/clang_path.json
@@ -429,6 +429,44 @@
},
{
"wd": "/tmp/stable",
+ "wrapper": {
+ "cmd": {
+ "path": "somedir/x86_64-cros-linux-gnu-clang",
+ "args": [
+ "main.cc"
+ ]
+ }
+ },
+ "cmds": [
+ {
+ "cmd": {
+ "path": "/usr/bin/ccache",
+ "args": [
+ "../../usr/bin/clang",
+ "--sysroot=/usr/x86_64-cros-linux-gnu",
+ "-Qunused-arguments",
+ "-Wno-tautological-constant-compare",
+ "-Wno-tautological-unsigned-enum-zero-compare",
+ "-Wno-unknown-warning-option",
+ "-Wno-section",
+ "-static-libgcc",
+ "main.cc",
+ "-B../../bin",
+ "-target",
+ "x86_64-cros-linux-gnu"
+ ],
+ "env_updates": [
+ "CCACHE_BASEDIR=/usr/x86_64-cros-linux-gnu",
+ "CCACHE_DIR=/var/cache/distfiles/ccache",
+ "CCACHE_UMASK=002",
+ "CCACHE_CPP2=yes"
+ ]
+ }
+ }
+ ]
+ },
+ {
+ "wd": "/tmp/stable",
"env": [
"PATH=/tmp/stable/pathenv"
],