Go: Add shared TidyModule function

This commit is contained in:
Michael B. Gale
2024-01-26 13:16:13 +00:00
parent f013d9d373
commit 254634075f
2 changed files with 9 additions and 5 deletions

View File

@@ -226,8 +226,7 @@ func tryUpdateGoModAndGoSum(buildInfo project.BuildInfo) {
beforeGoSumFileInfo, beforeGoSumErr := os.Stat(goSumPath)
// run `go mod tidy -e`
cmd := exec.Command("go", "mod", "tidy", "-e")
cmd.Dir = buildInfo.BaseDir
cmd := toolchain.TidyModule(buildInfo.BaseDir)
res := util.RunCmd(cmd)
if !res {
@@ -443,9 +442,7 @@ func initGoModForLegacyProject(buildInfo project.BuildInfo) {
return
}
modTidy := exec.Command("go", "mod", "tidy")
modTidy.Dir = buildInfo.BaseDir
modTidy := toolchain.TidyModule(buildInfo.BaseDir)
out, err := modTidy.CombinedOutput()
log.Println(string(out))

View File

@@ -71,3 +71,10 @@ func parseGoVersion(data string) string {
func SupportsWorkspaces() bool {
return semver.Compare(GetEnvGoSemVer(), "v1.18.0") >= 0
}
// Run `go mod tidy -e` in the directory given by `path`.
func TidyModule(path string) *exec.Cmd {
cmd := exec.Command("go", "mod", "tidy", "-e")
cmd.Dir = path
return cmd
}