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 (
5
5
"log"
6
6
"os"
7
7
"os/exec"
8
+ "path/filepath"
8
9
"strings"
9
10
11
+ "github.com/github/codeql-go/extractor/util"
10
12
"golang.org/x/mod/semver"
11
13
)
12
14
@@ -81,7 +83,20 @@ func TidyModule(path string) *exec.Cmd {
81
83
82
84
// Run `go mod init` in the directory given by `path`.
83
85
func 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 )
85
100
modInit .Dir = path
86
101
return modInit
87
102
}
You can’t perform that action at this time.
0 commit comments