Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ef0caa

Browse files
committed
Always discover subprojects
The documentation of the `--project-type` flag promises that subprojects will also be discovered:```--project-type string Only lint projects of the specified type and their subprojects. Can be {sketch|library|platform|all}. (default "all")```Under a specific combination of configurations a bug caused subprojects to not be discovered:- `--project-type` flag set to specific project type.- `--recursive` flag not used.- `PROJECT_PATH` is a folder (rather than file).So, for example, given this project structure:FooLibrary|-- examples| `-- FooExample| `-- FooExample.ino|-- src| `-- FooLibrary.h`-- library.propertiesThe following command only linted the library, and not the FooExample sketch:```arduino-lint --project-type library FooLibrary```Under any other configuration, subprojects were discovered and the FooExample sketch would be linted in the above example.
1 parent37a8a38 commit9ef0caa

File tree

2 files changed

+95
-64
lines changed

2 files changed

+95
-64
lines changed

‎internal/project/project.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,13 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
9292
returnnil,fmt.Errorf("Specified path %s is not an Arduino project",targetPath)
9393
}
9494

95+
varfoundParentProjects []Type
9596
ifconfiguration.SuperprojectTypeFilter()==projecttype.All||configuration.Recursive() {
9697
// Project discovery and/or type detection is required.
97-
foundParentProjects:=findProjectsUnderPath(targetPath,configuration.SuperprojectTypeFilter(),configuration.Recursive())
98-
for_,foundParentProject:=rangefoundParentProjects {
99-
foundProjects=append(foundProjects,foundParentProject)
100-
foundProjects=append(foundProjects,findSubprojects(foundParentProject,foundParentProject.ProjectType)...)
101-
}
98+
foundParentProjects=findProjectsUnderPath(targetPath,configuration.SuperprojectTypeFilter(),configuration.Recursive())
10299
}else {
103100
// Project was explicitly defined by user.
104-
foundProjects=append(foundProjects,
101+
foundParentProjects=append(foundParentProjects,
105102
Type{
106103
Path:targetPath,
107104
ProjectType:configuration.SuperprojectTypeFilter(),
@@ -110,6 +107,12 @@ func findProjects(targetPath *paths.Path) ([]Type, error) {
110107
)
111108
}
112109

110+
// Discover subprojects of all found projects.
111+
for_,foundParentProject:=rangefoundParentProjects {
112+
foundProjects=append(foundProjects,foundParentProject)
113+
foundProjects=append(foundProjects,findSubprojects(foundParentProject,foundParentProject.ProjectType)...)
114+
}
115+
113116
iffoundProjects==nil {
114117
returnnil,fmt.Errorf("No projects found under %s",targetPath)
115118
}

‎internal/project/project_test.go‎

Lines changed: 86 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package project
1717

1818
import (
19+
"fmt"
1920
"os"
2021
"reflect"
2122
"testing"
@@ -53,16 +54,16 @@ func TestFindProjects(t *testing.T) {
5354

5455
testTables:= []struct {
5556
testNamestring
56-
superprojectTypeFilterstring
57-
recursivestring
57+
superprojectTypeFilter[]string
58+
recursive[]string
5859
projectPaths []string
5960
errorAssertion assert.ErrorAssertionFunc
6061
expectedProjects []Type
6162
}{
6263
{
6364
"Sketch file",
64-
"all",
65-
"",
65+
[]string{"all","sketch"},
66+
[]string{"true","false"},
6667
[]string{sketchPath.Join("Sketch.ino").String()},
6768
assert.NoError,
6869
[]Type{
@@ -75,8 +76,8 @@ func TestFindProjects(t *testing.T) {
7576
},
7677
{
7778
"Library file",
78-
"all",
79-
"",
79+
[]string{"all","library"},
80+
[]string{"true","false"},
8081
[]string{libraryPath.Join("Library.h").String()},
8182
assert.NoError,
8283
[]Type{
@@ -94,8 +95,8 @@ func TestFindProjects(t *testing.T) {
9495
},
9596
{
9697
"Platform file",
97-
"all",
98-
"",
98+
[]string{"all","platform"},
99+
[]string{"true","false"},
99100
[]string{platformPath.Join("boards.txt").String()},
100101
assert.NoError,
101102
[]Type{
@@ -118,8 +119,8 @@ func TestFindProjects(t *testing.T) {
118119
},
119120
{
120121
"Package index file",
121-
"all",
122-
"",
122+
[]string{"all","package-index"},
123+
[]string{"true","false"},
123124
[]string{packageIndexFilePath.String()},
124125
assert.NoError,
125126
[]Type{
@@ -132,8 +133,8 @@ func TestFindProjects(t *testing.T) {
132133
},
133134
{
134135
"Explicit file",
135-
"sketch",
136-
"",
136+
[]string{"sketch"},
137+
[]string{"true","false"},
137138
[]string{libraryPath.Join("Library.h").String()},
138139
assert.NoError,
139140
[]Type{
@@ -146,8 +147,8 @@ func TestFindProjects(t *testing.T) {
146147
},
147148
{
148149
"Sketch folder",
149-
"all",
150-
"",
150+
[]string{"all","sketch"},
151+
[]string{"true","false"},
151152
[]string{sketchPath.String()},
152153
assert.NoError,
153154
[]Type{
@@ -160,8 +161,8 @@ func TestFindProjects(t *testing.T) {
160161
},
161162
{
162163
"Library folder",
163-
"all",
164-
"",
164+
[]string{"all","library"},
165+
[]string{"true","false"},
165166
[]string{libraryPath.String()},
166167
assert.NoError,
167168
[]Type{
@@ -179,8 +180,8 @@ func TestFindProjects(t *testing.T) {
179180
},
180181
{
181182
"Platform folder",
182-
"all",
183-
"",
183+
[]string{"all","platform"},
184+
[]string{"true","false"},
184185
[]string{platformPath.String()},
185186
assert.NoError,
186187
[]Type{
@@ -203,8 +204,8 @@ func TestFindProjects(t *testing.T) {
203204
},
204205
{
205206
"Package index folder",
206-
"all",
207-
"",
207+
[]string{"all","package-index"},
208+
[]string{"true","false"},
208209
[]string{packageIndexFolderPath.String()},
209210
assert.NoError,
210211
[]Type{
@@ -217,8 +218,8 @@ func TestFindProjects(t *testing.T) {
217218
},
218219
{
219220
"Explicit folder",
220-
"sketch",
221-
"false",
221+
[]string{"sketch"},
222+
[]string{"false"},
222223
[]string{libraryPath.String()},
223224
assert.NoError,
224225
[]Type{
@@ -230,9 +231,23 @@ func TestFindProjects(t *testing.T) {
230231
},
231232
},
232233
{
233-
"Projects folder, recursive",
234-
"all",
235-
"true",
234+
"Explicit folder",
235+
[]string{"sketch"},
236+
[]string{"true"},
237+
[]string{libraryPath.String()},
238+
assert.NoError,
239+
[]Type{
240+
{
241+
Path:libraryExamplePath,
242+
ProjectType:projecttype.Sketch,
243+
SuperprojectType:projecttype.Sketch,
244+
},
245+
},
246+
},
247+
{
248+
"Projects folder",
249+
[]string{"all"},
250+
[]string{"true"},
236251
[]string{projectsPath.String()},
237252
assert.NoError,
238253
[]Type{
@@ -253,18 +268,37 @@ func TestFindProjects(t *testing.T) {
253268
},
254269
},
255270
},
271+
{
272+
"Projects folder",
273+
[]string{"sketch"},
274+
[]string{"true"},
275+
[]string{projectsPath.String()},
276+
assert.NoError,
277+
[]Type{
278+
{
279+
Path:projectsPathLibraryExample,
280+
ProjectType:projecttype.Sketch,
281+
SuperprojectType:projecttype.Sketch,
282+
},
283+
{
284+
Path:projectsPathSketch,
285+
ProjectType:projecttype.Sketch,
286+
SuperprojectType:projecttype.Sketch,
287+
},
288+
},
289+
},
256290
{
257291
"Projects folder, non-recursive",
258-
"all",
259-
"false",
292+
[]string{"all"},
293+
[]string{"false"},
260294
[]string{projectsPath.String()},
261295
assert.Error,
262296
[]Type{},
263297
},
264298
{
265299
"Multiple target folders",
266-
"all",
267-
"true",
300+
[]string{"all"},
301+
[]string{"true"},
268302
[]string{projectsPath.String(),sketchPath.String()},
269303
assert.NoError,
270304
[]Type{
@@ -290,38 +324,32 @@ func TestFindProjects(t *testing.T) {
290324
},
291325
},
292326
},
293-
{
294-
"superproject type filter",
295-
"sketch",
296-
"true",
297-
[]string{projectsPath.String()},
298-
assert.NoError,
299-
[]Type{
300-
{
301-
Path:projectsPathLibraryExample,
302-
ProjectType:projecttype.Sketch,
303-
SuperprojectType:projecttype.Sketch,
304-
},
305-
{
306-
Path:projectsPathSketch,
307-
ProjectType:projecttype.Sketch,
308-
SuperprojectType:projecttype.Sketch,
309-
},
310-
},
311-
},
312327
}
313328

314329
for_,testTable:=rangetestTables {
315-
flags:=test.ConfigurationFlags()
316-
flags.Set("project-type",testTable.superprojectTypeFilter)
317-
iftestTable.recursive!="" {
318-
flags.Set("recursive",testTable.recursive)
319-
}
320-
configuration.Initialize(flags,testTable.projectPaths)
321-
foundProjects,err:=FindProjects()
322-
testTable.errorAssertion(t,err)
323-
iferr==nil {
324-
assert.True(t,reflect.DeepEqual(foundProjects,testTable.expectedProjects),testTable.testName)
330+
for_,superprojectTypeFilter:=rangetestTable.superprojectTypeFilter {
331+
for_,recursive:=rangetestTable.recursive {
332+
flags:=test.ConfigurationFlags()
333+
flags.Set("project-type",superprojectTypeFilter)
334+
ifrecursive!="" {
335+
flags.Set("recursive",recursive)
336+
}
337+
configuration.Initialize(flags,testTable.projectPaths)
338+
foundProjects,err:=FindProjects()
339+
testTable.errorAssertion(t,err)
340+
iferr==nil {
341+
assert.True(
342+
t,
343+
reflect.DeepEqual(foundProjects,testTable.expectedProjects),
344+
fmt.Sprintf(
345+
"%s (%s project-type=%s recursive=%s)",
346+
testTable.testName,
347+
testTable.projectPaths,
348+
superprojectTypeFilter,recursive,
349+
),
350+
)
351+
}
352+
}
325353
}
326354
}
327355
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp