Commit 86324f29 authored by Russ Cox's avatar Russ Cox

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/31577Reviewed-by: 's avatarQuentin Smith <quentin@golang.org>
parent ee4b58df
...@@ -2980,6 +2980,16 @@ func TestBinaryOnlyPackages(t *testing.T) { ...@@ -2980,6 +2980,16 @@ func TestBinaryOnlyPackages(t *testing.T) {
tg.run("run", tg.path("src/p3/p3.go")) tg.run("run", tg.path("src/p3/p3.go"))
tg.grepStdout("hello from p1", "did not see message from p1") tg.grepStdout("hello from p1", "did not see message from p1")
tg.tempFile("src/p4/p4.go", `package main`)
tg.tempFile("src/p4/p4not.go", `//go:binary-only-package
// +build asdf
package main
`)
tg.run("list", "-f", "{{.BinaryOnly}}", "p4")
tg.grepStdout("false", "did not see BinaryOnly=false for p4")
} }
// Issue 16050. // Issue 16050.
......
...@@ -1072,10 +1072,14 @@ func (ctxt *Context) matchFile(dir, name string, returnImports bool, allTags map ...@@ -1072,10 +1072,14 @@ func (ctxt *Context) matchFile(dir, name string, returnImports bool, allTags map
} }
// Look for +build comments to accept or reject the file. // Look for +build comments to accept or reject the file.
if !ctxt.shouldBuild(data, allTags, binaryOnly) && !ctxt.UseAllFiles { var sawBinaryOnly bool
if !ctxt.shouldBuild(data, allTags, &sawBinaryOnly) && !ctxt.UseAllFiles {
return return
} }
if binaryOnly != nil && sawBinaryOnly {
*binaryOnly = true
}
match = true match = true
return return
} }
...@@ -1119,9 +1123,8 @@ var binaryOnlyComment = []byte("//go:binary-only-package") ...@@ -1119,9 +1123,8 @@ var binaryOnlyComment = []byte("//go:binary-only-package")
// //
// marks the file as applicable only on Windows and Linux. // marks the file as applicable only on Windows and Linux.
// //
// If shouldBuild finds a //go:binary-only-package comment in a file that // If shouldBuild finds a //go:binary-only-package comment in the file,
// should be built, it sets *binaryOnly to true. Otherwise it does // it sets *binaryOnly to true. Otherwise it does not change *binaryOnly.
// not change *binaryOnly.
// //
func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binaryOnly *bool) bool { func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binaryOnly *bool) bool {
sawBinaryOnly := false sawBinaryOnly := false
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment