@@ -846,6 +846,57 @@ func LibraryPropertiesArchitecturesFieldLTMinLength() (result checkresult.Type,
846
846
return checkresult .Pass , ""
847
847
}
848
848
849
+ // LibraryPropertiesArchitecturesFieldAlias checks whether an alias architecture name is present, but not its true Arduino architecture name.
850
+ func LibraryPropertiesArchitecturesFieldSoloAlias () (result checkresult.Type , output string ) {
851
+ if checkdata .LibraryPropertiesLoadError () != nil {
852
+ return checkresult .NotRun , "Couldn't load library.properties"
853
+ }
854
+
855
+ architectures , ok := checkdata .LibraryProperties ().GetOk ("architectures" )
856
+ if ! ok {
857
+ return checkresult .Skip , "Field not present"
858
+ }
859
+
860
+ architecturesList := commaSeparatedToList (strings .ToLower (architectures ))
861
+
862
+ // Must be all lowercase (there is a separate check for incorrect architecture case).
863
+ var aliases = map [string ][]string {
864
+ "atmelavr" : {"avr" },
865
+ "atmelmegaavr" : {"megaavr" },
866
+ "atmelsam" : {"sam" , "samd" },
867
+ "espressif32" : {"esp32" },
868
+ "espressif8266" : {"esp8266" },
869
+ "intel_arc32" : {"arc32" },
870
+ "nordicnrf52" : {"nRF5" , "nrf52" , "mbed" },
871
+ }
872
+
873
+ trueArchitecturePresent := func (trueArchitecturesQuery []string ) bool {
874
+ for _ , trueArchitectureQuery := range trueArchitecturesQuery {
875
+ for _ , architecture := range architecturesList {
876
+ if architecture == trueArchitectureQuery {
877
+ return true
878
+ }
879
+ }
880
+ }
881
+
882
+ return false
883
+ }
884
+
885
+ soloAliases := []string {}
886
+ for _ , architecture := range architecturesList {
887
+ trueEquivalents , isAlias := aliases [architecture ]
888
+ if isAlias && ! trueArchitecturePresent (trueEquivalents ) {
889
+ soloAliases = append (soloAliases , architecture )
890
+ }
891
+ }
892
+
893
+ if len (soloAliases ) > 0 {
894
+ return checkresult .Fail , strings .Join (soloAliases , ", " )
895
+ }
896
+
897
+ return checkresult .Pass , ""
898
+ }
899
+
849
900
// LibraryPropertiesDependsFieldDisallowedCharacters checks for disallowed characters in the library.properties "depends" field.
850
901
func LibraryPropertiesDependsFieldDisallowedCharacters () (result checkresult.Type , output string ) {
851
902
if checkdata .LibraryPropertiesLoadError () != nil {
@@ -875,11 +926,10 @@ func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output
875
926
return checkresult .Skip , "Field not present"
876
927
}
877
928
878
- dependencies := strings . Split (depends , "," )
929
+ dependencies := commaSeparatedToList (depends )
879
930
880
931
dependenciesNotInIndex := []string {}
881
932
for _ , dependency := range dependencies {
882
- dependency = strings .TrimSpace (dependency )
883
933
if dependency == "" {
884
934
continue
885
935
}
@@ -959,10 +1009,9 @@ func LibraryPropertiesIncludesFieldItemNotFound() (result checkresult.Type, outp
959
1009
return checkresult .Skip , "Field not present"
960
1010
}
961
1011
962
- includesList := strings . Split (includes , "," )
1012
+ includesList := commaSeparatedToList (includes )
963
1013
964
1014
findInclude := func (include string ) bool {
965
- include = strings .TrimSpace (include )
966
1015
if include == "" {
967
1016
return true
968
1017
}
@@ -1357,3 +1406,13 @@ func nameInLibraryManagerIndex(name string) bool {
1357
1406
1358
1407
return false
1359
1408
}
1409
+
1410
+ // commaSeparatedToList returns the list equivalent of a comma-separated string.
1411
+ func commaSeparatedToList (commaSeparated string ) []string {
1412
+ list := []string {}
1413
+ for _ , item := range strings .Split (commaSeparated , "," ) {
1414
+ list = append (list , strings .TrimSpace (item ))
1415
+ }
1416
+
1417
+ return list
1418
+ }
0 commit comments