Skip to content

Commit 0c93641

Browse files
authored
Merge pull request github#15361 from github/mbg/go/legacy-gopath-mode-deprecated
Go: Update autobuilder to deal with the upcoming deprecation of the legacy GOPATH mode
2 parents ce1d0d2 + 008585e commit 0c93641

File tree

51 files changed

+1045
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1045
-318
lines changed

go/extractor/autobuilder/autobuilder.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,33 @@ func tryBuild(cmd string, args ...string) bool {
7070
return res && (!CheckExtracted || checkExtractorRun())
7171
}
7272

73-
// Autobuild attempts to detect build system and run the corresponding command.
73+
// If a project is accompanied by a build script (such as a makefile), then we try executing such
74+
// build scripts to build the project. This type represents pairs of script names to check for
75+
// and the names of corresponding build tools to invoke if those scripts exist.
76+
type BuildScript struct {
77+
Tool string // The name of the command to execute if the build script exists
78+
Filename string // The name of the build script to check for
79+
}
80+
81+
// An array of build scripts to check for and corresponding commands that we can execute
82+
// if they exist.
83+
var BuildScripts = []BuildScript{
84+
{Tool: "make", Filename: "Makefile"},
85+
{Tool: "make", Filename: "makefile"},
86+
{Tool: "make", Filename: "GNUmakefile"},
87+
{Tool: "ninja", Filename: "build.ninja"},
88+
{Tool: "./build", Filename: "build"},
89+
{Tool: "./build.sh", Filename: "build.sh"},
90+
}
91+
92+
// Autobuild attempts to detect build systems based on the presence of build scripts from the
93+
// list in `BuildScripts` and run the corresponding command. This may invoke zero or more
94+
// build scripts in the order given by `BuildScripts`.
7495
func Autobuild() bool {
75-
return tryBuildIfExists("Makefile", "make") ||
76-
tryBuildIfExists("makefile", "make") ||
77-
tryBuildIfExists("GNUmakefile", "make") ||
78-
tryBuildIfExists("build.ninja", "ninja") ||
79-
tryBuildIfExists("build", "./build") ||
80-
tryBuildIfExists("build.sh", "./build.sh")
96+
for _, script := range BuildScripts {
97+
if tryBuildIfExists(script.Filename, script.Tool) {
98+
return true
99+
}
100+
}
101+
return false
81102
}

go/extractor/autobuilder/build-environment.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,22 @@ func outputEnvironmentJson(version string) {
267267
// Get the version of Go to install and output it to stdout as json.
268268
func IdentifyEnvironment() {
269269
var v versionInfo
270-
buildInfo := project.GetBuildInfo(false)
271-
goVersionInfo := project.TryReadGoDirective(buildInfo)
272-
v.goModVersion, v.goModVersionFound = goVersionInfo.Version, goVersionInfo.Found
270+
workspaces := project.GetWorkspaceInfo(false)
273271

272+
// Remove temporary extractor files (e.g. auto-generated go.mod files) when we are done
273+
defer project.RemoveTemporaryExtractorFiles()
274+
275+
// Find the greatest Go version required by any of the workspaces.
276+
greatestGoVersion := project.RequiredGoVersion(&workspaces)
277+
v.goModVersion, v.goModVersionFound = greatestGoVersion.Version, greatestGoVersion.Found
278+
279+
// Find which, if any, version of Go is installed on the system already.
274280
v.goEnvVersionFound = toolchain.IsInstalled()
275281
if v.goEnvVersionFound {
276282
v.goEnvVersion = toolchain.GetEnvGoVersion()[2:]
277283
}
278284

285+
// Determine which version of Go we should recommend to install.
279286
msg, versionToInstall := getVersionToInstall(v)
280287
log.Println(msg)
281288

0 commit comments

Comments
 (0)