Skip to content

Don't do project discovery when explicitly defined #100

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 1 commit into from
Dec 14, 2020
Merged
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
34 changes: 28 additions & 6 deletions project/project.go
Original file line number Diff line number Diff line change
@@ -57,8 +57,18 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
// If targetPath is a file, targetPath itself is the project, so it's only necessary to determine/verify the type.
if targetPath.IsNotDir() {
logrus.Debug("Projects path is file")
// The filename provides additional information about the project type. So rather than using isProject(), which doesn't make use this information, use a specialized function that does.
isProject, projectType := isProjectIndicatorFile(targetPath, configuration.SuperprojectTypeFilter())
var isProject bool
var projectType projecttype.Type
if configuration.SuperprojectTypeFilter() == projecttype.All {
// Project type detection is required.
// The filename provides additional information about the project type. So rather than using isProject(), which doesn't make use this information, use a specialized function that does.
isProject, projectType = isProjectIndicatorFile(targetPath, configuration.SuperprojectTypeFilter())
} else {
// Project was explicitly defined by user.
isProject = true
projectType = configuration.SuperprojectTypeFilter()
}

if isProject {
var projectPath *paths.Path
if projectType == projecttype.PackageIndex {
@@ -81,10 +91,22 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
return nil, fmt.Errorf("specified path %s is not an Arduino project", targetPath)
}

foundParentProjects := findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())
for _, foundParentProject := range foundParentProjects {
foundProjects = append(foundProjects, foundParentProject)
foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...)
if configuration.SuperprojectTypeFilter() == projecttype.All || configuration.Recursive() {
// Project discovery and/or type detection is required.
foundParentProjects := findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())
for _, foundParentProject := range foundParentProjects {
foundProjects = append(foundProjects, foundParentProject)
foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...)
}
} else {
// Project was explicitly defined by user.
foundProjects = append(foundProjects,
Type{
Path: targetPath,
ProjectType: configuration.SuperprojectTypeFilter(),
SuperprojectType: configuration.SuperprojectTypeFilter(),
},
)
}

if foundProjects == nil {
28 changes: 28 additions & 0 deletions project/project_test.go
Original file line number Diff line number Diff line change
@@ -130,6 +130,20 @@ func TestFindProjects(t *testing.T) {
},
},
},
{
"Explicit file",
"sketch",
"",
[]string{libraryPath.Join("Library.h").String()},
assert.NoError,
[]Type{
{
Path: libraryPath,
ProjectType: projecttype.Sketch,
SuperprojectType: projecttype.Sketch,
},
},
},
{
"Sketch folder",
"all",
@@ -201,6 +215,20 @@ func TestFindProjects(t *testing.T) {
},
},
},
{
"Explicit folder",
"sketch",
"false",
[]string{libraryPath.String()},
assert.NoError,
[]Type{
{
Path: libraryPath,
ProjectType: projecttype.Sketch,
SuperprojectType: projecttype.Sketch,
},
},
},
{
"Projects folder, recursive",
"all",