Skip to content

Commit 617bb1b

Browse files
committed
Search child folders of subprojects parent folder for subprojects
Previously, the subprojects parent folder was searched for subprojects. Due to the recursive search setting, that still found library example sketches (after unnecessarily checking the examples folder itself for a sketch). However, the subproject search of platform bundled libraries is not recursive (because the libraries must be directly under the libraries folder), meaning these subprojects were not discovered.
1 parent 9d80c17 commit 617bb1b

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

project/project.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func findProjectsUnderPath(targetPath *paths.Path, projectTypeFilter projecttype
120120
// findSubprojects finds subprojects of the given project.
121121
// For example, the subprojects of a library are its example sketches.
122122
func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) []Type {
123-
subprojectFolderNames := []string{}
123+
subprojectsFolderNames := []string{}
124124
var subProjectType projecttype.Type
125125
var searchPathsRecursively bool
126126

@@ -130,11 +130,11 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [
130130
// Sketches don't have subprojects
131131
return nil
132132
case projecttype.Library:
133-
subprojectFolderNames = append(subprojectFolderNames, library.ExamplesFolderSupportedNames()...)
133+
subprojectsFolderNames = append(subprojectsFolderNames, library.ExamplesFolderSupportedNames()...)
134134
subProjectType = projecttype.Sketch
135135
searchPathsRecursively = true // Examples sketches can be under nested subfolders
136136
case projecttype.Platform:
137-
subprojectFolderNames = append(subprojectFolderNames, platform.BundledLibrariesFolderNames()...)
137+
subprojectsFolderNames = append(subprojectsFolderNames, platform.BundledLibrariesFolderNames()...)
138138
subProjectType = projecttype.Library
139139
searchPathsRecursively = false // Bundled libraries must be in the root of the libraries folder
140140
case projecttype.PackageIndex:
@@ -146,9 +146,19 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [
146146

147147
// Search the subproject paths for projects.
148148
var immediateSubprojects []Type
149-
for _, subprojectFolderName := range subprojectFolderNames {
150-
subprojectPath := superproject.Path.Join(subprojectFolderName)
151-
immediateSubprojects = append(immediateSubprojects, findProjectsUnderPath(subprojectPath, subProjectType, searchPathsRecursively)...)
149+
for _, subprojectsFolderName := range subprojectsFolderNames {
150+
subprojectsPath := superproject.Path.Join(subprojectsFolderName)
151+
if subprojectsPath.Exist() {
152+
directoryListing, err := subprojectsPath.ReadDir()
153+
if err != nil {
154+
panic(err)
155+
}
156+
directoryListing.FilterDirs()
157+
158+
for _, subprojectPath := range directoryListing {
159+
immediateSubprojects = append(immediateSubprojects, findProjectsUnderPath(subprojectPath, subProjectType, searchPathsRecursively)...)
160+
}
161+
}
152162
}
153163

154164
var allSubprojects []Type

0 commit comments

Comments
 (0)