Skip to content

Commit 6ed8622

Browse files
committed
Add checks for library layout incompatibility with library.properties configuration
Some of the library.properties configurations are only supported for libraries with a "recursive" layout.
1 parent 336fc8f commit 6ed8622

File tree

19 files changed

+184
-0
lines changed

19 files changed

+184
-0
lines changed

check/checkconfigurations/checkconfigurations.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,36 @@ var configurations = []Type{
161161
ErrorModes: nil,
162162
CheckFunction: checkfunctions.LibraryPropertiesDependsFieldNotInIndex,
163163
},
164+
{
165+
ProjectType: projecttype.Library,
166+
Category: "library.properties",
167+
Subcategory: "dot_a_linkage field",
168+
ID: "",
169+
Brief: `"true" with "1.5" library format`,
170+
Description: `dot_a_linkage feature is only supported for the "1.5" or "recursive" library format.`,
171+
MessageTemplate: `library.properties dot_a_linkage field enabled but library is not in "1.5" format. See: https://arduino.github.io/arduino-cli/latest/library-specification/#source-code`,
172+
DisableModes: nil,
173+
EnableModes: []checkmode.Type{checkmode.All},
174+
InfoModes: nil,
175+
WarningModes: []checkmode.Type{checkmode.Permissive},
176+
ErrorModes: []checkmode.Type{checkmode.Default},
177+
CheckFunction: checkfunctions.LibraryPropertiesDotALinkageFieldTrueWithFlatLayout,
178+
},
179+
{
180+
ProjectType: projecttype.Library,
181+
Category: "library.properties",
182+
Subcategory: "precompiled field",
183+
ID: "",
184+
Brief: "precompiled with flat layout",
185+
Description: `precompiled feature is only supported for the "1.5" or "recursive" library format.`,
186+
MessageTemplate: `library.properties precompiled field value {{.}}, is not supported with "1.0" format. See: https://arduino.github.io/arduino-cli/latest/library-specification/#libraryproperties-file-format`,
187+
DisableModes: nil,
188+
EnableModes: []checkmode.Type{checkmode.All},
189+
InfoModes: nil,
190+
WarningModes: []checkmode.Type{checkmode.Permissive},
191+
ErrorModes: []checkmode.Type{checkmode.Default},
192+
CheckFunction: checkfunctions.LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout,
193+
},
164194
{
165195
ProjectType: projecttype.Sketch,
166196
Category: "structure",

check/checkdata/library.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/arduino/arduino-check/project"
2626
"github.com/arduino/arduino-check/project/library/libraryproperties"
2727
"github.com/arduino/arduino-check/result/feedback"
28+
"github.com/arduino/arduino-cli/arduino/libraries"
2829
"github.com/arduino/go-paths-helper"
2930
"github.com/arduino/go-properties-orderedmap"
3031
"github.com/ory/jsonschema/v3"
@@ -33,6 +34,8 @@ import (
3334

3435
// Initialize gathers the library check data for the specified project.
3536
func InitializeForLibrary(project project.Type, schemasPath *paths.Path) {
37+
var err error
38+
3639
libraryProperties, libraryPropertiesLoadError = libraryproperties.Properties(project.Path)
3740
if libraryPropertiesLoadError != nil {
3841
logrus.Errorf("Error loading library.properties from %s: %s", project.Path, libraryPropertiesLoadError)
@@ -42,6 +45,12 @@ func InitializeForLibrary(project project.Type, schemasPath *paths.Path) {
4245
libraryPropertiesSchemaValidationResult = libraryproperties.Validate(libraryProperties, schemasPath)
4346
}
4447

48+
loadedLibrary, err = libraries.Load(project.Path, libraries.User)
49+
if err != nil {
50+
logrus.Errorf("Error loading library from %s: %s", project.Path, err)
51+
loadedLibrary = nil
52+
}
53+
4554
if libraryManagerIndex == nil { // Only download the Library Manager index once
4655
url := "http://downloads.arduino.cc/libraries/library_index.json"
4756
httpResponse, err := http.Get(url)
@@ -84,6 +93,13 @@ func LibraryPropertiesSchemaValidationResult() map[compliancelevel.Type]*jsonsch
8493
return libraryPropertiesSchemaValidationResult
8594
}
8695

96+
var loadedLibrary *libraries.Library
97+
98+
// LoadedLibrary returns the library object generated by Arduino CLI.
99+
func LoadedLibrary() *libraries.Library {
100+
return loadedLibrary
101+
}
102+
87103
var libraryManagerIndex map[string]interface{}
88104

89105
// LibraryManagerIndex returns the Library Manager index data.

check/checkfunctions/library.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/arduino/arduino-check/check/checkdata/schema/compliancelevel"
2626
"github.com/arduino/arduino-check/check/checkresult"
2727
"github.com/arduino/arduino-check/configuration"
28+
"github.com/arduino/arduino-cli/arduino/libraries"
2829
"github.com/arduino/go-properties-orderedmap"
2930
"github.com/sirupsen/logrus"
3031
)
@@ -140,6 +141,41 @@ func LibraryPropertiesDependsFieldNotInIndex() (result checkresult.Type, output
140141
return checkresult.Pass, ""
141142
}
142143

144+
// LibraryPropertiesDotALinkageFieldTrueWithFlatLayout checks whether a library using the "dot_a_linkage" feature has the required recursive layout type.
145+
func LibraryPropertiesDotALinkageFieldTrueWithFlatLayout() (result checkresult.Type, output string) {
146+
if checkdata.LoadedLibrary() == nil {
147+
return checkresult.NotRun, ""
148+
}
149+
150+
if !checkdata.LibraryProperties().ContainsKey("dot_a_linkage") {
151+
return checkresult.NotRun, ""
152+
}
153+
154+
if checkdata.LoadedLibrary().DotALinkage && checkdata.LoadedLibrary().Layout == libraries.FlatLayout {
155+
return checkresult.Fail, ""
156+
}
157+
158+
return checkresult.Pass, ""
159+
}
160+
161+
// LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout checks whether a precompiled library has the required recursive layout type.
162+
func LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout() (result checkresult.Type, output string) {
163+
if checkdata.LoadedLibrary() == nil || checkdata.LibraryPropertiesLoadError() != nil {
164+
return checkresult.NotRun, ""
165+
}
166+
167+
precompiled, ok := checkdata.LibraryProperties().GetOk("precompiled")
168+
if !ok {
169+
return checkresult.NotRun, ""
170+
}
171+
172+
if checkdata.LoadedLibrary().Precompiled && checkdata.LoadedLibrary().Layout == libraries.FlatLayout {
173+
return checkresult.Fail, precompiled
174+
}
175+
176+
return checkresult.Pass, ""
177+
}
178+
143179
// nameInLibraryManagerIndex returns whether there is a library in Library Manager index using the given name.
144180
func nameInLibraryManagerIndex(name string) bool {
145181
libraries := checkdata.LibraryManagerIndex()["libraries"].([]interface{})

check/checkfunctions/library_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,27 @@ func TestLibraryPropertiesDependsFieldNotInIndex(t *testing.T) {
9292

9393
checkCheckFunction(LibraryPropertiesDependsFieldNotInIndex, testTables, t)
9494
}
95+
96+
func TestLibraryPropertiesDotALinkageFieldTrueWithFlatLayout(t *testing.T) {
97+
testTables := []checkFunctionTestTable{
98+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
99+
{"Not defined", "MissingFields", checkresult.NotRun, ""},
100+
{"Flat layout", "DotALinkageFlat", checkresult.Fail, ""},
101+
{"Recursive layout", "DotALinkage", checkresult.Pass, ""},
102+
}
103+
104+
checkCheckFunction(LibraryPropertiesDotALinkageFieldTrueWithFlatLayout, testTables, t)
105+
}
106+
107+
func TestLibraryPropertiesPrecompiledFieldEnabledWithFlatLayout(t *testing.T) {
108+
testTables := []checkFunctionTestTable{
109+
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
110+
{"Not defined", "MissingFields", checkresult.NotRun, ""},
111+
{"Flat layout", "PrecompiledFlat", checkresult.Fail, "^true$"},
112+
{"Recursive layout", "Precompiled", checkresult.Pass, ""},
113+
{"Recursive, not precompiled", "NotPrecompiled", checkresult.NotRun, ""},
114+
{"Flat, not precompiled", "NotPrecompiledFlat", checkresult.NotRun, ""},
115+
}
116+
117+
checkCheckFunction(LibraryPropertiesPrecompiledFieldEnabledWithFlatLayout, testTables, t)
118+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=DotALinkage
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+
dot_a_linkage=true

check/checkfunctions/testdata/libraries/DotALinkage/src/DotALinkage.h

Whitespace-only changes.

check/checkfunctions/testdata/libraries/DotALinkageFlat/DotALinkageFlat.h

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=DotALinkageFlat
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+
dot_a_linkage=true

check/checkfunctions/testdata/libraries/MissingFields/library.properties

Whitespace-only changes.

check/checkfunctions/testdata/libraries/MissingFields/src/MissingFields.h

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=NotPrecompiled
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=Recursive.h

check/checkfunctions/testdata/libraries/NotPrecompiled/src/NotPrecompiled.h

Whitespace-only changes.

check/checkfunctions/testdata/libraries/NotPrecompiledFlat/NotPrecompiledFlat.h

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=NotPrecompiledFlat
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
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name=Precompiled
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=Recursive.h
11+
precompiled=true

check/checkfunctions/testdata/libraries/Precompiled/src/Precompiled.h

Whitespace-only changes.

check/checkfunctions/testdata/libraries/PrecompiledFlat/PrecompiledFlat.h

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=PrecompiledFlat
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+
precompiled=true

0 commit comments

Comments
 (0)