@@ -21,8 +21,12 @@ import (
21
21
22
22
func usage () {
23
23
fmt .Fprintf (os .Stderr ,
24
- `%s is a wrapper script that installs dependencies and calls the extractor, or if '--identify-environment'
25
- is passed then it produces a file 'environment.json' which specifies what go version is needed.
24
+ `When '--identify-environment' is passed then %s produces a file which specifies what Go
25
+ version is needed. The location of this file is controlled by the environment variable
26
+ CODEQL_EXTRACTOR_ENVIRONMENT_JSON, or defaults to "environment.json" if that is not set.
27
+
28
+ When no command line arguments are passed, %[1]s is a wrapper script that installs dependencies and
29
+ calls the extractor.
26
30
27
31
When LGTM_SRC is not set, the script installs dependencies as described below, and then invokes the
28
32
extractor in the working directory.
@@ -724,16 +728,15 @@ func checkForUnsupportedVersions(v versionInfo) (msg, version string) {
724
728
725
729
func checkForVersionsNotFound (v versionInfo ) (msg , version string ) {
726
730
if ! v .goInstallationFound && ! v .goDirectiveFound {
727
- msg = "No version of Go installed and no `go.mod` file found. Writing an " +
728
- "`environment.json` file specifying the maximum supported version of Go (" +
729
- maxGoVersion + ")."
731
+ msg = "No version of Go installed and no `go.mod` file found. Writing an environment " +
732
+ "file specifying the maximum supported version of Go (" + maxGoVersion + ")."
730
733
version = maxGoVersion
731
734
diagnostics .EmitNoGoModAndNoGoEnv (msg )
732
735
}
733
736
734
737
if ! v .goInstallationFound && v .goDirectiveFound {
735
- msg = "No version of Go installed. Writing an ` environment.json` file specifying the " +
736
- "version of Go found in the `go.mod` file (" + v .goModVersion + ")."
738
+ msg = "No version of Go installed. Writing an environment file specifying the version " +
739
+ "of Go found in the `go.mod` file (" + v .goModVersion + ")."
737
740
version = v .goModVersion
738
741
diagnostics .EmitNoGoEnv (msg )
739
742
}
@@ -751,8 +754,8 @@ func compareVersions(v versionInfo) (msg, version string) {
751
754
if semver .Compare ("v" + v .goModVersion , "v" + v .goEnvVersion ) > 0 {
752
755
msg = "The version of Go installed in the environment (" + v .goEnvVersion +
753
756
") is lower than the version found in the `go.mod` file (" + v .goModVersion +
754
- ").\n Writing an ` environment.json` file specifying the version of Go from the " +
755
- "`go.mod` file (" + v .goModVersion + ")."
757
+ ").\n Writing an environment file specifying the version of Go from the `go.mod` " +
758
+ "file (" + v .goModVersion + ")."
756
759
version = v .goModVersion
757
760
diagnostics .EmitVersionGoModHigherVersionEnvironment (msg )
758
761
} else {
@@ -788,22 +791,27 @@ func writeEnvironmentFile(version string) {
788
791
content = `{ "include": [ { "go": { "version": "` + version + `" } } ] }`
789
792
}
790
793
791
- targetFile , err := os .Create ("environment.json" )
794
+ filename , ok := os .LookupEnv ("CODEQL_EXTRACTOR_ENVIRONMENT_JSON" )
795
+ if ! ok {
796
+ filename = "environment.json"
797
+ }
798
+
799
+ targetFile , err := os .Create (filename )
792
800
if err != nil {
793
- log .Println ("Failed to create environment.json : " )
801
+ log .Println ("Failed to create environment file " + filename + " : " )
794
802
log .Println (err )
795
803
return
796
804
}
797
805
defer func () {
798
806
if err := targetFile .Close (); err != nil {
799
- log .Println ("Failed to close environment.json :" )
807
+ log .Println ("Failed to close environment file " + filename + " :" )
800
808
log .Println (err )
801
809
}
802
810
}()
803
811
804
812
_ , err = targetFile .WriteString (content )
805
813
if err != nil {
806
- log .Println ("Failed to write to environment.json : " )
814
+ log .Println ("Failed to write to environment file " + filename + " : " )
807
815
log .Println (err )
808
816
}
809
817
}
0 commit comments