Skip to content

Commit 5e3bbff

Browse files
authored
Merge pull request #46 from arduino/per1234/architectures-schema-checks
Add schema provided checks for library.properties architectures field
2 parents 52e129d + ffbf3cc commit 5e3bbff

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,36 @@ var configurations = []Type{
596596
ErrorModes: nil,
597597
CheckFunction: checkfunctions.LibraryPropertiesUrlFieldDeadLink,
598598
},
599+
{
600+
ProjectType: projecttype.Library,
601+
Category: "library.properties",
602+
Subcategory: "architectures field",
603+
ID: "",
604+
Brief: "missing architectures field",
605+
Description: "Defaults to *, but it's better to explicitly define architectures.",
606+
MessageTemplate: "missing architectures field in library.properties. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
607+
DisableModes: nil,
608+
EnableModes: []checkmode.Type{checkmode.All},
609+
InfoModes: nil,
610+
WarningModes: []checkmode.Type{checkmode.All},
611+
ErrorModes: nil,
612+
CheckFunction: checkfunctions.LibraryPropertiesArchitecturesFieldMissing,
613+
},
614+
{
615+
ProjectType: projecttype.Library,
616+
Category: "library.properties",
617+
Subcategory: "architectures field",
618+
ID: "",
619+
Brief: "architectures blank",
620+
Description: "Causes library to be considered incompatible with all architectures.",
621+
MessageTemplate: "Empty library.properties architectures field. Please define specific architectures or set to * if compatible with all. See https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format",
622+
DisableModes: nil,
623+
EnableModes: []checkmode.Type{checkmode.All},
624+
InfoModes: nil,
625+
WarningModes: []checkmode.Type{checkmode.Permissive},
626+
ErrorModes: []checkmode.Type{checkmode.Default},
627+
CheckFunction: checkfunctions.LibraryPropertiesArchitecturesFieldLTMinLength,
628+
},
599629
{
600630
ProjectType: projecttype.Library,
601631
Category: "library.properties",

check/checkfunctions/library.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,35 @@ func LibraryPropertiesUrlFieldDeadLink() (result checkresult.Type, output string
593593
return checkresult.Fail, httpResponse.Status
594594
}
595595

596+
// LibraryPropertiesArchitecturesFieldMissing checks for missing library.properties "architectures" field.
597+
func LibraryPropertiesArchitecturesFieldMissing() (result checkresult.Type, output string) {
598+
if checkdata.LibraryPropertiesLoadError() != nil {
599+
return checkresult.NotRun, ""
600+
}
601+
602+
if schema.RequiredPropertyMissing("architectures", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
603+
return checkresult.Fail, ""
604+
}
605+
return checkresult.Pass, ""
606+
}
607+
608+
// LibraryPropertiesNameFieldLTMinLength checks if the library.properties "architectures" value is less than the minimum length.
609+
func LibraryPropertiesArchitecturesFieldLTMinLength() (result checkresult.Type, output string) {
610+
if checkdata.LibraryPropertiesLoadError() != nil {
611+
return checkresult.NotRun, ""
612+
}
613+
614+
if !checkdata.LibraryProperties().ContainsKey("architectures") {
615+
return checkresult.NotRun, ""
616+
}
617+
618+
if schema.PropertyLessThanMinLength("architectures", checkdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Specification], configuration.SchemasPath()) {
619+
return checkresult.Fail, ""
620+
}
621+
622+
return checkresult.Pass, ""
623+
}
624+
596625
// LibraryPropertiesDependsFieldNotInIndex checks whether the libraries listed in the library.properties `depends` field are in the Library Manager index.
597626
func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output string) {
598627
if checkdata.LibraryPropertiesLoadError() != nil {

0 commit comments

Comments
 (0)