Skip to content

Add check for includes missing from library #55

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 2 commits into from
Nov 25, 2020
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
15 changes: 15 additions & 0 deletions check/checkconfigurations/checkconfigurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,21 @@ var configurations = []Type{
ErrorModes: []checkmode.Type{checkmode.Default},
CheckFunction: checkfunctions.LibraryPropertiesIncludesFieldLTMinLength,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Subcategory: "includes field",
ID: "",
Brief: "includes file not in library",
Description: `People often think this is the way to define their library's dependencies, which breaks the "Sketch > Include Library" feature for that library.`,
MessageTemplate: "library.properties includes field item(s) {{.}} not found in library.",
DisableModes: nil,
EnableModes: []checkmode.Type{checkmode.All},
InfoModes: nil,
WarningModes: []checkmode.Type{checkmode.Permissive},
ErrorModes: []checkmode.Type{checkmode.Default},
CheckFunction: checkfunctions.LibraryPropertiesIncludesFieldItemNotFound,
},
{
ProjectType: projecttype.Library,
Category: "library.properties",
Expand Down
41 changes: 41 additions & 0 deletions check/checkfunctions/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,47 @@ func LibraryPropertiesIncludesFieldLTMinLength() (result checkresult.Type, outpu
return checkresult.Pass, ""
}

// LibraryPropertiesIncludesFieldItemNotFound checks whether the header files specified in the library.properties `includes` field are in the library.
func LibraryPropertiesIncludesFieldItemNotFound() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
return checkresult.NotRun, ""
}

includes, ok := checkdata.LibraryProperties().GetOk("includes")
if !ok {
return checkresult.NotRun, ""
}

includesList, err := properties.SplitQuotedString(includes, "", false)
if err != nil {
panic(err)
}

findInclude := func(include string) bool {
for _, header := range checkdata.SourceHeaders() {
logrus.Tracef("Comparing include %s with header file %s", include, header)
if include == header {
logrus.Tracef("match!")
return true
}
}
return false
}

includesNotInLibrary := []string{}
for _, include := range includesList {
if !findInclude(include) {
includesNotInLibrary = append(includesNotInLibrary, include)
}
}

if len(includesNotInLibrary) > 0 {
return checkresult.Fail, strings.Join(includesNotInLibrary, ", ")
}

return checkresult.Pass, ""
}

// LibraryPropertiesPrecompiledFieldInvalid checks for invalid value in the library.properties "precompiled" field.
func LibraryPropertiesPrecompiledFieldInvalid() (result checkresult.Type, output string) {
if checkdata.LibraryPropertiesLoadError() != nil {
Expand Down
11 changes: 11 additions & 0 deletions check/checkfunctions/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ func TestLibraryPropertiesDotALinkageFieldTrueWithFlatLayout(t *testing.T) {
checkCheckFunction(LibraryPropertiesDotALinkageFieldTrueWithFlatLayout, testTables, t)
}

func TestLibraryPropertiesIncludesFieldItemNotFound(t *testing.T) {
testTables := []checkFunctionTestTable{
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
{"Not defined", "MissingFields", checkresult.NotRun, ""},
{"Missing includes", "MissingIncludes", checkresult.Fail, "^Nonexistent.h$"},
{"Present includes", "Recursive", checkresult.Pass, ""},
}

checkCheckFunction(LibraryPropertiesIncludesFieldItemNotFound, testTables, t)
}

func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {
testTables := []checkFunctionTestTable{
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=MissingIncludes
version=1.0.0
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
maintainer=Cristian Maglie <[email protected]>
sentence=A library that makes coding a web server a breeze.
paragraph=Supports HTTP1.1 and you can do GET and POST.
category=Communication
url=http://example.com/
architectures=avr
includes=Nonexistent.h
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/arduino/arduino-check
go 1.14

require (
github.com/arduino/arduino-cli v0.0.0-20200922073731-53e3230c4f71
github.com/arduino/arduino-cli v0.0.0-20201124150942-8d026eddbfb4
github.com/arduino/go-paths-helper v1.3.2
github.com/arduino/go-properties-orderedmap v1.4.0
github.com/client9/misspell v0.3.4
Expand Down
Loading