File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -5,8 +5,10 @@ import (
55 "log"
66 "os"
77 "os/exec"
8+ "path/filepath"
89 "strings"
910
11+ "github.com/github/codeql-go/extractor/util"
1012 "golang.org/x/mod/semver"
1113)
1214
@@ -81,7 +83,20 @@ func TidyModule(path string) *exec.Cmd {
8183
8284// Run `go mod init` in the directory given by `path`.
8385func InitModule (path string ) * exec.Cmd {
84- modInit := exec .Command ("go" , "mod" , "init" , "codeql/auto-project" )
86+ moduleName := "codeql/auto-project"
87+
88+ if importpath := util .GetImportPath (); importpath != "" {
89+ // This should be something like `github.com/user/repo`
90+ moduleName = importpath
91+
92+ // If we are not initialising the new module in the root directory of the workspace,
93+ // append the relative path to the module name.
94+ if relPath , err := filepath .Rel ("." , path ); err != nil && relPath != "." {
95+ moduleName = moduleName + "/" + relPath
96+ }
97+ }
98+
99+ modInit := exec .Command ("go" , "mod" , "init" , moduleName )
85100 modInit .Dir = path
86101 return modInit
87102}
You can’t perform that action at this time.
0 commit comments