Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e2656e4

Browse files
authored
Merge pull request #55 from arduino/per1234/includes-in-library-check
Add check for includes missing from library
2 parents 34d6956 + a90ff20 commit e2656e4

File tree

7 files changed

+163
-14
lines changed

7 files changed

+163
-14
lines changed

‎check/checkconfigurations/checkconfigurations.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,21 @@ var configurations = []Type{
716716
ErrorModes: []checkmode.Type{checkmode.Default},
717717
CheckFunction: checkfunctions.LibraryPropertiesIncludesFieldLTMinLength,
718718
},
719+
{
720+
ProjectType: projecttype.Library,
721+
Category: "library.properties",
722+
Subcategory: "includes field",
723+
ID: "",
724+
Brief: "includes file not in library",
725+
Description: `People often think this is the way to define their library's dependencies, which breaks the "Sketch > Include Library" feature for that library.`,
726+
MessageTemplate: "library.properties includes field item(s) {{.}} not found in library.",
727+
DisableModes: nil,
728+
EnableModes: []checkmode.Type{checkmode.All},
729+
InfoModes: nil,
730+
WarningModes: []checkmode.Type{checkmode.Permissive},
731+
ErrorModes: []checkmode.Type{checkmode.Default},
732+
CheckFunction: checkfunctions.LibraryPropertiesIncludesFieldItemNotFound,
733+
},
719734
{
720735
ProjectType: projecttype.Library,
721736
Category: "library.properties",

‎check/checkfunctions/library.go‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,47 @@ func LibraryPropertiesIncludesFieldLTMinLength() (result checkresult.Type, outpu
746746
return checkresult.Pass, ""
747747
}
748748

749+
// LibraryPropertiesIncludesFieldItemNotFound checks whether the header files specified in the library.properties `includes` field are in the library.
750+
func LibraryPropertiesIncludesFieldItemNotFound() (result checkresult.Type, output string) {
751+
if checkdata.LibraryPropertiesLoadError() != nil {
752+
return checkresult.NotRun, ""
753+
}
754+
755+
includes, ok := checkdata.LibraryProperties().GetOk("includes")
756+
if !ok {
757+
return checkresult.NotRun, ""
758+
}
759+
760+
includesList, err := properties.SplitQuotedString(includes, "", false)
761+
if err != nil {
762+
panic(err)
763+
}
764+
765+
findInclude := func(include string) bool {
766+
for _, header := range checkdata.SourceHeaders() {
767+
logrus.Tracef("Comparing include %s with header file %s", include, header)
768+
if include == header {
769+
logrus.Tracef("match!")
770+
return true
771+
}
772+
}
773+
return false
774+
}
775+
776+
includesNotInLibrary := []string{}
777+
for _, include := range includesList {
778+
if !findInclude(include) {
779+
includesNotInLibrary = append(includesNotInLibrary, include)
780+
}
781+
}
782+
783+
if len(includesNotInLibrary) > 0 {
784+
return checkresult.Fail, strings.Join(includesNotInLibrary, ", ")
785+
}
786+
787+
return checkresult.Pass, ""
788+
}
789+
749790
// LibraryPropertiesPrecompiledFieldInvalid checks for invalid value in the library.properties "precompiled" field.
750791
func LibraryPropertiesPrecompiledFieldInvalid() (result checkresult.Type, output string) {
751792
if checkdata.LibraryPropertiesLoadError() != nil {

‎check/checkfunctions/library_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,17 @@ func TestLibraryPropertiesDotALinkageFieldTrueWithFlatLayout(t *testing.T) {
168168
checkCheckFunction(LibraryPropertiesDotALinkageFieldTrueWithFlatLayout, testTables, t)
169169
}
170170

171+
func TestLibraryPropertiesIncludesFieldItemNotFound(t *testing.T) {
172+
testTables := []checkFunctionTestTable{
173+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
174+
{"Not defined", "MissingFields", checkresult.NotRun, ""},
175+
{"Missing includes", "MissingIncludes", checkresult.Fail, "^Nonexistent.h$"},
176+
{"Present includes", "Recursive", checkresult.Pass, ""},
177+
}
178+
179+
checkCheckFunction(LibraryPropertiesIncludesFieldItemNotFound, testTables, t)
180+
}
181+
171182
func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {
172183
testTables := []checkFunctionTestTable{
173184
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=MissingIncludes
2+
version=1.0.0
3+
author=Cristian Maglie <c.maglie@example.com>, Pippo Pluto <pippo@example.com>
4+
maintainer=Cristian Maglie <c.maglie@example.com>
5+
sentence=A library that makes coding a web server a breeze.
6+
paragraph=Supports HTTP1.1 and you can do GET and POST.
7+
category=Communication
8+
url=http://example.com/
9+
architectures=avr
10+
includes=Nonexistent.h

‎check/checkfunctions/testdata/libraries/MissingIncludes/src/MissingIncludes.h‎

Whitespace-only changes.

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/arduino/arduino-check
33
go 1.14
44

55
require (
6-
github.com/arduino/arduino-cli v0.0.0-20200922073731-53e3230c4f71
6+
github.com/arduino/arduino-cli v0.0.0-20201124150942-8d026eddbfb4
77
github.com/arduino/go-paths-helper v1.3.2
88
github.com/arduino/go-properties-orderedmap v1.4.0
99
github.com/client9/misspell v0.3.4

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /