|
1 | 1 | package main
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "errors" |
4 | 5 | "fmt"
|
5 | 6 | "golang.org/x/mod/semver"
|
6 | 7 | "io/ioutil"
|
@@ -206,6 +207,51 @@ func checkVendor() bool {
|
206 | 207 | return true
|
207 | 208 | }
|
208 | 209 |
|
| 210 | +func getOsToolsSubdir() (string, error) { |
| 211 | + switch runtime.GOOS { |
| 212 | + case "darwin": |
| 213 | + return "osx64", nil |
| 214 | + case "linux": |
| 215 | + return "linux64", nil |
| 216 | + case "windows": |
| 217 | + return "win64", nil |
| 218 | + } |
| 219 | + return "", errors.New("Unknown OS: " + runtime.GOOS) |
| 220 | +} |
| 221 | + |
| 222 | +func getExtractorDir() (string, error) { |
| 223 | + mypath, err := os.Executable() |
| 224 | + if err == nil { |
| 225 | + return filepath.Dir(mypath), nil |
| 226 | + } |
| 227 | + log.Printf("Could not determine path of autobuilder: %v.\n", err) |
| 228 | + |
| 229 | + // Fall back to rebuilding our own path from the extractor root: |
| 230 | + extractorRoot := os.Getenv("CODEQL_EXTRACTOR_GO_ROOT") |
| 231 | + if extractorRoot == "" { |
| 232 | + return "", errors.New("CODEQL_EXTRACTOR_GO_ROOT not set") |
| 233 | + } |
| 234 | + |
| 235 | + osSubdir, err := getOsToolsSubdir() |
| 236 | + if err != nil { |
| 237 | + return "", err |
| 238 | + } |
| 239 | + |
| 240 | + return filepath.Join(extractorRoot, "tools", osSubdir), nil |
| 241 | +} |
| 242 | + |
| 243 | +func getExtractorPath() (string, error) { |
| 244 | + dirname, err := getExtractorDir() |
| 245 | + if err != nil { |
| 246 | + return "", err |
| 247 | + } |
| 248 | + extractor := filepath.Join(dirname, "go-extractor") |
| 249 | + if runtime.GOOS == "windows" { |
| 250 | + extractor = extractor + ".exe" |
| 251 | + } |
| 252 | + return extractor, nil |
| 253 | +} |
| 254 | + |
209 | 255 | func main() {
|
210 | 256 | if len(os.Args) > 1 {
|
211 | 257 | usage()
|
@@ -507,13 +553,9 @@ func main() {
|
507 | 553 | }
|
508 | 554 |
|
509 | 555 | // extract
|
510 |
| - mypath, err := os.Executable() |
| 556 | + extractor, err := getExtractorPath() |
511 | 557 | if err != nil {
|
512 |
| - log.Fatalf("Could not determine path of autobuilder: %v.\n", err) |
513 |
| - } |
514 |
| - extractor := filepath.Join(filepath.Dir(mypath), "go-extractor") |
515 |
| - if runtime.GOOS == "windows" { |
516 |
| - extractor = extractor + ".exe" |
| 558 | + log.Fatalf("Could not determine path of extractor: %v.\n", err) |
517 | 559 | }
|
518 | 560 |
|
519 | 561 | cwd, err := os.Getwd()
|
|
0 commit comments