diff --git a/check/checkfunctions/library.go b/check/checkfunctions/library.go index 82fdc95f5..1b91d315a 100644 --- a/check/checkfunctions/library.go +++ b/check/checkfunctions/library.go @@ -38,14 +38,23 @@ import ( // LibraryPropertiesFormat checks for invalid library.properties format. func LibraryPropertiesFormat() (result checkresult.Type, output string) { + if checkdata.LoadedLibrary() != nil && checkdata.LoadedLibrary().IsLegacy { + return checkresult.NotRun, "" + } + if checkdata.LibraryPropertiesLoadError() != nil { return checkresult.Fail, checkdata.LibraryPropertiesLoadError().Error() } + return checkresult.Pass, "" } // LibraryPropertiesMissing checks for presence of library.properties. func LibraryPropertiesMissing() (result checkresult.Type, output string) { + if checkdata.LoadedLibrary() == nil { + return checkresult.NotRun, "" + } + if checkdata.LoadedLibrary().IsLegacy { return checkresult.Fail, "" } @@ -768,11 +777,7 @@ func LibraryPropertiesDotALinkageFieldInvalid() (result checkresult.Type, output // LibraryPropertiesDotALinkageFieldTrueWithFlatLayout checks whether a library using the "dot_a_linkage" feature has the required recursive layout type. func LibraryPropertiesDotALinkageFieldTrueWithFlatLayout() (result checkresult.Type, output string) { - if checkdata.LoadedLibrary() == nil { - return checkresult.NotRun, "" - } - - if !checkdata.LibraryProperties().ContainsKey("dot_a_linkage") { + if checkdata.LoadedLibrary() == nil || !checkdata.LibraryProperties().ContainsKey("dot_a_linkage") { return checkresult.NotRun, "" } @@ -905,7 +910,7 @@ func LibraryPropertiesMisspelledOptionalField() (result checkresult.Type, output // LibraryInvalid checks whether the provided path is a valid library. func LibraryInvalid() (result checkresult.Type, output string) { - if library.ContainsHeaderFile(checkdata.LoadedLibrary().SourceDir) { + if checkdata.LoadedLibrary() != nil && library.ContainsHeaderFile(checkdata.LoadedLibrary().SourceDir) { return checkresult.Pass, "" } @@ -1120,7 +1125,7 @@ func MisspelledExtrasFolderName() (result checkresult.Type, output string) { // RecursiveLibraryWithUtilityFolder checks for presence of a `utility` subfolder in a recursive layout library. func RecursiveLibraryWithUtilityFolder() (result checkresult.Type, output string) { - if checkdata.LoadedLibrary().Layout == libraries.FlatLayout { + if checkdata.LoadedLibrary() == nil || checkdata.LoadedLibrary().Layout == libraries.FlatLayout { return checkresult.NotRun, "" } diff --git a/check/checkfunctions/library_test.go b/check/checkfunctions/library_test.go index 3d6c0480f..af81e6218 100644 --- a/check/checkfunctions/library_test.go +++ b/check/checkfunctions/library_test.go @@ -84,6 +84,7 @@ func TestIncorrectLibraryPropertiesFileNameCase(t *testing.T) { func TestLibraryPropertiesMissing(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ + {"Invalid non-legacy", "InvalidLibraryProperties", checkresult.NotRun, ""}, {"Legacy", "Legacy", checkresult.Fail, ""}, {"Flat non-legacy", "Flat", checkresult.Pass, ""}, {"Recursive", "Recursive", checkresult.Pass, ""}, @@ -104,6 +105,7 @@ func TestRedundantLibraryProperties(t *testing.T) { func TestLibraryPropertiesFormat(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ {"Invalid", "InvalidLibraryProperties", checkresult.Fail, ""}, + {"Legacy", "Legacy", checkresult.NotRun, ""}, {"Valid", "Recursive", checkresult.Pass, ""}, } @@ -242,6 +244,7 @@ func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) { func TestLibraryInvalid(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ + {"Invalid library.properties", "InvalidLibraryProperties", checkresult.Fail, ""}, {"Invalid flat layout", "FlatWithoutHeader", checkresult.Fail, ""}, {"Invalid recursive layout", "RecursiveWithoutLibraryProperties", checkresult.Fail, ""}, {"Valid library", "Recursive", checkresult.Pass, ""}, @@ -383,6 +386,7 @@ func TestIncorrectExtrasFolderNameCase(t *testing.T) { func TestRecursiveLibraryWithUtilityFolder(t *testing.T) { testTables := []libraryCheckFunctionTestTable{ + {"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""}, {"Flat", "Flat", checkresult.NotRun, ""}, {"Recursive with utility", "RecursiveWithUtilityFolder", checkresult.Fail, ""}, {"Recursive without utility", "Recursive", checkresult.Pass, ""}, diff --git a/project/library/libraryproperties/libraryproperties.go b/project/library/libraryproperties/libraryproperties.go index cf7bb55b7..ba2837c93 100644 --- a/project/library/libraryproperties/libraryproperties.go +++ b/project/library/libraryproperties/libraryproperties.go @@ -26,11 +26,7 @@ import ( // Properties parses the library.properties from the given path and returns the data. func Properties(libraryPath *paths.Path) (*properties.Map, error) { - libraryProperties, err := properties.Load(libraryPath.Join("library.properties").String()) - if err != nil { - return nil, err - } - return libraryProperties, nil + return properties.SafeLoadFromPath(libraryPath.Join("library.properties")) } var schemaObject = make(map[compliancelevel.Type]*jsonschema.Schema)