]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: do not record go:binary-only-package if build tags not satisfied
authorRuss Cox <rsc@golang.org>
Thu, 20 Oct 2016 19:45:51 +0000 (15:45 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 24 Oct 2016 15:34:34 +0000 (15:34 +0000)
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 <quentin@golang.org>
src/cmd/go/go_test.go
src/go/build/build.go

index 33fc462339dd6f75506d44effe6c567534a17d12..7e92841082504a7e9805492a79aa222ea6879d39 100644 (file)
@@ -2980,6 +2980,16 @@ func TestBinaryOnlyPackages(t *testing.T) {
 
        tg.run("run", tg.path("src/p3/p3.go"))
        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.
index 9bd211521dbb9f8103182e2d04f231e5ff17aded..bd89e3188fb817852854b65aeff251083f70eccb 100644 (file)
@@ -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.
-       if !ctxt.shouldBuild(data, allTags, binaryOnly) && !ctxt.UseAllFiles {
+       var sawBinaryOnly bool
+       if !ctxt.shouldBuild(data, allTags, &sawBinaryOnly) && !ctxt.UseAllFiles {
                return
        }
 
+       if binaryOnly != nil && sawBinaryOnly {
+               *binaryOnly = true
+       }
        match = true
        return
 }
@@ -1119,9 +1123,8 @@ var binaryOnlyComment = []byte("//go:binary-only-package")
 //
 // marks the file as applicable only on Windows and Linux.
 //
-// If shouldBuild finds a //go:binary-only-package comment in a file that
-// should be built, it sets *binaryOnly to true. Otherwise it does
-// not change *binaryOnly.
+// If shouldBuild finds a //go:binary-only-package comment in the file,
+// it sets *binaryOnly to true. Otherwise it does not change *binaryOnly.
 //
 func (ctxt *Context) shouldBuild(content []byte, allTags map[string]bool, binaryOnly *bool) bool {
        sawBinaryOnly := false