Reviewers: Rob Pike
Russ Cox uploaded a change:
https://go-review.googlesource.com/3351
cmd/go: add build flag -toolexec
Like the -exec flag, which specifies a program to use to run a built
executable,
the -toolexec flag specifies a program to use to run a tool like 5a, 5g, or
5l.
This flag enables running the toolchain under common testing environments,
such as valgrind.
This flag also enables the use of custom testing environments or the
substitution
of alternate tools. See
https://godoc.org/rsc.io/toolstash for one
possibility.
Change-Id: I256aa7af2d96a4bc7911dc58151cc2155dbd4121
---
M src/cmd/go/build.go
M src/cmd/go/doc.go
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go
index e201f29..86c5ee9 100644
--- a/src/cmd/go/build.go
+++ b/src/cmd/go/build.go
@@ -93,6 +93,10 @@
a list of build tags to consider satisfied during the build.
For more information about build tags, see the description of
build constraints in the documentation for the go/build package.
+ -toolexec 'cmd args'
+ a program to use to invoke toolchain programs like 5a, 5g, and 5l.
+ For example, instead of running 5g, the go command will run
+ 'cmd args /path/to/5g <arguments for 5g>'.
The list flags accept a space-separated list of strings. To embed spaces
in an element in the list, surround it with either single or double quotes.
@@ -131,6 +135,7 @@
var buildLdflags []string // -ldflags flag
var buildGccgoflags []string // -gccgoflags flag
var buildRace bool // -race flag
+var buildToolExec []string // -toolexec flag
var buildContext = build.Default
var buildToolchain toolchain = noToolchain{}
@@ -184,6 +189,7 @@
cmd.Flag.Var((*stringsFlag)(&buildContext.BuildTags), "tags", "")
cmd.Flag.Var(buildCompiler{}, "compiler", "")
cmd.Flag.BoolVar(&buildRace, "race", false, "")
+ cmd.Flag.Var((*stringsFlag)(&buildToolExec), "toolexec", "")
}
func addBuildFlagsNX(cmd *Command) {
@@ -1657,7 +1663,7 @@
gcargs = append(gcargs, "-installsuffix", buildContext.InstallSuffix)
}
- args := stringList(tool(archChar+"g"), "-o", ofile, "-trimpath",
b.work,
buildGcflags, gcargs, "-D", p.localPrefix, importArgs)
+ args := stringList(buildToolExec, tool(archChar+"g"), "-o",
ofile, "-trimpath",
b.work, buildGcflags, gcargs, "-D", p.localPrefix,
importArgs)
if ofile == archive {
args = append(args, "-pack")
}
@@ -1676,7 +1682,7 @@
// Add -I pkg/GOOS_GOARCH so #include "textflag.h" works in .s files.
inc := filepath.Join(goroot, "pkg", fmt.Sprintf("%s_%s", goos, goarch))
sfile = mkAbs(p.Dir, sfile)
- return b.run(p.Dir, p.ImportPath, nil, tool(archChar+"a"), "-trimpath",
b.work, "-I", obj, "-I", inc, "-o",
ofile, "-D", "GOOS_"+goos, "-D", "GOARCH_"+goarch, sfile)
+ return b.run(p.Dir, p.ImportPath, nil, stringList(buildToolExec,
tool(archChar+"a"), "-trimpath",
b.work, "-I", obj, "-I", inc, "-o",
ofile, "-D", "GOOS_"+goos, "-D", "GOARCH_"+goarch, sfile))
}
func (gcToolchain) pkgpath(basedir string, p *Package) string {
@@ -1823,7 +1829,7 @@
}
}
ldflags = append(ldflags, buildLdflags...)
- return b.run(".", p.ImportPath, nil, tool(archChar+"l"), "-o", out,
importArgs, ldflags, mainpkg)
+ return b.run(".", p.ImportPath, nil, stringList(buildToolExec,
tool(archChar+"l"), "-o", out, importArgs, ldflags, mainpkg))
}
func (gcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string)
error {
diff --git a/src/cmd/go/doc.go b/src/cmd/go/doc.go
index d0d8a8a..af9a166 100644
--- a/src/cmd/go/doc.go
+++ b/src/cmd/go/doc.go
@@ -112,6 +112,10 @@
a list of build tags to consider satisfied during the build.
For more information about build tags, see the description of
build constraints in the documentation for the go/build package.
+ -toolexec 'cmd args'
+ a program to use to invoke toolchain programs like 5a, 5g, and 5l.
+ For example, instead of running 5g, the go command will run
+ 'cmd args /path/to/5g <arguments for 5g>'.
The list flags accept a space-separated list of strings. To embed spaces
in an element in the list, surround it with either single or double quotes.
--
https://go-review.googlesource.com/3351
Gerrit-Reviewer: Rob Pike <
r...@golang.org>