@@ -24,9 +24,10 @@ func usage() {
2424
2525// extractTests is set (a) if we were manually commanded to extract tests via the relevant
2626// environment variable / extractor option, or (b) we're mimicking a `go test` command.
27- func parseFlags (args []string , mimic bool , extractTests bool ) ([]string , []string , bool ) {
27+ func parseFlags (args []string , mimic bool , extractTests bool ) ([]string , []string , bool , string ) {
2828 i := 0
2929 buildFlags := []string {}
30+ var sourceRoot string
3031 for ; i < len (args ) && strings .HasPrefix (args [i ], "-" ); i ++ {
3132 if args [i ] == "--" {
3233 i ++
@@ -61,6 +62,18 @@ func parseFlags(args []string, mimic bool, extractTests bool) ([]string, []strin
6162 } else {
6263 log .Fatalf ("--mimic requires an argument, e.g. --mimic go" )
6364 }
65+ case "--source-root" :
66+ // The extractor can be called by the autobuilder with the working directory set to
67+ // the directory containing the workspace we're extracting, and this may be a
68+ // subdirectory of the actual source root. This argument lets us resolve paths that
69+ // are relative to that source root, e.g. for the list of overlay changed files.
70+ if i + 1 < len (args ) {
71+ i ++
72+ sourceRoot = args [i ]
73+ log .Printf ("Source root is %s" , sourceRoot )
74+ } else {
75+ log .Fatalf ("--source-root requires an argument, e.g. --source-root /path/to/root" )
76+ }
6477 }
6578 }
6679
@@ -93,14 +106,14 @@ func parseFlags(args []string, mimic bool, extractTests bool) ([]string, []strin
93106 cpuprofile = os .Getenv ("CODEQL_EXTRACTOR_GO_CPU_PROFILE" )
94107 memprofile = os .Getenv ("CODEQL_EXTRACTOR_GO_MEM_PROFILE" )
95108
96- return buildFlags , args [i :], extractTests
109+ return buildFlags , args [i :], extractTests , sourceRoot
97110}
98111
99112func main () {
100113 util .SetLogLevel ()
101114
102115 extractTestsDefault := os .Getenv ("CODEQL_EXTRACTOR_GO_OPTION_EXTRACT_TESTS" ) == "true"
103- buildFlags , patterns , extractTests := parseFlags (os .Args [1 :], false , extractTestsDefault )
116+ buildFlags , patterns , extractTests , sourceRoot := parseFlags (os .Args [1 :], false , extractTestsDefault )
104117
105118 if cpuprofile != "" {
106119 f , err := os .Create (cpuprofile )
@@ -120,7 +133,7 @@ func main() {
120133 }
121134
122135 log .Printf ("Build flags: '%s'; patterns: '%s'\n " , strings .Join (buildFlags , " " ), strings .Join (patterns , " " ))
123- err := extractor .ExtractWithFlags (buildFlags , patterns , extractTests )
136+ err := extractor .ExtractWithFlags (buildFlags , patterns , extractTests , sourceRoot )
124137 if err != nil {
125138 errString := err .Error ()
126139 if strings .Contains (errString , "unexpected directory layout:" ) {
0 commit comments