aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-10-11 11:26:36 -0700
committerManoj Gupta <manojgupta@chromium.org>2019-10-11 18:56:28 +0000
commit6ecb3475254b6ab7ab3be6a2f58abc2f2fdd3da8 (patch)
tree73874c62dcf685c5f28989db135ea19984b2c09d
parentf40d1b4761c07826176d3075148ee21ce75da465 (diff)
downloadtoolchain-utils-6ecb3475254b6ab7ab3be6a2f58abc2f2fdd3da8.tar.gz
compiler_wrapper: Replace UserHomeDir uses.
os.UserHomeDir is not available in the Go version in Cros SDK. Replace by explicit env value of "HOME". BUG=None TEST=go test Change-Id: Ia0da2d9bce042510fcc1b14cb074dadfe4d0f2f2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1856381 Commit-Queue: Manoj Gupta <manojgupta@chromium.org> Reviewed-by: George Burgess <gbiv@chromium.org> Reviewed-by: Tobias Bosch <tbosch@google.com> Tested-by: Manoj Gupta <manojgupta@chromium.org> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
-rw-r--r--compiler_wrapper/bisect_flag.go8
-rw-r--r--compiler_wrapper/bisect_flag_test.go5
-rw-r--r--compiler_wrapper/cros_hardened_config_test.go3
-rw-r--r--compiler_wrapper/goldenutil_test.go5
-rw-r--r--compiler_wrapper/testdata/android_golden/bisect.json11
-rw-r--r--compiler_wrapper/testdata/cros_clang_host_golden/bisect.json9
-rw-r--r--compiler_wrapper/testdata/cros_hardened_golden/bisect.json9
-rw-r--r--compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json9
-rw-r--r--compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json9
-rw-r--r--compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json9
10 files changed, 48 insertions, 29 deletions
diff --git a/compiler_wrapper/bisect_flag.go b/compiler_wrapper/bisect_flag.go
index 62bcbd31..6271e23f 100644
--- a/compiler_wrapper/bisect_flag.go
+++ b/compiler_wrapper/bisect_flag.go
@@ -5,7 +5,7 @@
package main
import (
- "os"
+ "errors"
"path/filepath"
)
@@ -41,9 +41,9 @@ func calcBisectCommand(env env, cfg *config, bisectStage string, compilerCmd *co
bisectDir, _ := env.getenv("BISECT_DIR")
if bisectDir == "" {
if cfg.isAndroidWrapper {
- homeDir, err := os.UserHomeDir()
- if err != nil {
- return nil, err
+ homeDir, ok := env.getenv("HOME")
+ if !ok {
+ return nil, errors.New("$HOME is not set")
}
bisectDir = filepath.Join(homeDir, "ANDROID_BISECT")
} else {
diff --git a/compiler_wrapper/bisect_flag_test.go b/compiler_wrapper/bisect_flag_test.go
index 43c3095b..8500eef2 100644
--- a/compiler_wrapper/bisect_flag_test.go
+++ b/compiler_wrapper/bisect_flag_test.go
@@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
- "os"
"path/filepath"
"strings"
"testing"
@@ -83,12 +82,12 @@ func TestDefaultBisectDirAndroid(t *testing.T) {
withBisectTestContext(t, func(ctx *testContext) {
ctx.env = []string{
"BISECT_STAGE=someBisectStage",
+ "HOME=/somehome",
}
ctx.cfg.isAndroidWrapper = true
cmd := mustCallBisectDriver(ctx, callCompiler(ctx, ctx.cfg, ctx.newCommand(gccX86_64, mainCc)))
- userHome, _ := os.UserHomeDir()
if err := verifyArgOrder(cmd,
- "someBisectStage", filepath.Join(userHome, "ANDROID_BISECT")); err != nil {
+ "someBisectStage", filepath.Join("/somehome", "ANDROID_BISECT")); err != nil {
t.Error(err)
}
})
diff --git a/compiler_wrapper/cros_hardened_config_test.go b/compiler_wrapper/cros_hardened_config_test.go
index c3881303..16e51358 100644
--- a/compiler_wrapper/cros_hardened_config_test.go
+++ b/compiler_wrapper/cros_hardened_config_test.go
@@ -196,6 +196,7 @@ func createBisectGoldenInputs(compiler string) goldenFile {
WrapperCmd: newGoldenCmd(compiler, mainCc),
Env: []string{
"BISECT_STAGE=someBisectStage",
+ "HOME=/user/home",
},
Cmds: okResults,
},
@@ -204,6 +205,7 @@ func createBisectGoldenInputs(compiler string) goldenFile {
Env: []string{
"BISECT_STAGE=someBisectStage",
"BISECT_DIR=someBisectDir",
+ "HOME=/user/home",
},
Cmds: okResults,
},
@@ -212,6 +214,7 @@ func createBisectGoldenInputs(compiler string) goldenFile {
Env: []string{
"BISECT_STAGE=someBisectStage",
"BISECT_DIR=someBisectDir",
+ "HOME=/user/home",
},
Cmds: errorResults,
},
diff --git a/compiler_wrapper/goldenutil_test.go b/compiler_wrapper/goldenutil_test.go
index 0bb2b11c..4eff8738 100644
--- a/compiler_wrapper/goldenutil_test.go
+++ b/compiler_wrapper/goldenutil_test.go
@@ -175,11 +175,10 @@ func fillGoldenResults(ctx *testContext, files []goldenFile) []goldenFile {
func writeGoldenRecords(ctx *testContext, writer io.Writer, records []goldenRecord) {
// Replace the temp dir with a stable path so that the goldens stay stable.
stableTempDir := filepath.Join(filepath.Dir(ctx.tempDir), "stable")
- homeDir, _ := os.UserHomeDir()
writer = &replacingWriter{
Writer: writer,
- old: [][]byte{[]byte(ctx.tempDir), []byte(homeDir)},
- new: [][]byte{[]byte(stableTempDir), []byte("$HOME")},
+ old: [][]byte{[]byte(ctx.tempDir)},
+ new: [][]byte{[]byte(stableTempDir)},
}
enc := json.NewEncoder(writer)
enc.SetIndent("", " ")
diff --git a/compiler_wrapper/testdata/android_golden/bisect.json b/compiler_wrapper/testdata/android_golden/bisect.json
index 41310ca1..a24222ab 100644
--- a/compiler_wrapper/testdata/android_golden/bisect.json
+++ b/compiler_wrapper/testdata/android_golden/bisect.json
@@ -2,7 +2,8 @@
{
"wd": "/tmp/stable",
"env": [
- "BISECT_STAGE=someBisectStage"
+ "BISECT_STAGE=someBisectStage",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -21,7 +22,7 @@
"-c",
"\nimport bisect_driver\nimport shlex\nimport sys\n\ndef ExpandArgs(args, target):\n\tfor arg in args:\n\t\tif arg[0] == '@':\n\t\t\twith open(arg[1:], 'rb') as f:\n\t\t\t\tExpandArgs(shlex.split(f.read()), target)\n\t\telse:\n\t\t\ttarget.append(arg)\n\treturn target\n\nstage = sys.argv[1]\ndir = sys.argv[2]\nexecargs = ExpandArgs(sys.argv[3:], [])\n\nsys.exit(bisect_driver.bisect_driver(stage, dir, execargs))\n",
"someBisectStage",
- "$HOME/ANDROID_BISECT",
+ "/user/home/ANDROID_BISECT",
"/tmp/stable/clang.real",
"main.cc"
]
@@ -33,7 +34,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -64,7 +66,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
diff --git a/compiler_wrapper/testdata/cros_clang_host_golden/bisect.json b/compiler_wrapper/testdata/cros_clang_host_golden/bisect.json
index 5a67a635..b9b1509f 100644
--- a/compiler_wrapper/testdata/cros_clang_host_golden/bisect.json
+++ b/compiler_wrapper/testdata/cros_clang_host_golden/bisect.json
@@ -2,7 +2,8 @@
{
"wd": "/tmp/stable",
"env": [
- "BISECT_STAGE=someBisectStage"
+ "BISECT_STAGE=someBisectStage",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -42,7 +43,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -82,7 +84,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
diff --git a/compiler_wrapper/testdata/cros_hardened_golden/bisect.json b/compiler_wrapper/testdata/cros_hardened_golden/bisect.json
index e0709e04..f9a503f3 100644
--- a/compiler_wrapper/testdata/cros_hardened_golden/bisect.json
+++ b/compiler_wrapper/testdata/cros_hardened_golden/bisect.json
@@ -2,7 +2,8 @@
{
"wd": "/tmp/stable",
"env": [
- "BISECT_STAGE=someBisectStage"
+ "BISECT_STAGE=someBisectStage",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -58,7 +59,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -114,7 +116,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
diff --git a/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json b/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json
index 905a8692..56b7b3ed 100644
--- a/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json
+++ b/compiler_wrapper/testdata/cros_hardened_llvmnext_golden/bisect.json
@@ -2,7 +2,8 @@
{
"wd": "/tmp/stable",
"env": [
- "BISECT_STAGE=someBisectStage"
+ "BISECT_STAGE=someBisectStage",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -63,7 +64,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -124,7 +126,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
diff --git a/compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json b/compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json
index c8255e56..f3061817 100644
--- a/compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json
+++ b/compiler_wrapper/testdata/cros_hardened_noccache_golden/bisect.json
@@ -2,7 +2,8 @@
{
"wd": "/tmp/stable",
"env": [
- "BISECT_STAGE=someBisectStage"
+ "BISECT_STAGE=someBisectStage",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -51,7 +52,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -100,7 +102,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
diff --git a/compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json b/compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json
index d81622fd..4bc696d3 100644
--- a/compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json
+++ b/compiler_wrapper/testdata/cros_nonhardened_golden/bisect.json
@@ -2,7 +2,8 @@
{
"wd": "/tmp/stable",
"env": [
- "BISECT_STAGE=someBisectStage"
+ "BISECT_STAGE=someBisectStage",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -50,7 +51,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {
@@ -98,7 +100,8 @@
"wd": "/tmp/stable",
"env": [
"BISECT_STAGE=someBisectStage",
- "BISECT_DIR=someBisectDir"
+ "BISECT_DIR=someBisectDir",
+ "HOME=/user/home"
],
"wrapper": {
"cmd": {