From: Bryan C. Mills Date: Thu, 10 Nov 2022 15:03:21 +0000 (-0500) Subject: go/build: omit PkgObj for packages "unsafe" and "builtin" X-Git-Tag: go1.20rc1~332 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=05cc8b5369b4c3571f0fb2aeed67f9229301b382;p=gostls13.git 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 Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot --- diff --git a/src/cmd/go/internal/modindex/read.go b/src/cmd/go/internal/modindex/read.go index fa0271f6ec..3e068d5600 100644 --- a/src/cmd/go/internal/modindex/read.go +++ b/src/cmd/go/internal/modindex/read.go @@ -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) } } diff --git a/src/cmd/go/testdata/script/install_goroot_targets.txt b/src/cmd/go/testdata/script/install_goroot_targets.txt index 4d6ca13e24..25b97b4b73 100644 --- a/src/cmd/go/testdata/script/install_goroot_targets.txt +++ b/src/cmd/go/testdata/script/install_goroot_targets.txt @@ -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= diff --git a/src/go/build/build.go b/src/go/build/build.go index 4c0388149d..6925154da1 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -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) } }