aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2017-04-27 18:25:43 +0100
committerDaniel Martí <mvdan@mvdan.cc>2017-04-28 19:08:35 +0000
commit16b6bb88ebfbd079a1d0b7c0cef80fa55eaf0211 (patch)
tree514ccb64de2852c2d44dd7bdbc94f0ca6ba85f79 /src
parent60db9fb6bccde26f5384978a3f64a6f409a515bc (diff)
downloadgo-16b6bb88ebfbd079a1d0b7c0cef80fa55eaf0211.tar.xz
cmd/go: error on space-separated list with comma
Using 'go build -tags "foo,bar"' might seem to work when you wanted -tags "foo bar", since they make up a single tag that doesn't exist and the build is unaffected. Instead, error on any tag that contains a comma. Fixes #18800. Change-Id: I6641e03e2ae121c8878d6301c4311aef97026b73 Reviewed-on: https://go-review.googlesource.com/41951 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/go_test.go12
-rw-r--r--src/cmd/go/internal/work/build.go6
2 files changed, 18 insertions, 0 deletions
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go
index 8cb5867c1e..0b1fe70221 100644
--- a/src/cmd/go/go_test.go
+++ b/src/cmd/go/go_test.go
@@ -3885,3 +3885,15 @@ func main() {
tg.creatingTemp(exe)
tg.run("build", "-o", exe, "p")
}
+
+func TestBuildTagsNoComma(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ tg.makeTempdir()
+ tg.setenv("GOPATH", tg.path("go"))
+ tg.run("install", "-tags", "tag1 tag2", "math")
+ tg.runFail("install", "-tags", "tag1,tag2", "math")
+ tg.grepBoth("space-separated list contains comma", "-tags with a comma-separated list didn't error")
+ tg.runFail("build", "-tags", "tag1,tag2", "math")
+ tg.grepBoth("space-separated list contains comma", "-tags with a comma-separated list didn't error")
+}
diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go
index 448aec7376..2f903adf3e 100644
--- a/src/cmd/go/internal/work/build.go
+++ b/src/cmd/go/internal/work/build.go
@@ -1102,6 +1102,12 @@ func (b *Builder) Do(root *Action) {
fmt.Fprintf(os.Stderr, "cmd/go: unsupported GOOS/GOARCH pair %s/%s\n", cfg.Goos, cfg.Goarch)
os.Exit(2)
}
+ for _, tag := range cfg.BuildContext.BuildTags {
+ if strings.Contains(tag, ",") {
+ fmt.Fprintf(os.Stderr, "cmd/go: -tags space-separated list contains comma\n")
+ os.Exit(2)
+ }
+ }
// Build list of all actions, assigning depth-first post-order priority.
// The original implementation here was a true queue