]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/go/internal/load/pkg.go
[dev.boringcrypto] all: merge master into dev.boringcrypto
[gostls13.git] / src / cmd / go / internal / load / pkg.go
index 12bf0e1f7a8620e20e699e2fe2f9333e9872ffb8..64267a4a46acaf5428f2651428c0587cac55d7dd 100644 (file)
@@ -64,7 +64,7 @@ type PackagePublic struct {
        Doc           string                `json:",omitempty"` // package documentation string
        Target        string                `json:",omitempty"` // installed target for this package (may be executable)
        Shlib         string                `json:",omitempty"` // the shared library that contains this package (only set when -linkshared)
-       Root          string                `json:",omitempty"` // Go root or Go path dir containing this package
+       Root          string                `json:",omitempty"` // Go root, Go path dir, or module root dir containing this package
        ConflictDir   string                `json:",omitempty"` // Dir is hidden by this other directory
        ForTest       string                `json:",omitempty"` // package is only for use in named test
        Export        string                `json:",omitempty"` // file containing export data (set by go list -export)
@@ -177,8 +177,7 @@ type PackageInternal struct {
        OmitDebug         bool                 // tell linker not to write debug information
        GobinSubdir       bool                 // install target would be subdir of GOBIN
        BuildInfo         string               // add this info to package main
-       TestinginitGo     []byte               // content for _testinginit.go
-       TestmainGo        []byte               // content for _testmain.go
+       TestmainGo        *[]byte              // content for _testmain.go
 
        Asmflags   []string // -asmflags for this package
        Gcflags    []string // -gcflags for this package
@@ -653,9 +652,14 @@ func loadPackageData(path, parentPath, parentDir, parentRoot string, parentIsStd
                                buildMode = build.ImportComment
                        }
                        data.p, data.err = cfg.BuildContext.ImportDir(r.dir, buildMode)
+                       if data.p.Root == "" && cfg.ModulesEnabled {
+                               if info := ModPackageModuleInfo(path); info != nil {
+                                       data.p.Root = info.Dir
+                               }
+                       }
                } else if r.err != nil {
                        data.p = new(build.Package)
-                       data.err = fmt.Errorf("unknown import path %q: %v", r.path, r.err)
+                       data.err = r.err
                } else if cfg.ModulesEnabled && path != "unsafe" {
                        data.p = new(build.Package)
                        data.err = fmt.Errorf("unknown import path %q: internal error: module loader did not resolve import", r.path)
@@ -668,11 +672,17 @@ func loadPackageData(path, parentPath, parentDir, parentRoot string, parentIsStd
                        data.p, data.err = cfg.BuildContext.Import(r.path, parentDir, buildMode)
                }
                data.p.ImportPath = r.path
-               if cfg.GOBIN != "" {
-                       data.p.BinDir = cfg.GOBIN
-               } else if cfg.ModulesEnabled && !data.p.Goroot {
-                       data.p.BinDir = ModBinDir()
+
+               // Set data.p.BinDir in cases where go/build.Context.Import
+               // may give us a path we don't want.
+               if !data.p.Goroot {
+                       if cfg.GOBIN != "" {
+                               data.p.BinDir = cfg.GOBIN
+                       } else if cfg.ModulesEnabled {
+                               data.p.BinDir = ModBinDir()
+                       }
                }
+
                if !cfg.ModulesEnabled && data.err == nil &&
                        data.p.ImportComment != "" && data.p.ImportComment != path &&
                        !strings.Contains(path, "/vendor/") && !strings.HasPrefix(path, "vendor/") {