Skip to content

Commit 38c2f3f

Browse files
authored
Merge pull request #143 from arduino/per1234/exempt-hidden-boards
Allow incomplete hidden board definitions
2 parents 29ccb0e + 170ffd8 commit 38c2f3f

File tree

4 files changed

+67
-51
lines changed

4 files changed

+67
-51
lines changed

Diff for: internal/project/platform/boardstxt/boardstxt.go

+15
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,18 @@ func BoardIDs(boardsTxt *properties.Map) []string {
8080

8181
return boardIDs[:boardIDCount]
8282
}
83+
84+
// VisibleBoardIDs returns the list of IDs for non-hidden boards from the given boards.txt properties.
85+
func VisibleBoardIDs(boardsTxt *properties.Map) []string {
86+
boardIDs := BoardIDs(boardsTxt)
87+
boardIDCount := 0
88+
for _, boardID := range boardIDs {
89+
if !boardsTxt.ContainsKey(boardID + ".hide") {
90+
// This element is a visible board, retain it in the section of the array that will be returned.
91+
boardIDs[boardIDCount] = boardID
92+
boardIDCount++
93+
}
94+
}
95+
96+
return boardIDs[:boardIDCount]
97+
}

Diff for: internal/project/platform/boardstxt/boardstxt_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,16 @@ func TestBoardIDs(t *testing.T) {
9292
boardsTxt.Set("baz.name", "qwer")
9393
assert.ElementsMatch(t, []string{"uno", "baz"}, BoardIDs(boardsTxt))
9494
}
95+
96+
func TestVisibleBoardIDs(t *testing.T) {
97+
boardsTxt := properties.NewFromHashmap(validBoardsTxtMap)
98+
99+
assert.ElementsMatch(t, []string{"uno"}, VisibleBoardIDs(boardsTxt))
100+
101+
boardsTxt.Set("menu.foo", "asdf")
102+
boardsTxt.Set("menu.bar", "zxcv")
103+
boardsTxt.Set("baz.name", "qwer")
104+
boardsTxt.Set("bat.name", "sdfg")
105+
boardsTxt.Set("bat.hide", "")
106+
assert.ElementsMatch(t, []string{"uno", "baz"}, VisibleBoardIDs(boardsTxt))
107+
}

Diff for: internal/project/projectdata/platform.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func InitializeForPlatform(project project.Type) {
3737

3838
boardsTxtMenuIds = boardstxt.MenuIDs(boardsTxt)
3939
boardsTxtBoardIds = boardstxt.BoardIDs(boardsTxt)
40+
boardsTxtVisibleBoardIds = boardstxt.VisibleBoardIDs(boardsTxt)
4041
}
4142

