]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: omit PkgObj for packages "unsafe" and "builtin"
authorBryan C. Mills <bcmills@google.com>
Thu, 10 Nov 2022 15:03:21 +0000 (10:03 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 10 Nov 2022 17:18:08 +0000 (17:18 +0000)
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>

src/cmd/go/internal/modindex/read.go
src/cmd/go/testdata/script/install_goroot_targets.txt
src/go/build/build.go

index fa0271f6ecfef6ba6053a387414250bbd1e20b51..3e068d56002bfbfd97fde17c237eb312957def87 100644 (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)
                                }
                        }
index 4d6ca13e2436f21e365acdf36e3dbefde33281e9..25b97b4b735613879a13582ef020639401bc9b0f 100644 (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=
index 4c0388149dbc9b52ecfdaadb4c2700e858f10a9f..6925154da18f4774b5c73ba72489212ba514bab3 100644 (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)
                        }
                }