Skip to content

Fix subproject discovery #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func Initialize(flags *pflag.FlagSet, projectPaths []string) error {

versionMode, _ = flags.GetBool("version")

targetPaths = nil
if len(projectPaths) == 0 {
// Default to using current working directory.
workingDirectoryPath, err := os.Getwd()
Expand Down
3 changes: 0 additions & 3 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,14 @@ func TestInitializeVersion(t *testing.T) {
}

func TestInitializeProjectPath(t *testing.T) {
targetPaths = nil
assert.Nil(t, Initialize(test.ConfigurationFlags(), []string{}))
workingDirectoryPath, err := os.Getwd()
require.Nil(t, err)
assert.Equal(t, paths.NewPathList(workingDirectoryPath), TargetPaths(), "Default PROJECT_PATH to current working directory")

targetPaths = nil
assert.Nil(t, Initialize(test.ConfigurationFlags(), projectPaths))
assert.Equal(t, paths.NewPathList(projectPaths[0]), TargetPaths())

targetPaths = nil
assert.Error(t, Initialize(test.ConfigurationFlags(), []string{"/nonexistent"}))
}

Expand Down
32 changes: 22 additions & 10 deletions project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
return nil, fmt.Errorf("specified path %s is not an Arduino project", targetPath)
}

foundProjects = append(foundProjects, findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())...)
foundParentProjects := findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())
for _, foundParentProject := range foundParentProjects {
foundProjects = append(foundProjects, foundParentProject)
foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...)
}

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

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

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

foundProjects = append(foundProjects, findSubprojects(foundProject, foundProject.ProjectType)...)

// Don't search recursively past a project.
return foundProjects
}
Expand All @@ -120,7 +122,7 @@ func findProjectsUnderPath(targetPath *paths.Path, projectTypeFilter projecttype
// findSubprojects finds subprojects of the given project.
// For example, the subprojects of a library are its example sketches.
func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) []Type {
subprojectFolderNames := []string{}
subprojectsFolderNames := []string{}
var subProjectType projecttype.Type
var searchPathsRecursively bool

Expand All @@ -130,11 +132,11 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [
// Sketches don't have subprojects
return nil
case projecttype.Library:
subprojectFolderNames = append(subprojectFolderNames, library.ExamplesFolderSupportedNames()...)
subprojectsFolderNames = append(subprojectsFolderNames, library.ExamplesFolderSupportedNames()...)
subProjectType = projecttype.Sketch
searchPathsRecursively = true // Examples sketches can be under nested subfolders
case projecttype.Platform:
subprojectFolderNames = append(subprojectFolderNames, platform.BundledLibrariesFolderNames()...)
subprojectsFolderNames = append(subprojectsFolderNames, platform.BundledLibrariesFolderNames()...)
subProjectType = projecttype.Library
searchPathsRecursively = false // Bundled libraries must be in the root of the libraries folder
case projecttype.PackageIndex:
Expand All @@ -146,9 +148,19 @@ func findSubprojects(superproject Type, apexSuperprojectType projecttype.Type) [

// Search the subproject paths for projects.
var immediateSubprojects []Type
for _, subprojectFolderName := range subprojectFolderNames {
subprojectPath := superproject.Path.Join(subprojectFolderName)
immediateSubprojects = append(immediateSubprojects, findProjectsUnderPath(subprojectPath, subProjectType, searchPathsRecursively)...)
for _, subprojectsFolderName := range subprojectsFolderNames {
subprojectsPath := superproject.Path.Join(subprojectsFolderName)
if subprojectsPath.Exist() {
directoryListing, err := subprojectsPath.ReadDir()
if err != nil {
panic(err)
}
directoryListing.FilterDirs()

for _, subprojectPath := range directoryListing {
immediateSubprojects = append(immediateSubprojects, findProjectsUnderPath(subprojectPath, subProjectType, searchPathsRecursively)...)
}
}
}

var allSubprojects []Type
Expand Down
Loading