[go] cmd/go: add build flag -toolexec

350 views
Skip to first unread message

Russ Cox (Gerrit)

unread,
Jan 27, 2015, 2:54:58 PM1/27/15
to Rob Pike, Ian Lance Taylor, Russ Cox, golang-co...@googlegroups.com
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>

David Crawshaw (Gerrit)

unread,
Jan 27, 2015, 3:07:47 PM1/27/15
to Russ Cox, Rob Pike, golang-co...@googlegroups.com
David Crawshaw has posted comments on this change.

cmd/go: add build flag -toolexec

Patch Set 1: Code-Review+1

If -toolexec applied to the cgo command, I believe this technique could be
used to improve on CC_FOR_TARGET.

Right now the Android workflow can get a bit complex because only one
cgo-enabled cross-compiler can be installed. Parameterizing CC_FOR_TARGET
over GOOS/GOARCH has always felt too complex for the Go tool, but this
logic could live in an external program invoked by -toolexec.

--
https://go-review.googlesource.com/3351
Gerrit-Reviewer: David Crawshaw <craw...@golang.org>
Gerrit-Reviewer: Rob Pike <r...@golang.org>
Gerrit-HasComments: No

Aram Hăvărneanu (Gerrit)

unread,
Jan 27, 2015, 3:23:37 PM1/27/15
to Russ Cox, Rob Pike, David Crawshaw, golang-co...@googlegroups.com
Aram Hăvărneanu has posted comments on this change.

cmd/go: add build flag -toolexec

Patch Set 1: Code-Review+1

--
https://go-review.googlesource.com/3351
Gerrit-Reviewer: Aram Hăvărneanu <ar...@mgk.ro>

Rob Pike (Gerrit)

unread,
Jan 27, 2015, 3:39:43 PM1/27/15
to Russ Cox, Rob Pike, David Crawshaw, Aram Hăvărneanu, golang-co...@googlegroups.com
Rob Pike has posted comments on this change.

cmd/go: add build flag -toolexec

Patch Set 1: Code-Review+2

Russ Cox (Gerrit)

unread,
Jan 29, 2015, 11:22:29 AM1/29/15
to Russ Cox, Rob Pike, David Crawshaw, Aram Hăvărneanu, golang-co...@googlegroups.com
Russ Cox has posted comments on this change.

cmd/go: add build flag -toolexec

Patch Set 1:

Done.

--
https://go-review.googlesource.com/3351
Gerrit-Reviewer: Aram Hăvărneanu <ar...@mgk.ro>
Gerrit-Reviewer: David Crawshaw <craw...@golang.org>
Gerrit-Reviewer: Rob Pike <r...@golang.org>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-HasComments: No

Russ Cox (Gerrit)

unread,
Jan 29, 2015, 11:25:45 AM1/29/15
to Russ Cox, Rob Pike, David Crawshaw, Aram Hăvărneanu, golang-co...@googlegroups.com
Russ Cox has posted comments on this change.

cmd/go: add build flag -toolexec

Patch Set 1:

I changed this to apply to all tools, as I had intended.

Russ Cox (Gerrit)

unread,
Jan 29, 2015, 11:25:53 AM1/29/15
to Russ Cox, Aram Hăvărneanu, Rob Pike, David Crawshaw, golang-co...@googlegroups.com
Reviewers: Aram Hăvărneanu, Rob Pike, David Crawshaw

Russ Cox uploaded a new patch set:
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
M src/cmd/go/fix.go
M src/cmd/go/get.go
M src/cmd/go/vet.go
5 files changed, 20 insertions(+), 9 deletions(-)

Russ Cox (Gerrit)

unread,
Jan 29, 2015, 11:25:55 AM1/29/15
to Russ Cox, golang-...@googlegroups.com, Rob Pike, David Crawshaw, Aram Hăvărneanu, golang-co...@googlegroups.com
Russ Cox has submitted this change and it was merged.

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
Reviewed-on: https://go-review.googlesource.com/3351
Reviewed-by: Rob Pike <r...@golang.org>
---
M src/cmd/go/build.go
M src/cmd/go/doc.go
M src/cmd/go/fix.go
M src/cmd/go/get.go
M src/cmd/go/vet.go
5 files changed, 20 insertions(+), 9 deletions(-)

Approvals:
Rob Pike: Looks good to me, approved
Reply all
Reply to author
Forward
0 new messages