This repository was archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
Autobuilder: fall back when os.Executable fails #383
Merged
smowton
merged 1 commit into
github:main
from
smowton:smowton/feature/work-around-broken-os-executable
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||||
package main | ||||||
|
||||||
import ( | ||||||
"errors" | ||||||
"fmt" | ||||||
"golang.org/x/mod/semver" | ||||||
"io/ioutil" | ||||||
|
@@ -206,6 +207,51 @@ func checkVendor() bool { | |||||
return true | ||||||
} | ||||||
|
||||||
func getOsToolsSubdir() (string, error) { | ||||||
switch runtime.GOOS { | ||||||
case "darwin": | ||||||
return "osx64", nil | ||||||
case "linux": | ||||||
return "linux64", nil | ||||||
case "windows": | ||||||
return "win64", nil | ||||||
} | ||||||
return "", errors.New("Unknown OS: " + runtime.GOOS) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I like the
Suggested change
|
||||||
} | ||||||
|
||||||
func getExtractorDir() (string, error) { | ||||||
mypath, err := os.Executable() | ||||||
if err == nil { | ||||||
return filepath.Dir(mypath), nil | ||||||
} | ||||||
log.Printf("Could not determine path of autobuilder: %v.\n", err) | ||||||
|
||||||
// Fall back to rebuilding our own path from the extractor root: | ||||||
extractorRoot := os.Getenv("CODEQL_EXTRACTOR_GO_ROOT") | ||||||
if extractorRoot == "" { | ||||||
return "", errors.New("CODEQL_EXTRACTOR_GO_ROOT not set") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably have a similar message here as when |
||||||
} | ||||||
|
||||||
osSubdir, err := getOsToolsSubdir() | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
|
||||||
return filepath.Join(extractorRoot, "tools", osSubdir), nil | ||||||
} | ||||||
|
||||||
func getExtractorPath() (string, error) { | ||||||
dirname, err := getExtractorDir() | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
extractor := filepath.Join(dirname, "go-extractor") | ||||||
if runtime.GOOS == "windows" { | ||||||
extractor = extractor + ".exe" | ||||||
} | ||||||
return extractor, nil | ||||||
} | ||||||
|
||||||
func main() { | ||||||
if len(os.Args) > 1 { | ||||||
usage() | ||||||
|
@@ -507,13 +553,9 @@ func main() { | |||||
} | ||||||
|
||||||
// extract | ||||||
mypath, err := os.Executable() | ||||||
extractor, err := getExtractorPath() | ||||||
if err != nil { | ||||||
log.Fatalf("Could not determine path of autobuilder: %v.\n", err) | ||||||
} | ||||||
extractor := filepath.Join(filepath.Dir(mypath), "go-extractor") | ||||||
if runtime.GOOS == "windows" { | ||||||
extractor = extractor + ".exe" | ||||||
log.Fatalf("Could not determine path of extractor: %v.\n", err) | ||||||
} | ||||||
|
||||||
cwd, err := os.Getwd() | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is known as
os.Getenv("CODEQL_PLATFORM")
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but that was being filtered out, presumably also by the tracer. It was known to
autobuild.sh
but not its childgo-autobuild
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matt-gretton-dann The tracer shouldn't filter out
CODEQL_
variables, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tracer has a concept of critical variables which it tries to preserve in the environment. But also when the tracer is turned off (as is the case when we trace go-autouild) we remove those critical variables. I believe this was historically deemed appropriate to try and preserve the environment the user would expect
CODEQL_PLATFORM
is one of those critical env. vars.