Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2546340

Browse files
committed
Go: Add shared TidyModule function
1 parent f013d9d commit 2546340

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ func tryUpdateGoModAndGoSum(buildInfo project.BuildInfo) {
226226
beforeGoSumFileInfo, beforeGoSumErr := os.Stat(goSumPath)
227227

228228
// run `go mod tidy -e`
229-
cmd := exec.Command("go", "mod", "tidy", "-e")
230-
cmd.Dir = buildInfo.BaseDir
229+
cmd := toolchain.TidyModule(buildInfo.BaseDir)
231230
res := util.RunCmd(cmd)
232231

233232
if !res {
@@ -443,9 +442,7 @@ func initGoModForLegacyProject(buildInfo project.BuildInfo) {
443442
return
444443
}
445444

446-
modTidy := exec.Command("go", "mod", "tidy")
447-
modTidy.Dir = buildInfo.BaseDir
448-
445+
modTidy := toolchain.TidyModule(buildInfo.BaseDir)
449446
out, err := modTidy.CombinedOutput()
450447
log.Println(string(out))
451448

go/extractor/toolchain/toolchain.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,10 @@ func parseGoVersion(data string) string {
7171
func SupportsWorkspaces() bool {
7272
return semver.Compare(GetEnvGoSemVer(), "v1.18.0") >= 0
7373
}
74+
75+
// Run `go mod tidy -e` in the directory given by `path`.
76+
func TidyModule(path string) *exec.Cmd {
77+
cmd := exec.Command("go", "mod", "tidy", "-e")
78+
cmd.Dir = path
79+
return cmd
80+
}

0 commit comments

Comments
 (0)