]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/go/internal/load/pkg.go
cmd/go: don't install most GOROOT .a files in pkg
[gostls13.git] / src / cmd / go / internal / load / pkg.go
index 1e50fdc0a5f0bc032049606ec95816891c2e5007..4a6414016ade4068593e20a26fc017b73556f0de 100644 (file)
@@ -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)