1
0
mirror of https://github.com/golang/go synced 2024-11-23 19:40:08 -07:00

go/build: omit PkgObj for packages "unsafe" and "builtin"

Package "builtin" is not a real, importable package; it exists only
for documentation. Package "unsafe" is not compiled into an object
file from its source code; instead, imports of "unsafe" are handled
specially by the compiler.

(In Go 1.19.3, package "unsafe" did not have an install target, while
package "builtin" did but that target was never written.)

Fixes #56687.
Updates #47257.

Change-Id: I1d1e90ff9e1629b80e0df93e1f7e17242c8dab69
Reviewed-on: https://go-review.googlesource.com/c/go/+/449376
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Bryan C. Mills 2022-11-10 10:03:21 -05:00 committed by Gopher Robot
parent b820fb8df1
commit 05cc8b5369
3 changed files with 12 additions and 8 deletions

View File

@ -436,7 +436,7 @@ func (rp *IndexPackage) Import(bctxt build.Context, mode build.ImportMode) (p *b
p.PkgTargetRoot = ctxt.joinPath(p.Root, pkgtargetroot)
// Set the install target if applicable.
if strings.ToLower(godebug.Get("installgoroot")) == "all" || !p.Goroot {
if !p.Goroot || (strings.EqualFold(godebug.Get("installgoroot"), "all") && p.ImportPath != "unsafe" && p.ImportPath != "builtin") {
p.PkgObj = ctxt.joinPath(p.Root, pkga)
}
}

View File

@ -1,5 +1,4 @@
[short] skip
[!cgo] skip
# Most packages in std do not have an install target.
go list -f '{{.Target}}' fmt
@ -8,11 +7,11 @@ go list -export -f '{{.Export}}' fmt
stdout $GOCACHE
# Packages that use cgo still do.
go list -f '{{.Target}}' runtime/cgo
stdout .
go list -export -f '{{.Export}}' runtime/cgo
! stdout $GOCACHE
stdout cgo\.a
[cgo] go list -f '{{.Target}}' runtime/cgo
[cgo] stdout .
[cgo] go list -export -f '{{.Export}}' runtime/cgo
[cgo] ! stdout $GOCACHE
[cgo] stdout cgo\.a
# With GODEBUG=installgoroot=all, fmt has a target.
# (Though we can't try installing it without modifying goroot).
@ -20,6 +19,11 @@ env GODEBUG=installgoroot=all
go list -f '{{.Target}}' fmt
stdout fmt\.a
# However, the fake packages "builtin" and "unsafe" do not.
go list -f '{{.Target}}' builtin unsafe
! stdout .
go install builtin unsafe # Should succeed as no-ops.
# With CGO_ENABLED=0, packages that would have
# an install target with cgo on no longer do.
env GODEBUG=

View File

@ -783,7 +783,7 @@ Found:
p.PkgTargetRoot = ctxt.joinPath(p.Root, pkgtargetroot)
// Set the install target if applicable.
if strings.ToLower(godebug.Get("installgoroot")) == "all" || !p.Goroot {
if !p.Goroot || (strings.EqualFold(godebug.Get("installgoroot"), "all") && p.ImportPath != "unsafe" && p.ImportPath != "builtin") {
p.PkgObj = ctxt.joinPath(p.Root, pkga)
}
}