Skip to content

Commit 42cac64

Browse files
committed
Remove redundant subproject discovery
Previously, project.findProjectsUnderPath() searched for projects and subprojects under the given path. The problem with this is that project.findSubprojects() uses project.findProjectsUnderPath() to detect subprojects, which resulted in subproject duplicates. Making the project and subproject discovery distinct steps fixes this and also makes the code easier to follow.
1 parent 617bb1b commit 42cac64

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

project/project.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
7575
return nil, fmt.Errorf("specified path %s is not an Arduino project", targetPath)
7676
}
7777

78-
foundProjects = append(foundProjects, findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())...)
78+
foundParentProjects := findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())
79+
for _, foundParentProject := range foundParentProjects {
80+
foundProjects = append(foundProjects, foundParentProject)
81+
foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...)
82+
}
7983

8084
if foundProjects == nil {
8185
return nil, fmt.Errorf("no projects found under %s", targetPath)
@@ -84,7 +88,7 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
8488
return foundProjects, nil
8589
}
8690

87-
// findProjectsUnderPath finds projects of the given type and subprojects of those projects. It returns a slice containing the definitions of all found projects.
91+
// findProjectsUnderPath finds projects of the given type under the given path. It returns a slice containing the definitions of all found projects.
8892
func findProjectsUnderPath(targetPath *paths.Path, projectTypeFilter projecttype.Type, recursive bool) []Type {
8993
var foundProjects []Type
9094

@@ -99,8 +103,6 @@ func findProjectsUnderPath(targetPath *paths.Path, projectTypeFilter projecttype
99103
}
100104
foundProjects = append(foundProjects, foundProject)
101105

102-
foundProjects = append(foundProjects, findSubprojects(foundProject, foundProject.ProjectType)...)
103-
104106
// Don't search recursively past a project.
105107
return foundProjects
106108
}

0 commit comments

Comments
 (0)