aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid du Colombier <0intro@gmail.com>2016-06-01 15:13:55 +0200
committerDavid du Colombier <0intro@gmail.com>2016-06-01 13:33:43 +0000
commite29e0ba19af26c30c95b59aeda482e60ae594113 (patch)
tree846af8d0bf052d6bfe181d7a43850decc74a8e68
parentbd2dc2d819b85beb8887466a165242e2d540e4b9 (diff)
downloadgo-e29e0ba19af26c30c95b59aeda482e60ae594113.tar.gz
go-e29e0ba19af26c30c95b59aeda482e60ae594113.zip
cmd/compile: fix TestAssembly on Plan 9
Since CL 23620, TestAssembly is failing on Plan 9. In CL 23620, the process environment is passed to 'go tool compile' after setting GOARCH. On Plan 9, if GOARCH is already set in the process environment, it would take precedence. On Unix, it works as expected because the first GOARCH found takes precedence. This change uses the mergeEnvLists function from cmd/go/main.go to merge the two environment lists such that variables with the same name in "in" replace those in "out". Change-Id: Idee22058343932ee18666dda331c562c89c33507 Reviewed-on: https://go-review.googlesource.com/23593 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: David du Colombier <0intro@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/cmd/compile/internal/gc/asm_test.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/gc/asm_test.go b/src/cmd/compile/internal/gc/asm_test.go
index 73d2e336d2..b44bf77c5d 100644
--- a/src/cmd/compile/internal/gc/asm_test.go
+++ b/src/cmd/compile/internal/gc/asm_test.go
@@ -61,7 +61,7 @@ func compileToAsm(dir, arch, pkg string) string {
var stdout, stderr bytes.Buffer
cmd := exec.Command("go", "tool", "compile", "-S", "-o", filepath.Join(dir, "out.o"), src)
- cmd.Env = append([]string{"GOARCH=" + arch}, os.Environ()...)
+ cmd.Env = mergeEnvLists([]string{"GOARCH=" + arch}, os.Environ())
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
@@ -103,3 +103,22 @@ func f(x int) int {
[]string{"\tSHLQ\t\\$5,", "\tLEAQ\t\\(.*\\)\\(.*\\*2\\),"},
},
}
+
+// mergeEnvLists merges the two environment lists such that
+// variables with the same name in "in" replace those in "out".
+// This always returns a newly allocated slice.
+func mergeEnvLists(in, out []string) []string {
+ out = append([]string(nil), out...)
+NextVar:
+ for _, inkv := range in {
+ k := strings.SplitAfterN(inkv, "=", 2)[0]
+ for i, outkv := range out {
+ if strings.HasPrefix(outkv, k) {
+ out[i] = inkv
+ continue NextVar
+ }
+ }
+ out = append(out, inkv)
+ }
+ return out
+}