4243
programmersTxtExists = ProjectPath().Join("programmers.txt").Exist()
@@ -95,11 +96,18 @@ func BoardsTxtMenuIds() []string {
9596

9697
var boardsTxtBoardIds []string
9798

98-
// BoardsTxtMenuIds returns the list of board IDs present in the platform's boards.txt.
99+
// BoardsTxtBoardIds returns the list of board IDs present in the platform's boards.txt.
99100
func BoardsTxtBoardIds() []string {
100101
return boardsTxtBoardIds
101102
}
102103

104+
var boardsTxtVisibleBoardIds []string
105+
106+
// BoardsTxtVisibleBoardIds returns the list of IDs for visible boards present in the platform's boards.txt.
107+
func BoardsTxtVisibleBoardIds() []string {
108+
return boardsTxtVisibleBoardIds
109+
}
110+
103111
var programmersTxtExists bool
104112

105113
// ProgrammersTxtExists returns whether the platform contains a programmer.txt file.

Diff for: internal/rule/rulefunction/platform.go

+30-50
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func BoardsTxtBoardIDNameMissing() (result ruleresult.Type, output string) {
6464
return ruleresult.Skip, "boards.txt has no boards"
6565
}
6666

67-
nonCompliantBoardIDs := boardIDMissingRequiredProperty("name", compliancelevel.Specification)
67+
nonCompliantBoardIDs := iDMissingRequiredProperty(projectdata.BoardsTxtBoardIds(), "name", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
6868

6969
if len(nonCompliantBoardIDs) > 0 {
7070
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -83,7 +83,7 @@ func BoardsTxtBoardIDNameLTMinLength() (result ruleresult.Type, output string) {
8383
return ruleresult.Skip, "boards.txt has no boards"
8484
}
8585

86-
nonCompliantBoardIDs := boardIDValueLTMinLength("name", compliancelevel.Specification)
86+
nonCompliantBoardIDs := iDValueLTMinLength(projectdata.BoardsTxtBoardIds(), "name", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
8787

8888
if len(nonCompliantBoardIDs) > 0 {
8989
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -102,7 +102,7 @@ func BoardsTxtBoardIDBuildBoardMissing() (result ruleresult.Type, output string)
102102
return ruleresult.Skip, "boards.txt has no boards"
103103
}
104104

105-
nonCompliantBoardIDs := boardIDMissingRequiredProperty("build\\.board", compliancelevel.Strict)
105+
nonCompliantBoardIDs := iDMissingRequiredProperty(projectdata.BoardsTxtBoardIds(), "build\\.board", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Strict])
106106

107107
if len(nonCompliantBoardIDs) > 0 {
108108
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -121,7 +121,7 @@ func BoardsTxtBoardIDBuildBoardLTMinLength() (result ruleresult.Type, output str
121121
return ruleresult.Skip, "boards.txt has no boards"
122122
}
123123

124-
nonCompliantBoardIDs := boardIDValueLTMinLength("build\\.board", compliancelevel.Specification)
124+
nonCompliantBoardIDs := iDValueLTMinLength(projectdata.BoardsTxtBoardIds(), "build\\.board", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
125125

126126
if len(nonCompliantBoardIDs) > 0 {
127127
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -136,11 +136,11 @@ func BoardsTxtBoardIDBuildCoreMissing() (result ruleresult.Type, output string)
136136
return ruleresult.NotRun, "Couldn't load boards.txt"
137137
}
138138

139-
if len(projectdata.BoardsTxtBoardIds()) == 0 {
140-
return ruleresult.Skip, "boards.txt has no boards"
139+
if len(projectdata.BoardsTxtVisibleBoardIds()) == 0 {
140+
return ruleresult.Skip, "boards.txt has no visible boards"
141141
}
142142

143-
nonCompliantBoardIDs := boardIDMissingRequiredProperty("build\\.core", compliancelevel.Specification)
143+
nonCompliantBoardIDs := iDMissingRequiredProperty(projectdata.BoardsTxtVisibleBoardIds(), "build\\.core", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
144144

145145
if len(nonCompliantBoardIDs) > 0 {
146146
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -155,11 +155,11 @@ func BoardsTxtBoardIDBuildCoreLTMinLength() (result ruleresult.Type, output stri
155155
return ruleresult.NotRun, "Couldn't load boards.txt"
156156
}
157157

158-
if len(projectdata.BoardsTxtBoardIds()) == 0 {
159-
return ruleresult.Skip, "boards.txt has no boards"
158+
if len(projectdata.BoardsTxtVisibleBoardIds()) == 0 {
159+
return ruleresult.Skip, "boards.txt has no visible boards"
160160
}
161161

162-
nonCompliantBoardIDs := boardIDValueLTMinLength("build\\.core", compliancelevel.Specification)
162+
nonCompliantBoardIDs := iDValueLTMinLength(projectdata.BoardsTxtVisibleBoardIds(), "build\\.core", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
163163

164164
if len(nonCompliantBoardIDs) > 0 {
165165
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -202,7 +202,7 @@ func BoardsTxtBoardIDHideInvalid() (result ruleresult.Type, output string) {
202202
return ruleresult.Skip, "boards.txt has no boards"
203203
}
204204

205-
nonCompliantBoardIDs := boardIDValueEnumMismatch("hide", compliancelevel.Specification)
205+
nonCompliantBoardIDs := iDValueEnumMismatch(projectdata.BoardsTxtBoardIds(), "hide", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
206206

207207
if len(nonCompliantBoardIDs) > 0 {
208208
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -245,7 +245,7 @@ func BoardsTxtBoardIDMenuMenuIDOptionIDLTMinLength() (result ruleresult.Type, ou
245245
return ruleresult.Skip, "boards.txt has no boards"
246246
}
247247

248-
nonCompliantBoardIDs := boardIDValueLTMinLength("menu\\.[^.]+\\.[^.]+", compliancelevel.Strict)
248+
nonCompliantBoardIDs := iDValueLTMinLength(projectdata.BoardsTxtBoardIds(), "menu\\.[^.]+\\.[^.]+", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Strict])
249249

250250
if len(nonCompliantBoardIDs) > 0 {
251251
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -264,7 +264,7 @@ func BoardsTxtBoardIDSerialDisableDTRInvalid() (result ruleresult.Type, output s
264264
return ruleresult.Skip, "boards.txt has no boards"
265265
}
266266

267-
nonCompliantBoardIDs := boardIDValueEnumMismatch("serial\\.disableDTR", compliancelevel.Specification)
267+
nonCompliantBoardIDs := iDValueEnumMismatch(projectdata.BoardsTxtBoardIds(), "serial\\.disableDTR", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
268268

269269
if len(nonCompliantBoardIDs) > 0 {
270270
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -283,7 +283,7 @@ func BoardsTxtBoardIDSerialDisableRTSInvalid() (result ruleresult.Type, output s
283283
return ruleresult.Skip, "boards.txt has no boards"
284284
}
285285

286-
nonCompliantBoardIDs := boardIDValueEnumMismatch("serial\\.disableRTS", compliancelevel.Specification)
286+
nonCompliantBoardIDs := iDValueEnumMismatch(projectdata.BoardsTxtBoardIds(), "serial\\.disableRTS", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
287287

288288
if len(nonCompliantBoardIDs) > 0 {
289289
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -298,11 +298,11 @@ func BoardsTxtBoardIDUploadToolMissing() (result ruleresult.Type, output string)
298298
return ruleresult.NotRun, "Couldn't load boards.txt"
299299
}
300300

301-
if len(projectdata.BoardsTxtBoardIds()) == 0 {
302-
return ruleresult.Skip, "boards.txt has no boards"
301+
if len(projectdata.BoardsTxtVisibleBoardIds()) == 0 {
302+
return ruleresult.Skip, "boards.txt has no visible boards"
303303
}
304304

305-
nonCompliantBoardIDs := boardIDMissingRequiredProperty("upload\\.tool", compliancelevel.Specification)
305+
nonCompliantBoardIDs := iDMissingRequiredProperty(projectdata.BoardsTxtVisibleBoardIds(), "upload\\.tool", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
306306

307307
if len(nonCompliantBoardIDs) > 0 {
308308
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -321,7 +321,7 @@ func BoardsTxtBoardIDUploadToolLTMinLength() (result ruleresult.Type, output str
321321
return ruleresult.Skip, "boards.txt has no boards"
322322
}
323323

324-
nonCompliantBoardIDs := boardIDValueLTMinLength("upload\\.tool", compliancelevel.Specification)
324+
nonCompliantBoardIDs := iDValueLTMinLength(projectdata.BoardsTxtBoardIds(), "upload\\.tool", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
325325

326326
if len(nonCompliantBoardIDs) > 0 {
327327
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -336,11 +336,11 @@ func BoardsTxtBoardIDUploadMaximumSizeMissing() (result ruleresult.Type, output
336336
return ruleresult.NotRun, "Couldn't load boards.txt"
337337
}
338338

339-
if len(projectdata.BoardsTxtBoardIds()) == 0 {
340-
return ruleresult.Skip, "boards.txt has no boards"
339+
if len(projectdata.BoardsTxtVisibleBoardIds()) == 0 {
340+
return ruleresult.Skip, "boards.txt has no visible boards"
341341
}
342342

343-
nonCompliantBoardIDs := boardIDMissingRequiredProperty("upload\\.maximum_size", compliancelevel.Strict)
343+
nonCompliantBoardIDs := iDMissingRequiredProperty(projectdata.BoardsTxtVisibleBoardIds(), "upload\\.maximum_size", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Strict])
344344

345345
if len(nonCompliantBoardIDs) > 0 {
346346
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -359,7 +359,7 @@ func BoardsTxtBoardIDUploadMaximumSizeInvalid() (result ruleresult.Type, output
359359
return ruleresult.Skip, "boards.txt has no boards"
360360
}
361361

362-
nonCompliantBoardIDs := boardIDValuePatternMismatch("upload\\.maximum_size", compliancelevel.Specification)
362+
nonCompliantBoardIDs := iDValuePatternMismatch(projectdata.BoardsTxtBoardIds(), "upload\\.maximum_size", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
363363

364364
if len(nonCompliantBoardIDs) > 0 {
365365
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -374,11 +374,11 @@ func BoardsTxtBoardIDUploadMaximumDataSizeMissing() (result ruleresult.Type, out
374374
return ruleresult.NotRun, "Couldn't load boards.txt"
375375
}
376376

377-
if len(projectdata.BoardsTxtBoardIds()) == 0 {
378-
return ruleresult.Skip, "boards.txt has no boards"
377+
if len(projectdata.BoardsTxtVisibleBoardIds()) == 0 {
378+
return ruleresult.Skip, "boards.txt has no visible boards"
379379
}
380380

381-
nonCompliantBoardIDs := boardIDMissingRequiredProperty("upload\\.maximum_data_size", compliancelevel.Strict)
381+
nonCompliantBoardIDs := iDMissingRequiredProperty(projectdata.BoardsTxtVisibleBoardIds(), "upload\\.maximum_data_size", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Strict])
382382

383383
if len(nonCompliantBoardIDs) > 0 {
384384
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -397,7 +397,7 @@ func BoardsTxtBoardIDUploadMaximumDataSizeInvalid() (result ruleresult.Type, out
397397
return ruleresult.Skip, "boards.txt has no boards"
398398
}
399399

400-
nonCompliantBoardIDs := boardIDValuePatternMismatch("upload\\.maximum_data_size", compliancelevel.Specification)
400+
nonCompliantBoardIDs := iDValuePatternMismatch(projectdata.BoardsTxtBoardIds(), "upload\\.maximum_data_size", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
401401

402402
if len(nonCompliantBoardIDs) > 0 {
403403
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -416,7 +416,7 @@ func BoardsTxtBoardIDUploadUse1200bpsTouchInvalid() (result ruleresult.Type, out
416416
return ruleresult.Skip, "boards.txt has no boards"
417417
}
418418

419-
nonCompliantBoardIDs := boardIDValueEnumMismatch("upload\\.use_1200bps_touch", compliancelevel.Specification)
419+
nonCompliantBoardIDs := iDValueEnumMismatch(projectdata.BoardsTxtBoardIds(), "upload\\.use_1200bps_touch", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
420420

421421
if len(nonCompliantBoardIDs) > 0 {
422422
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -435,7 +435,7 @@ func BoardsTxtBoardIDUploadWaitForUploadPortInvalid() (result ruleresult.Type, o
435435
return ruleresult.Skip, "boards.txt has no boards"
436436
}
437437

438-
nonCompliantBoardIDs := boardIDValueEnumMismatch("upload\\.wait_for_upload_port", compliancelevel.Specification)
438+
nonCompliantBoardIDs := iDValueEnumMismatch(projectdata.BoardsTxtBoardIds(), "upload\\.wait_for_upload_port", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
439439

440440
if len(nonCompliantBoardIDs) > 0 {
441441
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -454,7 +454,7 @@ func BoardsTxtBoardIDVidNInvalid() (result ruleresult.Type, output string) {
454454
return ruleresult.Skip, "boards.txt has no boards"
455455
}
456456

457-
nonCompliantBoardIDs := boardIDValuePatternMismatch("vid\\.[0-9]+", compliancelevel.Specification)
457+
nonCompliantBoardIDs := iDValuePatternMismatch(projectdata.BoardsTxtBoardIds(), "vid\\.[0-9]+", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
458458

459459
if len(nonCompliantBoardIDs) > 0 {
460460
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -473,7 +473,7 @@ func BoardsTxtBoardIDPidNInvalid() (result ruleresult.Type, output string) {
473473
return ruleresult.Skip, "boards.txt has no boards"
474474
}
475475

476-
nonCompliantBoardIDs := boardIDValuePatternMismatch("pid\\.[0-9]+", compliancelevel.Specification)
476+
nonCompliantBoardIDs := iDValuePatternMismatch(projectdata.BoardsTxtBoardIds(), "pid\\.[0-9]+", projectdata.BoardsTxtSchemaValidationResult()[compliancelevel.Specification])
477477

478478
if len(nonCompliantBoardIDs) > 0 {
479479
return ruleresult.Fail, strings.Join(nonCompliantBoardIDs, ", ")
@@ -1760,26 +1760,6 @@ func PlatformTxtBootloaderPatternMissing() (result ruleresult.Type, output strin
17601760
return ruleresult.Pass, ""
17611761
}
17621762

1763-
// boardIDMissingRequiredProperty returns the list of board IDs missing the given required property.
1764-
func boardIDMissingRequiredProperty(propertyNameQuery string, complianceLevel compliancelevel.Type) []string {
1765-
return iDMissingRequiredProperty(projectdata.BoardsTxtBoardIds(), propertyNameQuery, projectdata.BoardsTxtSchemaValidationResult()[complianceLevel])
1766-
}
1767-
1768-
// boardIDValueLTMinLength returns the list of board IDs with value of the given property less than the minimum length.
1769-
func boardIDValueLTMinLength(propertyNameQuery string, complianceLevel compliancelevel.Type) []string {
1770-
return iDValueLTMinLength(projectdata.BoardsTxtBoardIds(), propertyNameQuery, projectdata.BoardsTxtSchemaValidationResult()[complianceLevel])
1771-
}
1772-
1773-
// boardIDValueEnumMismatch returns the list of board IDs with value of the given property not matching the JSON schema enum.
1774-
func boardIDValueEnumMismatch(propertyNameQuery string, complianceLevel compliancelevel.Type) []string {
1775-
return iDValueEnumMismatch(projectdata.BoardsTxtBoardIds(), propertyNameQuery, projectdata.BoardsTxtSchemaValidationResult()[complianceLevel])
1776-
}
1777-
1778-
// boardIDValueEnumMismatch returns the list of board IDs with value of the given property not matching the JSON schema pattern.
1779-
func boardIDValuePatternMismatch(propertyNameQuery string, complianceLevel compliancelevel.Type) []string {
1780-
return iDValuePatternMismatch(projectdata.BoardsTxtBoardIds(), propertyNameQuery, projectdata.BoardsTxtSchemaValidationResult()[complianceLevel])
1781-
}
1782-
17831763
// programmerIDMissingRequiredProperty returns the list of programmer IDs missing the given required property.
17841764
func programmerIDMissingRequiredProperty(propertyNameQuery string, complianceLevel compliancelevel.Type) []string {
17851765
return iDMissingRequiredProperty(projectdata.ProgrammersTxtProgrammerIds(), propertyNameQuery, projectdata.ProgrammersTxtSchemaValidationResult()[complianceLevel])

0 commit comments

Comments
 (0)