@@ -25,10 +25,8 @@ func usage() {
25
25
26
26
Options:
27
27
--identify-environment
28
- Produce an environment file specifying which Go version should be installed in the environment
29
- so that autobuilding will be successful. The location of this file is controlled by the
30
- environment variable CODEQL_EXTRACTOR_ENVIRONMENT_JSON, or defaults to 'environment.json' if
31
- that is not set.
28
+ Output some json on stdout specifying which Go version should be installed in the environment
29
+ so that autobuilding will be successful.
32
30
33
31
Build behavior:
34
32
@@ -745,8 +743,8 @@ func getVersionWhenGoModVersionNotFound(v versionInfo) (msg, version string) {
745
743
// There is no Go version installed in the environment. We have no indication which version
746
744
// was intended to be used to build this project. Go versions are generally backwards
747
745
// compatible, so we install the maximum supported version.
748
- msg = "No version of Go installed and no `go.mod` file found. Writing an environment " +
749
- "file specifying the maximum supported version of Go (" + maxGoVersion + ")."
746
+ msg = "No version of Go installed and no `go.mod` file found. Requesting the maximum " +
747
+ "supported version of Go (" + maxGoVersion + ")."
750
748
version = maxGoVersion
751
749
diagnostics .EmitNoGoModAndNoGoEnv (msg )
752
750
} else if outsideSupportedRange (v .goEnvVersion ) {
@@ -928,39 +926,19 @@ func getVersionToInstall(v versionInfo) (msg, version string) {
928
926
return getVersionWhenGoModVersionSupported (v )
929
927
}
930
928
931
- // Write an environment file to the current directory. If `version` is the empty string then
932
- // write an empty environment file, otherwise write an environment file specifying the version
933
- // of Go to install. The path to the environment file is specified by the
934
- // CODEQL_EXTRACTOR_ENVIRONMENT_JSON environment variable, or defaults to `environment.json`.
935
- func writeEnvironmentFile (version string ) {
929
+ // Output some JSON to stdout specifying the version of Go to install, unless `version` is the
930
+ // empty string.
931
+ func outputEnvironmentJson (version string ) {
936
932
var content string
937
933
if version == "" {
938
934
content = `{ "include": [] }`
939
935
} else {
940
936
content = `{ "include": [ { "go": { "version": "` + version + `" } } ] }`
941
937
}
938
+ _ , err := fmt .Fprint (os .Stdout , content )
942
939
943
- filename , ok := os .LookupEnv ("CODEQL_EXTRACTOR_ENVIRONMENT_JSON" )
944
- if ! ok {
945
- filename = "environment.json"
946
- }
947
-
948
- targetFile , err := os .Create (filename )
949
- if err != nil {
950
- log .Println ("Failed to create environment file " + filename + ": " )
951
- log .Println (err )
952
- return
953
- }
954
- defer func () {
955
- if err := targetFile .Close (); err != nil {
956
- log .Println ("Failed to close environment file " + filename + ":" )
957
- log .Println (err )
958
- }
959
- }()
960
-
961
- _ , err = targetFile .WriteString (content )
962
940
if err != nil {
963
- log .Println ("Failed to write to environment file " + filename + " : " )
941
+ log .Println ("Failed to write environment json to stdout : " )
964
942
log .Println (err )
965
943
}
966
944
}
@@ -984,7 +962,7 @@ func isGoInstalled() bool {
984
962
return err == nil
985
963
}
986
964
987
- // Get the version of Go to install and write it to an environment file .
965
+ // Get the version of Go to install and output it to stdout as json .
988
966
func identifyEnvironment () {
989
967
var v versionInfo
990
968
depMode := getDepMode ()
@@ -998,7 +976,7 @@ func identifyEnvironment() {
998
976
msg , versionToInstall := getVersionToInstall (v )
999
977
log .Println (msg )
1000
978
1001
- writeEnvironmentFile (versionToInstall )
979
+ outputEnvironmentJson (versionToInstall )
1002
980
}
1003
981
1004
982
func main () {
0 commit comments