aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-09-30 10:37:42 -0700
committerTobias Bosch <tbosch@google.com>2019-09-30 23:21:03 +0000
commitc58f8d5cfbfc7a9561963af92017a9d3dbdcb61d (patch)
tree2e524107444d938f1e98c588bf96c2ba29ecdc30 /compiler_wrapper
parent606ae84584e61b0a1f47ed5de2cbaaaad1393712 (diff)
downloadtoolchain-utils-c58f8d5cfbfc7a9561963af92017a9d3dbdcb61d.tar.gz
Android wrapper: Add support for --gomacc-path.
This is used by Android. To keep the wrappers in sync, we also support it on ChromeOS. BUG=chromium:773875 TEST=golden tests and comparison against old andorid wrapper. Change-Id: I02d7456ead1c94327eb6810aeef4d106596518ec Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1831789 Reviewed-by: George Burgess <gbiv@chromium.org> Tested-by: Tobias Bosch <tbosch@google.com>
Diffstat (limited to 'compiler_wrapper')
-rw-r--r--compiler_wrapper/android_config_test.go13
-rw-r--r--compiler_wrapper/compiler_wrapper.go34
-rw-r--r--compiler_wrapper/gomacc_flag.go30
-rw-r--r--compiler_wrapper/gomacc_flag_test.go44
-rw-r--r--compiler_wrapper/testdata/android_golden/clang_path.json24
5 files changed, 130 insertions, 15 deletions
diff --git a/compiler_wrapper/android_config_test.go b/compiler_wrapper/android_config_test.go
index 67a3b0f6..fddde817 100644
--- a/compiler_wrapper/android_config_test.go
+++ b/compiler_wrapper/android_config_test.go
@@ -5,6 +5,7 @@
package main
import (
+ "path"
"path/filepath"
"testing"
)
@@ -29,6 +30,10 @@ func TestAndroidConfig(t *testing.T) {
}
func createAndroidClangPathGoldenInputs(ctx *testContext) goldenFile {
+ gomaPath := path.Join(ctx.tempDir, "gomacc")
+ ctx.writeFile(gomaPath, "")
+ defaultPath := filepath.Join(ctx.tempDir, "clang")
+
deepPath := "a/b/c/d/e/f/g/clang"
linkedDeepPath := "symlinked/clang_other"
ctx.writeFile(filepath.Join(ctx.tempDir, "/pathenv/clang"), "")
@@ -37,11 +42,11 @@ func createAndroidClangPathGoldenInputs(ctx *testContext) goldenFile {
Name: "clang_path.json",
Records: []goldenRecord{
{
- WrapperCmd: newGoldenCmd(filepath.Join(ctx.tempDir, "clang"), mainCc),
+ WrapperCmd: newGoldenCmd(defaultPath, mainCc),
Cmds: okResults,
},
{
- WrapperCmd: newGoldenCmd(filepath.Join(ctx.tempDir, "clang"), mainCc),
+ WrapperCmd: newGoldenCmd(defaultPath, mainCc),
Cmds: errorResults,
},
{
@@ -61,6 +66,10 @@ func createAndroidClangPathGoldenInputs(ctx *testContext) goldenFile {
WrapperCmd: newGoldenCmd("clang", mainCc),
Cmds: okResults,
},
+ {
+ WrapperCmd: newGoldenCmd(defaultPath, mainCc, "--gomacc-path", gomaPath),
+ Cmds: okResults,
+ },
},
}
}
diff --git a/compiler_wrapper/compiler_wrapper.go b/compiler_wrapper/compiler_wrapper.go
index 899a85c8..09ef41d0 100644
--- a/compiler_wrapper/compiler_wrapper.go
+++ b/compiler_wrapper/compiler_wrapper.go
@@ -85,7 +85,9 @@ func callCompilerInternal(env env, cfg *config, inputCmd *command) (exitCode int
return 0, err
}
}
- processGomaCCacheFlags(sysroot, allowCCache, mainBuilder)
+ if err := processGomaCCacheFlags(sysroot, allowCCache, mainBuilder); err != nil {
+ return 0, err
+ }
compilerCmd = mainBuilder.build()
} else {
if clangSyntax {
@@ -94,10 +96,16 @@ func callCompilerInternal(env env, cfg *config, inputCmd *command) (exitCode int
if err != nil {
return 0, err
}
- gccCmd := calcGccCommand(mainBuilder)
+ gccCmd, err := calcGccCommand(mainBuilder)
+ if err != nil {
+ return 0, err
+ }
return checkClangSyntax(env, clangCmd, gccCmd)
}
- compilerCmd = calcGccCommand(mainBuilder)
+ compilerCmd, err = calcGccCommand(mainBuilder)
+ if err != nil {
+ return 0, err
+ }
}
rusageLogfileName := getRusageLogFilename(env)
bisectStage := getBisectStage(env)
@@ -142,11 +150,13 @@ func calcClangCommand(allowCCache bool, builder *commandBuilder) (*command, erro
if err != nil {
return nil, err
}
- processGomaCCacheFlags(sysroot, allowCCache, builder)
+ if err := processGomaCCacheFlags(sysroot, allowCCache, builder); err != nil {
+ return nil, err
+ }
return builder.build(), nil
}
-func calcGccCommand(builder *commandBuilder) *command {
+func calcGccCommand(builder *commandBuilder) (*command, error) {
sysroot := ""
if !builder.cfg.isHostWrapper {
sysroot = processSysrootFlag(builder)
@@ -158,9 +168,11 @@ func calcGccCommand(builder *commandBuilder) *command {
processGccFlags(builder)
if !builder.cfg.isHostWrapper {
allowCCache := true
- processGomaCCacheFlags(sysroot, allowCCache, builder)
+ if err := processGomaCCacheFlags(sysroot, allowCCache, builder); err != nil {
+ return nil, err
+ }
}
- return builder.build()
+ return builder.build(), nil
}
func calcCommonPreUserArgs(builder *commandBuilder) {
@@ -176,14 +188,18 @@ func calcCommonPreUserArgs(builder *commandBuilder) {
}
}
-func processGomaCCacheFlags(sysroot string, allowCCache bool, builder *commandBuilder) {
+func processGomaCCacheFlags(sysroot string, allowCCache bool, builder *commandBuilder) (err error) {
gomaccUsed := false
if !builder.cfg.isHostWrapper {
- gomaccUsed = processGomaCccFlags(builder)
+ gomaccUsed, err = processGomaCccFlags(builder)
+ if err != nil {
+ return err
+ }
}
if !gomaccUsed && allowCCache {
processCCacheFlag(sysroot, builder)
}
+ return nil
}
func getAbsWrapperPath(env env, wrapperCmd *command) (string, error) {
diff --git a/compiler_wrapper/gomacc_flag.go b/compiler_wrapper/gomacc_flag.go
index bdcd92ee..ac298b12 100644
--- a/compiler_wrapper/gomacc_flag.go
+++ b/compiler_wrapper/gomacc_flag.go
@@ -8,12 +8,34 @@ import (
"os"
)
-func processGomaCccFlags(builder *commandBuilder) (gomaUsed bool) {
- if gomaPath, _ := builder.env.getenv("GOMACC_PATH"); gomaPath != "" {
+func processGomaCccFlags(builder *commandBuilder) (gomaUsed bool, err error) {
+ gomaPath := ""
+ nextArgIsGomaPath := false
+ builder.transformArgs(func(arg builderArg) string {
+ if arg.fromUser {
+ if arg.value == "--gomacc-path" {
+ nextArgIsGomaPath = true
+ return ""
+ }
+ if nextArgIsGomaPath {
+ gomaPath = arg.value
+ nextArgIsGomaPath = false
+ return ""
+ }
+ }
+ return arg.value
+ })
+ if nextArgIsGomaPath {
+ return false, newUserErrorf("--gomacc-path given without value")
+ }
+ if gomaPath == "" {
+ gomaPath, _ = builder.env.getenv("GOMACC_PATH")
+ }
+ if gomaPath != "" {
if _, err := os.Lstat(gomaPath); err == nil {
builder.wrapPath(gomaPath)
- return true
+ return true, nil
}
}
- return false
+ return false, nil
}
diff --git a/compiler_wrapper/gomacc_flag_test.go b/compiler_wrapper/gomacc_flag_test.go
index 92df66ea..d7b2b0b7 100644
--- a/compiler_wrapper/gomacc_flag_test.go
+++ b/compiler_wrapper/gomacc_flag_test.go
@@ -39,6 +39,50 @@ func TestOmitGomaccIfEnvIsGivenButInvalid(t *testing.T) {
})
}
+func TestCallGomaccIfArgIsGivenAndValid(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ gomaPath := path.Join(ctx.tempDir, "gomacc")
+ // Create a file so the gomacc path is valid.
+ ctx.writeFile(gomaPath, "")
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand(gccX86_64, mainCc, "--gomacc-path", gomaPath)))
+ if err := verifyPath(cmd, gomaPath); err != nil {
+ t.Error(err)
+ }
+ if err := verifyArgCount(cmd, 0, "--gomacc-path"); err != nil {
+ t.Error(err)
+ }
+ if err := verifyArgCount(cmd, 0, gomaPath); err != nil {
+ t.Error(err)
+ }
+ if err := verifyArgOrder(cmd, gccX86_64+".real", mainCc); err != nil {
+ t.Error(err)
+ }
+ })
+}
+
+func TestOmitGomaccIfArgIsGivenButInvalid(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ // Note: This path does not point to a valid file.
+ gomaPath := path.Join(ctx.tempDir, "gomacc")
+ cmd := ctx.must(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand(gccX86_64, mainCc, "--gomacc-path", gomaPath)))
+ if err := verifyPath(cmd, gccX86_64+".real"); err != nil {
+ t.Error(err)
+ }
+ })
+}
+
+func TestErrorOnGomaccArgWithoutValue(t *testing.T) {
+ withTestContext(t, func(ctx *testContext) {
+ stderr := ctx.mustFail(callCompiler(ctx, ctx.cfg,
+ ctx.newCommand(gccX86_64, mainCc, "--gomacc-path")))
+ if err := verifyNonInternalError(stderr, "--gomacc-path given without value"); err != nil {
+ t.Error(err)
+ }
+ })
+}
+
func TestOmitGomaccByDefault(t *testing.T) {
withTestContext(t, func(ctx *testContext) {
cmd := ctx.must(callCompiler(ctx, ctx.cfg,
diff --git a/compiler_wrapper/testdata/android_golden/clang_path.json b/compiler_wrapper/testdata/android_golden/clang_path.json
index 2928bf89..cab712b5 100644
--- a/compiler_wrapper/testdata/android_golden/clang_path.json
+++ b/compiler_wrapper/testdata/android_golden/clang_path.json
@@ -133,5 +133,29 @@
}
}
]
+ },
+ {
+ "wd": "/tmp/stable",
+ "wrapper": {
+ "cmd": {
+ "path": "/tmp/stable/clang",
+ "args": [
+ "main.cc",
+ "--gomacc-path",
+ "/tmp/stable/gomacc"
+ ]
+ }
+ },
+ "cmds": [
+ {
+ "cmd": {
+ "path": "/tmp/stable/gomacc",
+ "args": [
+ "/tmp/stable/clang.real",
+ "main.cc"
+ ]
+ }
+ }
+ ]
}
]