Skip to content

Commit 4d28c0d

Browse files
committed
Go: Call go mod vendor to synchronise vendor directory when it exists
1 parent 6267506 commit 4d28c0d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,17 @@ func installDependencies(workspace project.GoWorkspace) {
480480

481481
// get dependencies for all modules
482482
for _, module := range workspace.Modules {
483+
path := filepath.Dir(module.Path)
484+
485+
if util.DirExists(filepath.Join(path, "vendor")) {
486+
vendor := toolchain.VendorModule(path)
487+
log.Printf("Synchronizing vendor file using `go mod vendor` in %s.\n", path)
488+
util.RunCmd(vendor)
489+
}
490+
483491
install = exec.Command("go", "get", "-v", "./...")
484-
install.Dir = filepath.Dir(module.Path)
485-
log.Printf("Installing dependencies using `go get -v ./...` in `%s`.\n", filepath.Dir(module.Path))
492+
install.Dir = path
493+
log.Printf("Installing dependencies using `go get -v ./...` in `%s`.\n", path)
486494
util.RunCmd(install)
487495
}
488496
}

go/extractor/toolchain/toolchain.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,10 @@ func InitModule(path string) *exec.Cmd {
8585
modInit.Dir = path
8686
return modInit
8787
}
88+
89+
// Constructs a command to run `go mod vendor` in the directory given by `path`.
90+
func VendorModule(path string) *exec.Cmd {
91+
modVendor := exec.Command("go", "mod", "vendor")
92+
modVendor.Dir = path
93+
return modVendor
94+
}

0 commit comments

Comments
 (0)