aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorFilippo Valsorda <filippo@golang.org>2019-02-08 15:36:33 -0500
committerFilippo Valsorda <filippo@golang.org>2019-02-08 17:54:25 -0500
commit4ed8ad4d69d68da66fac413ed897bdde8d47057b (patch)
treecacacea336211dd3b82bb814f288157f1d601782 /src/cmd/go/internal/load/pkg.go
parent14c64dbc4a4cd359d0cede6e4a7fd01ba9e9d23b (diff)
parent7ccd3583eddcd79679fb29cfc83a6e6fb6973f1e (diff)
downloadgo-4ed8ad4d69d68da66fac413ed897bdde8d47057b.tar.gz
go-4ed8ad4d69d68da66fac413ed897bdde8d47057b.zip
[dev.boringcrypto] all: merge master into dev.boringcrypto
Change-Id: I9246c8228d38559c40e69fa403fa946ac1b31dbe
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go35
1 files changed, 10 insertions, 25 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index afb70a540c..49bd98216c 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -1003,10 +1003,12 @@ func disallowInternal(srcDir string, importer *Package, importerPath string, p *
} else {
// p is in a module, so make it available based on the importer's import path instead
// of the file path (https://golang.org/issue/23970).
- if importerPath == "." {
+ if importer.Internal.CmdlineFiles {
// The importer is a list of command-line files.
// Pretend that the import path is the import path of the
// directory containing them.
+ // If the directory is outside the main module, this will resolve to ".",
+ // which is not a prefix of any valid module.
importerPath = ModDirImportPath(importer.Dir)
}
parentOfInternal := p.ImportPath[:i]
@@ -1057,20 +1059,6 @@ func disallowVendor(srcDir string, importer *Package, importerPath, path string,
return p
}
- // Modules must not import vendor packages in the standard library,
- // but the usual vendor visibility check will not catch them
- // because the module loader presents them with an ImportPath starting
- // with "golang_org/" instead of "vendor/".
- if p.Standard && !importer.Standard && strings.HasPrefix(p.ImportPath, "golang_org") {
- perr := *p
- perr.Error = &PackageError{
- ImportStack: stk.Copy(),
- Err: "use of vendored package " + path + " not allowed",
- }
- perr.Incomplete = true
- return &perr
- }
-
if perr := disallowVendorVisibility(srcDir, p, stk); perr != p {
return perr
}
@@ -1349,6 +1337,7 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
// SWIG adds imports of some standard packages.
if p.UsesSwig() {
+ addImport("unsafe", true)
if cfg.BuildContext.Compiler != "gccgo" {
addImport("runtime/cgo", true)
}
@@ -1534,9 +1523,13 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
}
if cfg.ModulesEnabled {
- p.Module = ModPackageModuleInfo(p.ImportPath)
+ mainPath := p.ImportPath
+ if p.Internal.CmdlineFiles {
+ mainPath = "command-line-arguments"
+ }
+ p.Module = ModPackageModuleInfo(mainPath)
if p.Name == "main" {
- p.Internal.BuildInfo = ModPackageBuildInfo(p.ImportPath, p.Deps)
+ p.Internal.BuildInfo = ModPackageBuildInfo(mainPath, p.Deps)
}
}
}
@@ -1786,9 +1779,6 @@ func loadPackage(arg string, stk *ImportStack) *Package {
bp.ImportPath = arg
bp.Goroot = true
bp.BinDir = cfg.GOROOTbin
- if cfg.GOROOTbin != "" {
- bp.BinDir = cfg.GOROOTbin
- }
bp.Root = cfg.GOROOT
bp.SrcRoot = cfg.GOROOTsrc
p := new(Package)
@@ -2006,11 +1996,6 @@ func GoFilesPackage(gofiles []string) *Package {
}
bp, err := ctxt.ImportDir(dir, 0)
- if ModDirImportPath != nil {
- // Use the effective import path of the directory
- // for deciding visibility during pkg.load.
- bp.ImportPath = ModDirImportPath(dir)
- }
pkg := new(Package)
pkg.Internal.Local = true
pkg.Internal.CmdlineFiles = true