Skip to content

Adjust platform.txt required properties according to core reference #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions internal/rule/rulefunction/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,14 @@ func PlatformTxtCompilerWarningFlagsNoneMissing() (result ruleresult.Type, outpu
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.warning_flags\\.none", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand All @@ -708,6 +716,14 @@ func PlatformTxtCompilerWarningFlagsDefaultMissing() (result ruleresult.Type, ou
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.warning_flags\\.default", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand All @@ -725,6 +741,14 @@ func PlatformTxtCompilerWarningFlagsMoreMissing() (result ruleresult.Type, outpu
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.warning_flags\\.more", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand All @@ -742,6 +766,14 @@ func PlatformTxtCompilerWarningFlagsAllMissing() (result ruleresult.Type, output
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.warning_flags\\.all", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand All @@ -759,6 +791,14 @@ func PlatformTxtCompilerOptimizationFlagsDebugMissing() (result ruleresult.Type,
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if !projectdata.PlatformTxt().ContainsKey("compiler.optimization_flags.release") {
return ruleresult.Skip, "Dependent property not present"
}
Expand All @@ -780,6 +820,14 @@ func PlatformTxtCompilerOptimizationFlagsReleaseMissing() (result ruleresult.Typ
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if !projectdata.PlatformTxt().ContainsKey("compiler.optimization_flags.debug") {
return ruleresult.Skip, "Dependent property not present"
}
Expand All @@ -801,6 +849,14 @@ func PlatformTxtCompilerCExtraFlagsMissing() (result ruleresult.Type, output str
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.c\\.extra_flags", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Strict]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -839,6 +895,14 @@ func PlatformTxtCompilerCppExtraFlagsMissing() (result ruleresult.Type, output s
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.cpp\\.extra_flags", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Strict]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -877,6 +941,14 @@ func PlatformTxtCompilerSExtraFlagsMissing() (result ruleresult.Type, output str
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.S\\.extra_flags", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Strict]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -915,6 +987,14 @@ func PlatformTxtCompilerArExtraFlagsMissing() (result ruleresult.Type, output st
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.ar\\.extra_flags", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Strict]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -953,6 +1033,14 @@ func PlatformTxtCompilerCElfExtraFlagsMissing() (result ruleresult.Type, output
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("compiler\\.c\\.elf\\.extra_flags", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Strict]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1033,6 +1121,14 @@ func PlatformTxtRecipeCOPatternMissing() (result ruleresult.Type, output string)
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.c\\.o\\.pattern", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1092,6 +1188,14 @@ func PlatformTxtRecipeCppOPatternMissing() (result ruleresult.Type, output strin
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.cpp\\.o\\.pattern", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1151,6 +1255,14 @@ func PlatformTxtRecipeSOPatternMissing() (result ruleresult.Type, output string)
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.S\\.o\\.pattern", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1210,6 +1322,14 @@ func PlatformTxtRecipeArPatternMissing() (result ruleresult.Type, output string)
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.ar\\.pattern", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1269,6 +1389,14 @@ func PlatformTxtRecipeCCombinePatternMissing() (result ruleresult.Type, output s
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.c\\.combine\\.pattern", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1328,6 +1456,14 @@ func PlatformTxtRecipeOutputTmpFileMissing() (result ruleresult.Type, output str
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.output\\.tmp_file", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1366,6 +1502,14 @@ func PlatformTxtRecipeOutputSaveFileMissing() (result ruleresult.Type, output st
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.output\\.save_file", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Specification]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1404,6 +1548,14 @@ func PlatformTxtRecipeSizePatternMissing() (result ruleresult.Type, output strin
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.size\\.pattern", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Strict]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1442,6 +1594,14 @@ func PlatformTxtRecipeSizeRegexMissing() (result ruleresult.Type, output string)
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.size\\.regex", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Strict]) {
return ruleresult.Fail, ""
}
Expand All @@ -1459,6 +1619,14 @@ func PlatformTxtRecipeSizeRegexDataMissing() (result ruleresult.Type, output str
return ruleresult.NotRun, "Couldn't load platform.txt"
}

if projectdata.BoardsTxtLoadError() != nil {
return ruleresult.NotRun, "Couldn't load boards.txt"
}

if platformReferencesCore() {
return ruleresult.Skip, "Core reference used"
}

if schema.RequiredPropertyMissing("recipe\\.size\\.regex\\.data", projectdata.PlatformTxtSchemaValidationResult()[compliancelevel.Strict]) {
return ruleresult.Fail, ""
}
Expand Down Expand Up @@ -1892,3 +2060,26 @@ func iDValuePatternMismatch(iDs []string, propertyNameQuery string, validationRe

return nonCompliantIDs
}

// platformReferencesCore checks whether all boards of the platform use core references.
// See: https://arduino.github.io/arduino-cli/dev/platform-specification/#core-reference
func platformReferencesCore() bool {
referencesCore := false // Default return value.
for _, boardID := range projectdata.BoardsTxt().FirstLevelKeys() {
if boardID != "menu" {
// It is a board ID.
boardProperties := projectdata.BoardsTxt().SubTree(boardID)
for _, key := range boardProperties.Keys() {
if key == "build.core" || strings.HasSuffix(key, ".build.core") {
if !strings.Contains(boardProperties.ExpandPropsInString(boardProperties.Get(key)), ":") {
// This board does not use a core reference.
return false
}
referencesCore = true
}
}
}
}

return referencesCore
}
Loading