]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: escape $WORK in ccompile when -n is set
authorGrigoriyMikhalkin <grigoriymikhalkin@gmail.com>
Wed, 26 Feb 2020 15:02:36 +0000 (15:02 +0000)
committerBryan C. Mills <bcmills@google.com>
Wed, 26 Feb 2020 15:51:45 +0000 (15:51 +0000)
Fixes #37012

Change-Id: I169807788c022042a2b5cf04f67ae41a7325fbcf
GitHub-Last-Rev: 9e77301c7ab3125a6f21f2c9cd998503976a5d5d
GitHub-Pull-Request: golang/go#37289
Reviewed-on: https://go-review.googlesource.com/c/go/+/219919
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/script/build_n_cgo.txt [new file with mode: 0644]

index 1bba3a5329fc8b734e73c247f15c3fd4f21af349..70f3c7b27e026f978518549e7e81cdc54ce7bad5 100644 (file)
@@ -2129,9 +2129,8 @@ func (b *Builder) gfortran(a *Action, p *load.Package, workdir, out string, flag
 func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []string, file string, compiler []string) error {
        file = mkAbs(p.Dir, file)
        desc := p.ImportPath
-       if !filepath.IsAbs(outfile) {
-               outfile = filepath.Join(p.Dir, outfile)
-       }
+       outfile = mkAbs(p.Dir, outfile)
+
        output, err := b.runOut(a, filepath.Dir(file), b.cCompilerEnv(), compiler, flags, "-o", outfile, "-c", filepath.Base(file))
        if len(output) > 0 {
                // On FreeBSD 11, when we pass -g to clang 3.8 it
diff --git a/src/cmd/go/testdata/script/build_n_cgo.txt b/src/cmd/go/testdata/script/build_n_cgo.txt
new file mode 100644 (file)
index 0000000..200d137
--- /dev/null
@@ -0,0 +1,13 @@
+[!cgo] skip
+
+# Test that nothing is prepended to $WORK path prefix.
+# See issue golang.org/issue/37012.
+go build -n
+! stderr '[/\\]\$WORK'
+
+-- main.go --
+package main
+
+import "C"
+
+var _ C.int