From d6891bd480b664afe4e2f4a0a0a72324943859f3 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 12 Mar 2019 09:25:46 -0400 Subject: [PATCH] cmd/go: search the target for patterns when -mod=vendor is set This fixes the root cause of the bootstrap failure reported in https://groups.google.com/d/msg/golang-dev/xcVJDj5GJ84/U0pVnUOnBwAJ. Updates #30228 Change-Id: I9ce0898922a5aac1f61ceff30319cf88031676c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/167079 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Jay Conrod --- src/cmd/go/internal/modload/search.go | 9 ++++++++- src/cmd/go/testdata/script/mod_vendor_build.txt | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modload/search.go b/src/cmd/go/internal/modload/search.go index 2e82b92cc5..2cd657326c 100644 --- a/src/cmd/go/internal/modload/search.go +++ b/src/cmd/go/internal/modload/search.go @@ -105,7 +105,14 @@ func matchPackages(pattern string, tags map[string]bool, useStd bool, modules [] } if cfg.BuildMod == "vendor" { - walkPkgs(filepath.Join(ModRoot(), "vendor"), "", false) + if HasModRoot() { + modPrefix := Target.Path + if Target.Path == "std" { + modPrefix = "" + } + walkPkgs(ModRoot(), modPrefix, false) + walkPkgs(filepath.Join(ModRoot(), "vendor"), "", false) + } return pkgs } diff --git a/src/cmd/go/testdata/script/mod_vendor_build.txt b/src/cmd/go/testdata/script/mod_vendor_build.txt index 01ee2d202a..da3fd91055 100644 --- a/src/cmd/go/testdata/script/mod_vendor_build.txt +++ b/src/cmd/go/testdata/script/mod_vendor_build.txt @@ -25,6 +25,10 @@ env GOPROXY=off ! go list ... go list -mod=vendor ... +# However, it should still list packages in the main module. +go list -mod=vendor m/... +stdout m + -- go.mod -- module m