mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Go: Add methods to GoModule for the tidy and vendor commands
These ensure that the module path is used automatically
This commit is contained in:
@@ -168,7 +168,7 @@ func tryUpdateGoModAndGoSum(workspace project.GoWorkspace) {
|
||||
beforeGoSumFileInfo, beforeGoSumErr := os.Stat(goSumPath)
|
||||
|
||||
// run `go mod tidy -e`
|
||||
cmd := toolchain.TidyModule(goModDir)
|
||||
cmd := goMod.Tidy()
|
||||
res := util.RunCmd(cmd)
|
||||
|
||||
if !res {
|
||||
@@ -428,7 +428,7 @@ func installDependencies(workspace project.GoWorkspace) {
|
||||
path := filepath.Dir(module.Path)
|
||||
|
||||
if util.DirExists(filepath.Join(path, "vendor")) {
|
||||
vendor := toolchain.VendorModule(path)
|
||||
vendor := module.Vendor()
|
||||
log.Printf("Synchronizing vendor file using `go mod vendor` in %s.\n", path)
|
||||
util.RunCmd(vendor)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package project
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
@@ -48,6 +49,16 @@ func (module *GoModule) RequiredGoVersion() util.SemVer {
|
||||
}
|
||||
}
|
||||
|
||||
// Runs `go mod tidy` for this module.
|
||||
func (module *GoModule) Tidy() *exec.Cmd {
|
||||
return toolchain.TidyModule(filepath.Dir(module.Path))
|
||||
}
|
||||
|
||||
// Runs `go mod vendor -e` for this module.
|
||||
func (module *GoModule) Vendor() *exec.Cmd {
|
||||
return toolchain.VendorModule(filepath.Dir(module.Path))
|
||||
}
|
||||
|
||||
// Represents information about a Go project workspace: this may either be a folder containing
|
||||
// a `go.work` file or a collection of `go.mod` files.
|
||||
type GoWorkspace struct {
|
||||
|
||||
Reference in New Issue
Block a user