Skip to content

Commit e5de4f2

Browse files
authored
Merge pull request github#15789 from github/mbg/go/autobuilder-review-comments
2 parents 73fe20f + 9b5bf51 commit e5de4f2

File tree

3 files changed

+21
-33
lines changed

3 files changed

+21
-33
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ func installDependenciesAndBuild() {
603603
}
604604
}
605605

606+
// Track all projects which could not be extracted successfully
607+
var unsuccessfulProjects = []string{}
608+
606609
// Attempt to extract all workspaces; we will tolerate individual extraction failures here
607610
for i, workspace := range workspaces {
608611
goVersionInfo := workspace.RequiredGoVersion()
@@ -639,13 +642,8 @@ func installDependenciesAndBuild() {
639642
}
640643

641644
workspaces[i].Extracted = extract(workspace)
642-
}
643-
644-
// Find all projects which could not be extracted successfully
645-
var unsuccessfulProjects = []string{}
646645

647-
for _, workspace := range workspaces {
648-
if !workspace.Extracted {
646+
if !workspaces[i].Extracted {
649647
unsuccessfulProjects = append(unsuccessfulProjects, workspace.BaseDir)
650648
}
651649
}
@@ -666,7 +664,7 @@ func installDependenciesAndBuild() {
666664
strings.Join(unsuccessfulProjects, ", "))
667665
diagnostics.EmitExtractionFailedForProjects(unsuccessfulProjects)
668666
} else {
669-
log.Println("Success: extraction succeeded for all discovered projects.")
667+
log.Printf("Success: extraction succeeded for all %d discovered project(s).\n", len(workspaces))
670668
}
671669
}
672670

go/extractor/project/project.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ var filesToRemove []string = []string{}
129129

130130
// Try to initialize a go.mod file for projects that do not already have one.
131131
func InitGoModForLegacyProject(path string) {
132-
log.Printf("Project appears to be a legacy Go project, attempting to initialize go.mod in %s\n", path)
132+
log.Printf("The code in %s seems to be missing a go.mod file. Attempting to initialize one...\n", path)
133133

134134
modInit := toolchain.InitModule(path)
135135

@@ -217,9 +217,13 @@ func discoverWorkspace(workFilePath string) GoWorkspace {
217217
if err != nil {
218218
// We couldn't read the `go.work` file for some reason; let's try to find `go.mod` files ourselves
219219
log.Printf("Unable to read %s, falling back to finding `go.mod` files manually:\n%s\n", workFilePath, err.Error())
220+
221+
goModFilePaths := findGoModFiles(baseDir)
222+
log.Printf("Discovered the following Go modules in %s:\n%s\n", baseDir, strings.Join(goModFilePaths, "\n"))
223+
220224
return GoWorkspace{
221225
BaseDir: baseDir,
222-
Modules: LoadGoModules(findGoModFiles(baseDir)),
226+
Modules: LoadGoModules(goModFilePaths),
223227
DepMode: GoGetWithModules,
224228
ModMode: getModMode(GoGetWithModules, baseDir),
225229
}
@@ -230,9 +234,13 @@ func discoverWorkspace(workFilePath string) GoWorkspace {
230234
if err != nil {
231235
// The `go.work` file couldn't be parsed for some reason; let's try to find `go.mod` files ourselves
232236
log.Printf("Unable to parse %s, falling back to finding `go.mod` files manually:\n%s\n", workFilePath, err.Error())
237+
238+
goModFilePaths := findGoModFiles(baseDir)
239+
log.Printf("Discovered the following Go modules in %s:\n%s\n", baseDir, strings.Join(goModFilePaths, "\n"))
240+
233241
return GoWorkspace{
234242
BaseDir: baseDir,
235-
Modules: LoadGoModules(findGoModFiles(baseDir)),
243+
Modules: LoadGoModules(goModFilePaths),
236244
DepMode: GoGetWithModules,
237245
ModMode: getModMode(GoGetWithModules, baseDir),
238246
}
@@ -471,8 +479,10 @@ func getBuildRoots(emitDiagnostics bool) (goWorkspaces []GoWorkspace, totalModul
471479

472480
// Finds Go workspaces in the current working directory.
473481
func GetWorkspaceInfo(emitDiagnostics bool) []GoWorkspace {
474-
bazelPaths := util.FindAllFilesWithName(".", "BUILD", "vendor")
475-
bazelPaths = append(bazelPaths, util.FindAllFilesWithName(".", "BUILD.bazel", "vendor")...)
482+
bazelPaths := slices.Concat(
483+
util.FindAllFilesWithName(".", "BUILD", "vendor"),
484+
util.FindAllFilesWithName(".", "BUILD.bazel", "vendor"),
485+
)
476486
if len(bazelPaths) > 0 {
477487
// currently not supported
478488
if emitDiagnostics {

go/extractor/util/util.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -320,27 +320,7 @@ func FindAllFilesWithName(root string, name string, dirsToSkip ...string) []stri
320320
return paths
321321
}
322322

323-
// Determines whether there are any Go source files in locations which do not have a Go.mod
324-
// file in the same directory or higher up in the file hierarchy, relative to the `root`.
325-
func AnyGoFilesOutsideDirs(root string, dirsToSkip ...string) bool {
326-
found := false
327-
filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
328-
if err != nil {
329-
return err
330-
}
331-
if d.IsDir() && slices.Contains(dirsToSkip, path) {
332-
return filepath.SkipDir
333-
}
334-
if filepath.Ext(d.Name()) == ".go" {
335-
found = true
336-
return filepath.SkipAll
337-
}
338-
return nil
339-
})
340-
return found
341-
}
342-
343-
// Returns an array of any Go source files in locations which do not have a Go.mod
323+
// Returns an array of any Go source files in locations which do not have a `go.mod`
344324
// file in the same directory or higher up in the file hierarchy, relative to the `root`.
345325
func GoFilesOutsideDirs(root string, dirsToSkip ...string) []string {
346326
result := []string{}

0 commit comments

Comments
 (0)