aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2022-09-21 15:51:27 -0400
committerMichael Matloob <matloob@golang.org>2022-10-28 23:35:08 +0000
commitb726b0cadb5102bb718f879bede0e76d1e5f5c34 (patch)
treed5e474a4699d75e73039ef92f73ed86d5920424f /src/cmd/go/internal/load/pkg.go
parent4c69d0eeb869cdc987e35d09a052a0e0320c0c96 (diff)
downloadgo-b726b0cadb5102bb718f879bede0e76d1e5f5c34.tar.gz
go-b726b0cadb5102bb718f879bede0e76d1e5f5c34.zip
cmd/go: don't install most GOROOT .a files in pkg
Packages in GOROOT that don't use cgo will not be installed in GOROOT/pkg, and will instead be cached as usual like other Go packages. - add a internal/buildinternal package to hold the identities of the five packages that use cgo - update dist's test code to do a go build std cmd before checking staleness on builders. Because most of those packages no longer have install locations, and have dependencies that don't either, the packages need to be cached to not be stale. - fix index_test to import packages with the path "." when preparing the "want" values to compare the indexed data to. (the module index matches the behavior of build.ImportDir, which always passes in "." as the path. - In both the index and go/build Importers, don't set PkgObj for GOROOT packages which will no longer have install targets. PkgTargetRoot will still be set to compute target paths, which will still be needed in buildmode=shared. - "downgrade" all install actions that don't have a target to build actions. (The target should already not be set for packages that shouldn't be installed). For #47257 Change-Id: Ia5aee6b3b20b58e028119cf0352a4c4a2f10f6b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/432535 Run-TryBot: Michael Matloob <matloob@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index 1e50fdc0a5..4a6414016a 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -374,7 +374,9 @@ func (p *Package) copyBuild(opts PackageOpts, pp *build.Package) {
old := pp.PkgTargetRoot
pp.PkgRoot = cfg.BuildPkgdir
pp.PkgTargetRoot = cfg.BuildPkgdir
- pp.PkgObj = filepath.Join(cfg.BuildPkgdir, strings.TrimPrefix(pp.PkgObj, old))
+ if pp.PkgObj != "" {
+ pp.PkgObj = filepath.Join(cfg.BuildPkgdir, strings.TrimPrefix(pp.PkgObj, old))
+ }
}
p.Dir = pp.Dir
@@ -1814,11 +1816,19 @@ func (p *Package) load(ctx context.Context, opts PackageOpts, path string, stk *
p.Target = ""
} else {
p.Target = p.Internal.Build.PkgObj
- if cfg.BuildLinkshared && p.Target != "" {
- // TODO(bcmills): The reliance on p.Target implies that -linkshared does
- // not work for any package that lacks a Target — such as a non-main
+ if cfg.BuildBuildmode == "shared" && p.Internal.Build.PkgTargetRoot != "" {
+ // TODO(matloob): This shouldn't be necessary, but the misc/cgo/testshared
+ // test fails without Target set for this condition. Figure out why and
+ // fix it.
+ p.Target = filepath.Join(p.Internal.Build.PkgTargetRoot, p.ImportPath+".a")
+ }
+ if cfg.BuildLinkshared && p.Internal.Build.PkgTargetRoot != "" {
+ // TODO(bcmills): The reliance on PkgTargetRoot implies that -linkshared does
+ // not work for any package that lacks a PkgTargetRoot — such as a non-main
// package in module mode. We should probably fix that.
- shlibnamefile := p.Target[:len(p.Target)-2] + ".shlibname"
+ targetPrefix := filepath.Join(p.Internal.Build.PkgTargetRoot, p.ImportPath)
+ p.Target = targetPrefix + ".a"
+ shlibnamefile := targetPrefix + ".shlibname"
shlib, err := os.ReadFile(shlibnamefile)
if err != nil && !os.IsNotExist(err) {
base.Fatalf("reading shlibname: %v", err)