Skip to content

Commit 1650f1b

Browse files
author
Jay Conrod
committed
cmd/go: drop support for binary-only packages
Fixes #28152 Change-Id: I98db923bdf8de7acf2df452313427bfea43b63c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/165746 Run-TryBot: Jay Conrod <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent a30421a commit 1650f1b

File tree

7 files changed

+27
-100
lines changed

7 files changed

+27
-100
lines changed

src/cmd/go/alldocs.go

+1-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/go_test.go

+8-43
Original file line numberDiff line numberDiff line change
@@ -4206,9 +4206,9 @@ func TestBinaryOnlyPackages(t *testing.T) {
42064206
42074207
package p1
42084208
`)
4209-
tg.wantStale("p1", "missing or invalid binary-only package", "p1 is binary-only but has no binary, should be stale")
4209+
tg.wantStale("p1", "binary-only packages are no longer supported", "p1 is binary-only, and this message should always be printed")
42104210
tg.runFail("install", "p1")
4211-
tg.grepStderr("missing or invalid binary-only package", "did not report attempt to compile binary-only package")
4211+
tg.grepStderr("binary-only packages are no longer supported", "did not report attempt to compile binary-only package")
42124212

42134213
tg.tempFile("src/p1/p1.go", `
42144214
package p1
@@ -4234,48 +4234,13 @@ func TestBinaryOnlyPackages(t *testing.T) {
42344234
import _ "fmt"
42354235
func G()
42364236
`)
4237-
tg.wantNotStale("p1", "binary-only package", "should NOT want to rebuild p1 (first)")
4238-
tg.run("install", "-x", "p1") // no-op, up to date
4239-
tg.grepBothNot(`[\\/]compile`, "should not have run compiler")
4240-
tg.run("install", "p2") // does not rebuild p1 (or else p2 will fail)
4241-
tg.wantNotStale("p2", "", "should NOT want to rebuild p2")
4242-
4243-
// changes to the non-source-code do not matter,
4244-
// and only one file needs the special comment.
4245-
tg.tempFile("src/p1/missing2.go", `
4246-
package p1
4247-
func H()
4248-
`)
4249-
tg.wantNotStale("p1", "binary-only package", "should NOT want to rebuild p1 (second)")
4250-
tg.wantNotStale("p2", "", "should NOT want to rebuild p2")
4251-
4252-
tg.tempFile("src/p3/p3.go", `
4253-
package main
4254-
import (
4255-
"p1"
4256-
"p2"
4257-
)
4258-
func main() {
4259-
p1.F(false)
4260-
p2.F()
4261-
}
4262-
`)
4263-
tg.run("install", "p3")
4264-
4265-
tg.run("run", tg.path("src/p3/p3.go"))
4266-
tg.grepStdout("hello from p1", "did not see message from p1")
4267-
4268-
tg.tempFile("src/p4/p4.go", `package main`)
4269-
// The odd string split below avoids vet complaining about
4270-
// a // +build line appearing too late in this source file.
4271-
tg.tempFile("src/p4/p4not.go", `//go:binary-only-package
4272-
4273-
/`+`/ +build asdf
4237+
tg.wantStale("p1", "binary-only package", "should NOT want to rebuild p1 (first)")
4238+
tg.runFail("install", "p2")
4239+
tg.grepStderr("p1: binary-only packages are no longer supported", "did not report error for binary-only p1")
42744240

4275-
package main
4276-
`)
4277-
tg.run("list", "-f", "{{.BinaryOnly}}", "p4")
4278-
tg.grepStdout("false", "did not see BinaryOnly=false for p4")
4241+
tg.run("list", "-deps", "-f", "{{.ImportPath}}: {{.BinaryOnly}}", "p2")
4242+
tg.grepStdout("p1: true", "p1 not listed as BinaryOnly")
4243+
tg.grepStdout("p2: false", "p2 listed as BinaryOnly")
42794244
}
42804245

42814246
// Issue 16050.

src/cmd/go/internal/help/helpdoc.go

-9
Original file line numberDiff line numberDiff line change
@@ -635,15 +635,6 @@ constraints, but the go command stops scanning for build constraints
635635
at the first item in the file that is not a blank line or //-style
636636
line comment. See the go/build package documentation for
637637
more details.
638-
639-
Through the Go 1.12 release, non-test Go source files can also include
640-
a //go:binary-only-package comment, indicating that the package
641-
sources are included for documentation only and must not be used to
642-
build the package binary. This enables distribution of Go packages in
643-
their compiled form alone. Even binary-only packages require accurate
644-
import blocks listing required dependencies, so that those
645-
dependencies can be supplied when linking the resulting command.
646-
Note that this feature is scheduled to be removed after the Go 1.12 release.
647638
`,
648639
}
649640

src/cmd/go/internal/list/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ to -f '{{.ImportPath}}'. The struct being passed to the template is:
6060
StaleReason string // explanation for Stale==true
6161
Root string // Go root or Go path dir containing this package
6262
ConflictDir string // this directory shadows Dir in $GOPATH
63-
BinaryOnly bool // binary-only package: cannot be recompiled from sources
63+
BinaryOnly bool // binary-only package (no longer supported)
6464
ForTest string // package is only for use in named test
6565
Export string // file containing export data (when using -export)
6666
Module *Module // info about package's containing module, if any (can be nil)

src/cmd/go/internal/work/exec.go

+3-15
Original file line numberDiff line numberDiff line change
@@ -422,24 +422,12 @@ func (b *Builder) build(a *Action) (err error) {
422422
}
423423

424424
if a.Package.BinaryOnly {
425-
_, err := os.Stat(a.Package.Target)
426-
if err == nil {
427-
a.built = a.Package.Target
428-
a.Target = a.Package.Target
429-
if b.NeedExport {
430-
a.Package.Export = a.Package.Target
431-
}
432-
a.buildID = b.fileHash(a.Package.Target)
433-
a.Package.Stale = false
434-
a.Package.StaleReason = "binary-only package"
435-
return nil
436-
}
437-
a.Package.Stale = true
438-
a.Package.StaleReason = "missing or invalid binary-only package"
425+
p.Stale = true
426+
p.StaleReason = "binary-only packages are no longer supported"
439427
if b.IsCmdList {
440428
return nil
441429
}
442-
return fmt.Errorf("missing or invalid binary-only package; expected file %q", a.Package.Target)
430+
return errors.New("binary-only packages are no longer supported")
443431
}
444432

445433
if err := b.Mkdir(a.Objdir); err != nil {

src/cmd/go/testdata/script/binary_only.txt

-12
This file was deleted.

src/go/build/doc.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,28 @@
149149
//
150150
// Binary-Only Packages
151151
//
152-
// It is possible to distribute packages in binary form without including the
153-
// source code used for compiling the package. To do this, the package must
154-
// be distributed with a source file not excluded by build constraints and
155-
// containing a "//go:binary-only-package" comment.
156-
// Like a build constraint, this comment must appear near the top of the file,
157-
// preceded only by blank lines and other line comments and with a blank line
152+
// In Go 1.12 and earlier, it was possible to distribute packages in binary
153+
// form without including the source code used for compiling the package.
154+
// The package was distributed with a source file not excluded by build
155+
// constraints and containing a "//go:binary-only-package" comment. Like a
156+
// build constraint, this comment appeared at the top of a file, preceded
157+
// only by blank lines and other line comments and with a blank line
158158
// following the comment, to separate it from the package documentation.
159159
// Unlike build constraints, this comment is only recognized in non-test
160160
// Go source files.
161161
//
162-
// The minimal source code for a binary-only package is therefore:
162+
// The minimal source code for a binary-only package was therefore:
163163
//
164164
// //go:binary-only-package
165165
//
166166
// package mypkg
167167
//
168-
// The source code may include additional Go code. That code is never compiled
169-
// but will be processed by tools like godoc and might be useful as end-user
170-
// documentation.
168+
// The source code could include additional Go code. That code was never
169+
// compiled but would be processed by tools like godoc and might be useful
170+
// as end-user documentation.
171+
//
172+
// "go build" and other commands no longer support binary-only-packages.
173+
// Import and ImportDir will still set the BinaryOnly flag in packages
174+
// containing these comments for use in tools and error messages.
171175
//
172176
package build

0 commit comments

Comments
 (0)