diff options
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" ], |