Skip to content

Commit 86324f2

Browse files
committed
go/build: do not record go:binary-only-package if build tags not satisfied
This is the documented (and now implemented) behavior. Fixes #16841. Change-Id: Ic75adc5ba18303ed9578e04284f32933f905d6a3 Reviewed-on: https://go-review.googlesource.com/31577 Reviewed-by: Quentin Smith <[email protected]>
1 parent ee4b58d commit 86324f2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/cmd/go/go_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,16 @@ func TestBinaryOnlyPackages(t *testing.T) {
29802980

29812981
tg.run("run", tg.path("src/p3/p3.go"))
29822982
tg.grepStdout("hello from p1", "did not see message from p1")
2983+
2984+
tg.tempFile("src/p4/p4.go", `package main`)
2985+
tg.tempFile("src/p4/p4not.go", `//go:binary-only-package
2986+
2987+
// +build asdf
2988+
2989+
package main
2990+
`)
2991+
tg.run("list", "-f", "{{.BinaryOnly}}", "p4")
2992+
tg.grepStdout("false", "did not see BinaryOnly=false for p4")
29832993
}
29842994

29852995
// Issue 16050.

src/go/build/build.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -1072,10 +1072,14 @@ func (ctxt *Context) matchFile(dir, name string, returnImports bool, allTags map
10721072
}
10731073

10741074
// Look for +build comments to accept or reject the file.
1075-
if !ctxt.shouldBuild(data, allTags, binaryOnly) && !ctxt.UseAllFiles {
1075+
var sawBinaryOnly bool
1076+
if !ctxt.shouldBuild(data, allTags, &sawBinaryOnly) && !ctxt.UseAllFiles {
10761077
return
10771078
}
10781079

1080+
if binaryOnly != nil && sawBinaryOnly {
1081+
*binaryOnly = true
1082+
}
10791083
match = true
10801084
return
10811085
}
@@ -1119,9 +1123,8 @@ var binaryOnlyComment = []byte("//go:binary-only-package")
11191123
//
11201124
// marks the file as applicable only on Windows and Linux.
11211125
//
1122-
// If shouldBuild finds a //go:binary-only-package comment in a file that
1123-
// should be built, it sets *binaryOnly to true. Otherwise it does
1124-
// not change *binaryOnly.
1126+
// If shouldBuild finds a //go:binary-only-package comment in the file,
1127+
// it sets *binaryOnly to true. Otherwise it does not change *binaryOnly.
11251128
//
11261129
func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binaryOnly *bool) bool {
11271130
sawBinaryOnly := false

0 commit comments

Comments
 (0)