Skip to content

Commit 3337e70

Browse files
committed
Don't do project discovery when explicitly defined
Previously, the project path discovery and type detection were done even when the user's settings explicitely defined these things. When the contents of the given path did not contain something slightly resembling a project of the given type, the process exited. That behavior is the only one possible when a project is not explicitely defined by the user, but in the case of an explicit definition, this is an unnecessary short circuiting of the process. The checks can still be run. This will result in the same exit status as before, but the check results may provide the user with helpful information about why their project is invalid.
1 parent d6fbfe1 commit 3337e70

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

Diff for: project/project.go

+28-6
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
5757
// If targetPath is a file, targetPath itself is the project, so it's only necessary to determine/verify the type.
5858
if targetPath.IsNotDir() {
5959
logrus.Debug("Projects path is file")
60-
// 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.
61-
isProject, projectType := isProjectIndicatorFile(targetPath, configuration.SuperprojectTypeFilter())
60+
var isProject bool
61+
var projectType projecttype.Type
62+
if configuration.SuperprojectTypeFilter() == projecttype.All {
63+
// Project type detection is required.
64+
// 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.
65+
isProject, projectType = isProjectIndicatorFile(targetPath, configuration.SuperprojectTypeFilter())
66+
} else {
67+
// Project was explicitly defined by user.
68+
isProject = true
69+
projectType = configuration.SuperprojectTypeFilter()
70+
}
71+
6272
if isProject {
6373
var projectPath *paths.Path
6474
if projectType == projecttype.PackageIndex {
@@ -81,10 +91,22 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
8191
return nil, fmt.Errorf("specified path %s is not an Arduino project", targetPath)
8292
}
8393

84-
foundParentProjects := findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())
85-
for _, foundParentProject := range foundParentProjects {
86-
foundProjects = append(foundProjects, foundParentProject)
87-
foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...)
94+
if configuration.SuperprojectTypeFilter() == projecttype.All || configuration.Recursive() {
95+
// Project discovery and/or type detection is required.
96+
foundParentProjects := findProjectsUnderPath(targetPath, configuration.SuperprojectTypeFilter(), configuration.Recursive())
97+
for _, foundParentProject := range foundParentProjects {
98+
foundProjects = append(foundProjects, foundParentProject)
99+
foundProjects = append(foundProjects, findSubprojects(foundParentProject, foundParentProject.ProjectType)...)
100+
}
101+
} else {
102+
// Project was explicitly defined by user.
103+
foundProjects = append(foundProjects,
104+
Type{
105+
Path: targetPath,
106+
ProjectType: configuration.SuperprojectTypeFilter(),
107+
SuperprojectType: configuration.SuperprojectTypeFilter(),
108+
},
109+
)
88110
}
89111

90112
if foundProjects == nil {

Diff for: project/project_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ func TestFindProjects(t *testing.T) {
130130
},
131131
},
132132
},
133+
{
134+
"Explicit file",
135+
"sketch",
136+
"",
137+
[]string{libraryPath.Join("Library.h").String()},
138+
assert.NoError,
139+
[]Type{
140+
{
141+
Path: libraryPath,
142+
ProjectType: projecttype.Sketch,
143+
SuperprojectType: projecttype.Sketch,
144+
},
145+
},
146+
},
133147
{
134148
"Sketch folder",
135149
"all",
@@ -201,6 +215,20 @@ func TestFindProjects(t *testing.T) {
201215
},
202216
},
203217
},
218+
{
219+
"Explicit folder",
220+
"sketch",
221+
"false",
222+
[]string{libraryPath.String()},
223+
assert.NoError,
224+
[]Type{
225+
{
226+
Path: libraryPath,
227+
ProjectType: projecttype.Sketch,
228+
SuperprojectType: projecttype.Sketch,
229+
},
230+
},
231+
},
204232
{
205233
"Projects folder, recursive",
206234
"all",

0 commit comments

Comments
 (0)