From: GrigoriyMikhalkin Date: Wed, 26 Feb 2020 15:02:36 +0000 (+0000) Subject: cmd/go: escape $WORK in ccompile when -n is set X-Git-Tag: go1.15beta1~1048 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8992f7c4597dcc60b91e8b088fb31b49b9b55496;p=gostls13.git cmd/go: escape $WORK in ccompile when -n is set 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 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 1bba3a5329..70f3c7b27e 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -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 index 0000000000..200d13760e --- /dev/null +++ b/src/cmd/go/testdata/script/build_n_cgo.txt @@ -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