Skip to content

Commit 6eac48c

Browse files
committed
Go: Refactor greatest version logic into dedicated function
1 parent a9d8643 commit 6eac48c

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

go/extractor/autobuilder/build-environment.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,7 @@ func IdentifyEnvironment() {
273273
defer project.RemoveTemporaryExtractorFiles()
274274

275275
// Find the greatest Go version required by any of the workspaces.
276-
greatestGoVersion := project.GoVersionInfo{Version: "", Found: false}
277-
for _, workspace := range workspaces {
278-
goVersionInfo := workspace.RequiredGoVersion()
279-
if goVersionInfo.Found && (!greatestGoVersion.Found || semver.Compare("v"+goVersionInfo.Version, "v"+greatestGoVersion.Version) > 0) {
280-
greatestGoVersion = goVersionInfo
281-
}
282-
}
276+
greatestGoVersion := project.RequiredGoVersion(&workspaces)
283277
v.goModVersion, v.goModVersionFound = greatestGoVersion.Version, greatestGoVersion.Found
284278

285279
// Find which, if any, version of Go is installed on the system already.

go/extractor/project/project.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ func (workspace *GoWorkspace) RequiredGoVersion() GoVersionInfo {
8989
return GoVersionInfo{Version: "", Found: false}
9090
}
9191

92+
// Finds the greatest Go version required by any of the given `workspaces`.
93+
// Returns a `GoVersionInfo` value with `Found: false` if no version information is available.
94+
func RequiredGoVersion(workspaces *[]GoWorkspace) GoVersionInfo {
95+
greatestGoVersion := GoVersionInfo{Version: "", Found: false}
96+
for _, workspace := range *workspaces {
97+
goVersionInfo := workspace.RequiredGoVersion()
98+
if goVersionInfo.Found && (!greatestGoVersion.Found || semver.Compare("v"+goVersionInfo.Version, "v"+greatestGoVersion.Version) > 0) {
99+
greatestGoVersion = goVersionInfo
100+
}
101+
}
102+
return greatestGoVersion
103+
}
104+
92105
// Determines whether any of the directory paths in the input are nested.
93106
func checkDirsNested(inputDirs []string) (string, bool) {
94107
// replace "." with "" so that we can check if all the paths are nested

0 commit comments

Comments
 (0)