Skip to content

Commit d344f72

Browse files
committed
Go: Add methods to GoModule for the tidy and vendor commands
These ensure that the module path is used automatically
1 parent 881b258 commit d344f72

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func tryUpdateGoModAndGoSum(workspace project.GoWorkspace) {
168168
beforeGoSumFileInfo, beforeGoSumErr := os.Stat(goSumPath)
169169

170170
// run `go mod tidy -e`
171-
cmd := toolchain.TidyModule(goModDir)
171+
cmd := goMod.Tidy()
172172
res := util.RunCmd(cmd)
173173

174174
if !res {
@@ -428,7 +428,7 @@ func installDependencies(workspace project.GoWorkspace) {
428428
path := filepath.Dir(module.Path)
429429

430430
if util.DirExists(filepath.Join(path, "vendor")) {
431-
vendor := toolchain.VendorModule(path)
431+
vendor := module.Vendor()
432432
log.Printf("Synchronizing vendor file using `go mod vendor` in %s.\n", path)
433433
util.RunCmd(vendor)
434434
}

go/extractor/project/project.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package project
33
import (
44
"log"
55
"os"
6+
"os/exec"
67
"path/filepath"
78
"regexp"
89
"slices"
@@ -48,6 +49,16 @@ func (module *GoModule) RequiredGoVersion() util.SemVer {
4849
}
4950
}
5051

52+
// Runs `go mod tidy` for this module.
53+
func (module *GoModule) Tidy() *exec.Cmd {
54+
return toolchain.TidyModule(filepath.Dir(module.Path))
55+
}
56+
57+
// Runs `go mod vendor -e` for this module.
58+
func (module *GoModule) Vendor() *exec.Cmd {
59+
return toolchain.VendorModule(filepath.Dir(module.Path))
60+
}
61+
5162
// Represents information about a Go project workspace: this may either be a folder containing
5263
// a `go.work` file or a collection of `go.mod` files.
5364
type GoWorkspace struct {

0 commit comments

Comments
 (0)