@@ -546,75 +546,77 @@ func installDependenciesAndBuild() {
546546
547547 // determine how to install dependencies and whether a GOPATH needs to be set up before
548548 // extraction
549- buildInfo := project .GetBuildInfo (true )
549+ buildInfos := project .GetBuildInfo (true )
550550 if _ , present := os .LookupEnv ("GO111MODULE" ); ! present {
551551 os .Setenv ("GO111MODULE" , "auto" )
552552 }
553553
554- goVersionInfo := project .TryReadGoDirective (buildInfo )
554+ for _ , buildInfo := range buildInfos {
555+ goVersionInfo := project .TryReadGoDirective (buildInfo )
555556
556- // This diagnostic is not required if the system Go version is 1.21 or greater, since the
557- // Go tooling should install required Go versions as needed.
558- if semver .Compare (toolchain .GetEnvGoSemVer (), "v1.21.0" ) < 0 && goVersionInfo .Found && semver .Compare ("v" + goVersionInfo .Version , toolchain .GetEnvGoSemVer ()) > 0 {
559- diagnostics .EmitNewerGoVersionNeeded (toolchain .GetEnvGoSemVer (), "v" + goVersionInfo .Version )
560- if val , _ := os .LookupEnv ("GITHUB_ACTIONS" ); val == "true" {
561- log .Printf (
562- "The go.mod file requires version %s of Go, but version %s is installed. Consider adding an actions/setup-go step to your workflow.\n " ,
563- "v" + goVersionInfo .Version ,
564- toolchain .GetEnvGoSemVer ())
557+ // This diagnostic is not required if the system Go version is 1.21 or greater, since the
558+ // Go tooling should install required Go versions as needed.
559+ if semver .Compare (toolchain .GetEnvGoSemVer (), "v1.21.0" ) < 0 && goVersionInfo .Found && semver .Compare ("v" + goVersionInfo .Version , toolchain .GetEnvGoSemVer ()) > 0 {
560+ diagnostics .EmitNewerGoVersionNeeded (toolchain .GetEnvGoSemVer (), "v" + goVersionInfo .Version )
561+ if val , _ := os .LookupEnv ("GITHUB_ACTIONS" ); val == "true" {
562+ log .Printf (
563+ "The go.mod file requires version %s of Go, but version %s is installed. Consider adding an actions/setup-go step to your workflow.\n " ,
564+ "v" + goVersionInfo .Version ,
565+ toolchain .GetEnvGoSemVer ())
566+ }
565567 }
566- }
567568
568- fixGoVendorIssues (& buildInfo , goVersionInfo .Found )
569+ fixGoVendorIssues (& buildInfo , goVersionInfo .Found )
569570
570- tryUpdateGoModAndGoSum (buildInfo )
571+ tryUpdateGoModAndGoSum (buildInfo )
571572
572- importpath := getImportPath ()
573- needGopath := getNeedGopath (buildInfo , importpath )
573+ importpath := getImportPath ()
574+ needGopath := getNeedGopath (buildInfo , importpath )
574575
575- inLGTM := os .Getenv ("LGTM_SRC" ) != "" || os .Getenv ("LGTM_INDEX_NEED_GOPATH" ) != ""
576+ inLGTM := os .Getenv ("LGTM_SRC" ) != "" || os .Getenv ("LGTM_INDEX_NEED_GOPATH" ) != ""
576577
577- if inLGTM && needGopath {
578- paths := moveToTemporaryGopath (srcdir , importpath )
578+ if inLGTM && needGopath {
579+ paths := moveToTemporaryGopath (srcdir , importpath )
579580
580- // schedule restoring the contents of newdir to their original location after this function completes:
581- defer restoreRepoLayout (paths .newdir , paths .files , filepath .Base (paths .scratch ), srcdir )
581+ // schedule restoring the contents of newdir to their original location after this function completes:
582+ defer restoreRepoLayout (paths .newdir , paths .files , filepath .Base (paths .scratch ), srcdir )
582583
583- pt := createPathTransformerFile (paths .newdir )
584- defer os .Remove (pt .Name ())
584+ pt := createPathTransformerFile (paths .newdir )
585+ defer os .Remove (pt .Name ())
585586
586- writePathTransformerFile (pt , paths .realSrc , paths .root , paths .newdir )
587- setGopath (paths .root )
588- }
589-
590- // check whether an explicit dependency installation command was provided
591- inst := util .Getenv ("CODEQL_EXTRACTOR_GO_BUILD_COMMAND" , "LGTM_INDEX_BUILD_COMMAND" )
592- shouldInstallDependencies := false
593- if inst == "" {
594- shouldInstallDependencies = buildWithoutCustomCommands (buildInfo .ModMode )
595- } else {
596- buildWithCustomCommands (inst )
597- }
587+ writePathTransformerFile (pt , paths .realSrc , paths .root , paths .newdir )
588+ setGopath (paths .root )
589+ }
598590
599- if buildInfo . ModMode == project . ModVendor {
600- // test if running `go` with -mod=vendor works, and if it doesn't, try to fallback to -mod=mod
601- // or not set if the go version < 1.14. Note we check this post-build in case the build brings
602- // the vendor directory up to date.
603- if ! checkVendor () {
604- buildInfo . ModMode = project . ModMod
605- log . Println ( "The vendor directory is not consistent with the go.mod; not using vendored dependencies." )
591+ // check whether an explicit dependency installation command was provided
592+ inst := util . Getenv ( "CODEQL_EXTRACTOR_GO_BUILD_COMMAND" , "LGTM_INDEX_BUILD_COMMAND" )
593+ shouldInstallDependencies := false
594+ if inst == "" {
595+ shouldInstallDependencies = buildWithoutCustomCommands ( buildInfo . ModMode )
596+ } else {
597+ buildWithCustomCommands ( inst )
606598 }
607- }
608599
609- if shouldInstallDependencies {
610600 if buildInfo .ModMode == project .ModVendor {
611- log .Printf ("Skipping dependency installation because a Go vendor directory was found." )
612- } else {
613- installDependencies (buildInfo )
601+ // test if running `go` with -mod=vendor works, and if it doesn't, try to fallback to -mod=mod
602+ // or not set if the go version < 1.14. Note we check this post-build in case the build brings
603+ // the vendor directory up to date.
604+ if ! checkVendor () {
605+ buildInfo .ModMode = project .ModMod
606+ log .Println ("The vendor directory is not consistent with the go.mod; not using vendored dependencies." )
607+ }
614608 }
615- }
616609
617- extract (buildInfo )
610+ if shouldInstallDependencies {
611+ if buildInfo .ModMode == project .ModVendor {
612+ log .Printf ("Skipping dependency installation because a Go vendor directory was found." )
613+ } else {
614+ installDependencies (buildInfo )
615+ }
616+ }
617+
618+ extract (buildInfo )
619+ }
618620}
619621
620622func main () {
0 commit comments