Commit ecc01a7d authored by Russ Cox's avatar Russ Cox

go/build: invert AllowVendor to IgnoreVendor

Looking for vendor directories is a better default.

Fixes #13772

Change-Id: Iabbaea71ccc67b72f14f1f412dc8ab70cb41996d
Reviewed-on: https://go-review.googlesource.com/18450Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarAustin Clements <austin@google.com>
parent ca4ea81d
......@@ -348,11 +348,9 @@ func loadImport(path, srcDir string, parent *Package, stk *importStack, importPo
// TODO: After Go 1, decide when to pass build.AllowBinary here.
// See issue 3268 for mistakes to avoid.
buildMode := build.ImportComment
if go15VendorExperiment && mode&useVendor != 0 && path == origPath {
// We've already searched the vendor directories and didn't find anything.
// Let Import search them again so that, if the package is not found anywhere,
// the error includes the vendor directories in the list of places considered.
buildMode |= build.AllowVendor
if !go15VendorExperiment || mode&useVendor == 0 || path != origPath {
// Not vendoring, or we already found the vendored path.
buildMode |= build.IgnoreVendor
}
bp, err := buildContext.Import(path, srcDir, buildMode)
bp.ImportPath = importPath
......
......@@ -344,18 +344,20 @@ const (
// See golang.org/s/go14customimport for more information.
ImportComment
// If AllowVendor is set, Import searches vendor directories
// By default, Import searches vendor directories
// that apply in the given source directory before searching
// the GOROOT and GOPATH roots.
// If an Import finds and returns a package using a vendor
// directory, the resulting ImportPath is the complete path
// to the package, including the path elements leading up
// to and including "vendor".
// For example, if Import("y", "x/subdir", AllowVendor) finds
// For example, if Import("y", "x/subdir", 0) finds
// "x/vendor/y", the returned package's ImportPath is "x/vendor/y",
// not plain "y".
// See golang.org/s/go15vendor for more information.
AllowVendor
//
// Setting IgnoreVendor ignores vendor directories.
IgnoreVendor
)
// A Package describes the Go package found in a directory.
......@@ -571,7 +573,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa
gopath := ctxt.gopath()
// Vendor directories get first chance to satisfy import.
if mode&AllowVendor != 0 && srcDir != "" {
if mode&IgnoreVendor == 0 && srcDir != "" {
searchVendor := func(root string, isGoroot bool) bool {
sub, ok := ctxt.hasSubdir(root, srcDir)
if !ok || !strings.HasPrefix(sub, "src/") || strings.Contains(sub, "/testdata/") {
......
......@@ -303,7 +303,7 @@ func TestImportVendor(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
p, err := ctxt.Import("golang.org/x/net/http2/hpack", filepath.Join(ctxt.GOROOT, "src/net/http"), AllowVendor)
p, err := ctxt.Import("golang.org/x/net/http2/hpack", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
if err != nil {
t.Fatalf("cannot find vendored golang.org/x/net/http2/hpack from net/http directory: %v", err)
}
......@@ -317,7 +317,7 @@ func TestImportVendorFailure(t *testing.T) {
testenv.MustHaveGoBuild(t) // really must just have source
ctxt := Default
ctxt.GOPATH = ""
p, err := ctxt.Import("x.com/y/z", filepath.Join(ctxt.GOROOT, "src/net/http"), AllowVendor)
p, err := ctxt.Import("x.com/y/z", filepath.Join(ctxt.GOROOT, "src/net/http"), 0)
if err == nil {
t.Fatalf("found made-up package x.com/y/z in %s", p.Dir)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment