Go: Call go mod vendor to synchronise vendor directory when it exists

This commit is contained in:
Michael B. Gale
2024-02-15 16:19:07 +00:00
parent 6267506a77
commit 4d28c0d2a9
2 changed files with 17 additions and 2 deletions

View File

@@ -480,9 +480,17 @@ func installDependencies(workspace project.GoWorkspace) {
// get dependencies for all modules
for _, module := range workspace.Modules {
path := filepath.Dir(module.Path)
if util.DirExists(filepath.Join(path, "vendor")) {
vendor := toolchain.VendorModule(path)
log.Printf("Synchronizing vendor file using `go mod vendor` in %s.\n", path)
util.RunCmd(vendor)
}
install = exec.Command("go", "get", "-v", "./...")
install.Dir = filepath.Dir(module.Path)
log.Printf("Installing dependencies using `go get -v ./...` in `%s`.\n", filepath.Dir(module.Path))
install.Dir = path
log.Printf("Installing dependencies using `go get -v ./...` in `%s`.\n", path)
util.RunCmd(install)
}
}

View File

@@ -85,3 +85,10 @@ func InitModule(path string) *exec.Cmd {
modInit.Dir = path
return modInit
}
// Constructs a command to run `go mod vendor` in the directory given by `path`.
func VendorModule(path string) *exec.Cmd {
modVendor := exec.Command("go", "mod", "vendor")
modVendor.Dir = path
return modVendor
}