aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/load.go
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2023-05-17 14:04:25 -0400
committerMichael Matloob <matloob@golang.org>2023-07-24 18:09:22 +0000
commit89a457844f2b39794f9a8c16f008d3825f1ab455 (patch)
tree8cca92e05d1508daa4353aa279581cdaf0e984b7 /src/cmd/go/internal/modload/load.go
parent7141d1e6d820241de321f8a9d336871737560950 (diff)
downloadgo-89a457844f2b39794f9a8c16f008d3825f1ab455.tar.gz
go-89a457844f2b39794f9a8c16f008d3825f1ab455.zip
cmd/go: add support for vendoring in workspace mode
In most cases this change removes assumptions that there is a single main module in vendor mode and iterates over the workspace modules when doing checks. The go mod vendor command will now, if in workspace mode, create a vendor directory in the same directory as the go.work file, containing the packages (and modules in modules.txt) loaded from the workspace. When reassembling the module graph from the vendor directory, an edges are added from each of the main modules to their requirements, plus additionally to a fake 'vendor/modules.txt' module with edges to all the modules listed in vendor/modules.txt. For #60056 Change-Id: I4a485bb39836e7ab35cdc7726229191c6599903e Reviewed-on: https://go-review.googlesource.com/c/go/+/495801 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r--src/cmd/go/internal/modload/load.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go
index a993fe819c..9b4cb19ebf 100644
--- a/src/cmd/go/internal/modload/load.go
+++ b/src/cmd/go/internal/modload/load.go
@@ -571,7 +571,7 @@ func resolveLocalPackage(ctx context.Context, dir string, rs *Requirements) (str
return "", fmt.Errorf("without -mod=vendor, directory %s has no package path", absDir)
}
- readVendorList(mainModule)
+ readVendorList(VendorDir())
if _, ok := vendorPkgModule[pkg]; !ok {
return "", fmt.Errorf("directory %s is not a package listed in vendor/modules.txt", absDir)
}
@@ -1354,6 +1354,15 @@ func (ld *loader) updateRequirements(ctx context.Context) (changed bool, err err
// In workspace mode / workspace pruning mode, the roots are the main modules
// rather than the main module's direct dependencies. The check below on the selected
// roots does not apply.
+ if cfg.BuildMod == "vendor" {
+ // In workspace vendor mode, we don't need to load the requirements of the workspace
+ // modules' dependencies so the check below doesn't work. But that's okay, because
+ // checking whether modules are required directly for the purposes of pruning is
+ // less important in vendor mode: if we were able to load the package, we have
+ // everything we need to build the package, and dependencies' tests are pruned out
+ // of the vendor directory anyway.
+ continue
+ }
if mg, err := rs.Graph(ctx); err != nil {
return false, err
} else if _, ok := mg.RequiredBy(dep.mod); !ok {