]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: invert AllowVendor to IgnoreVendor
authorRuss Cox <rsc@golang.org>
Fri, 8 Jan 2016 17:38:41 +0000 (12:38 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 8 Jan 2016 18:49:01 +0000 (18:49 +0000)
Looking for vendor directories is a better default.

Fixes #13772

Change-Id: Iabbaea71ccc67b72f14f1f412dc8ab70cb41996d
Reviewed-on: https://go-review.googlesource.com/18450
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/cmd/go/pkg.go
src/go/build/build.go
src/go/build/build_test.go

index 3361fc32005921c162668916f2480e5237b844be..7d2779e01f1b955d20f901d7ebac1f1ade9ed1d6 100644 (file)
@@ -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
index c94267077515ac24b34fb710c22c36e02cee816d..9539413aad61f998546298d31b5702fa65a17ba9 100644 (file)
@@ -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/") {
index 07efc14292f4f88dcd78e2df05b04bf76c309d51..f70389780d0a7dc28d7f18af6dc9b82047df2df9 100644 (file)
@@ -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)
        }