Skip to content

Commit 67e4638

Browse files
authored
Merge pull request #87 from arduino/per1234/package-index-platform-checks
Add package index and platform checks
2 parents 83b63b7 + ae4be20 commit 67e4638

File tree

36 files changed

+835
-8
lines changed

36 files changed

+835
-8
lines changed

Diff for: .prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66

77
# Test files
88
/check/checkdata/schema/testdata/invalid-schema.json
9+
/check/checkdata/testdata/packageindexes/invalid-JSON/package_foo_index.json
10+
/check/checkfunctions/testdata/packageindexes/invalid-JSON/package_foo_index.json

Diff for: check/checkconfigurations/checkconfigurations.go

+60
Original file line numberDiff line numberDiff line change
@@ -1151,4 +1151,64 @@ var configurations = []Type{
11511151
ErrorModes: []checkmode.Type{checkmode.Strict},
11521152
CheckFunction: checkfunctions.MissingReadme,
11531153
},
1154+
{
1155+
ProjectType: projecttype.Platform,
1156+
Category: "configuration files",
1157+
Subcategory: "boards.txt",
1158+
ID: "",
1159+
Brief: "missing",
1160+
Description: "",
1161+
MessageTemplate: "Required boards.txt is missing. Expected at: {{.}}",
1162+
DisableModes: nil,
1163+
EnableModes: []checkmode.Type{checkmode.Default},
1164+
InfoModes: nil,
1165+
WarningModes: nil,
1166+
ErrorModes: []checkmode.Type{checkmode.Default},
1167+
CheckFunction: checkfunctions.BoardsTxtMissing,
1168+
},
1169+
{
1170+
ProjectType: projecttype.Platform,
1171+
Category: "configuration files",
1172+
Subcategory: "boards.txt",
1173+
ID: "",
1174+
Brief: "Invalid boards.txt",
1175+
Description: "",
1176+
MessageTemplate: "boards.txt has an invalid format: {{.}}",
1177+
DisableModes: nil,
1178+
EnableModes: []checkmode.Type{checkmode.Default},
1179+
InfoModes: nil,
1180+
WarningModes: nil,
1181+
ErrorModes: []checkmode.Type{checkmode.Default},
1182+
CheckFunction: checkfunctions.BoardsTxtFormat,
1183+
},
1184+
{
1185+
ProjectType: projecttype.PackageIndex,
1186+
Category: "data",
1187+
Subcategory: "",
1188+
ID: "",
1189+
Brief: "Invalid JSON format",
1190+
Description: "",
1191+
MessageTemplate: "Invalid JSON format.",
1192+
DisableModes: nil,
1193+
EnableModes: []checkmode.Type{checkmode.Default},
1194+
InfoModes: nil,
1195+
WarningModes: nil,
1196+
ErrorModes: []checkmode.Type{checkmode.Default},
1197+
CheckFunction: checkfunctions.PackageIndexJSONFormat,
1198+
},
1199+
{
1200+
ProjectType: projecttype.PackageIndex,
1201+
Category: "data",
1202+
Subcategory: "",
1203+
ID: "",
1204+
Brief: "Invalid format",
1205+
Description: "",
1206+
MessageTemplate: "Invalid package index format: {{.}}",
1207+
DisableModes: nil,
1208+
EnableModes: []checkmode.Type{checkmode.Default},
1209+
InfoModes: nil,
1210+
WarningModes: nil,
1211+
ErrorModes: []checkmode.Type{checkmode.Default},
1212+
CheckFunction: checkfunctions.PackageIndexFormat,
1213+
},
11541214
}

Diff for: check/checkdata/checkdata.go

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package checkdata
2121

2222
import (
2323
"github.com/arduino/arduino-check/project"
24+
"github.com/arduino/arduino-check/project/packageindex"
2425
"github.com/arduino/arduino-check/project/projecttype"
2526
"github.com/arduino/go-paths-helper"
2627
)
@@ -34,7 +35,16 @@ func Initialize(project project.Type, schemasPath *paths.Path) {
3435
case projecttype.Library:
3536
InitializeForLibrary(project, schemasPath)
3637
case projecttype.Platform:
38+
InitializeForPlatform(project)
3739
case projecttype.PackageIndex:
40+
var err error
41+
// Because a package index project is a file, but project.Path may be a folder, an extra discovery step is needed for this project type.
42+
projectPath, err = packageindex.Find(project.Path)
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
InitializeForPackageIndex()
3848
}
3949
}
4050

Diff for: check/checkdata/packageindex.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This file is part of arduino-check.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-check.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package checkdata
17+
18+
import (
19+
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
20+
)
21+
22+
// InitializeForPackageIndex gathers the package index check data for the specified project.
23+
func InitializeForPackageIndex() {
24+
packageIndex, packageIndexLoadError = packageindex.LoadIndex(ProjectPath())
25+
}
26+
27+
var packageIndex *packageindex.Index
28+
29+
// PackageIndex returns the packageindex.Index object generated by Arduino CLI.
30+
func PackageIndex() *packageindex.Index {
31+
return packageIndex
32+
}
33+
34+
var packageIndexLoadError error
35+
36+
// PackageIndexLoadError returns the error return of packageindex.LoadIndex().
37+
func PackageIndexLoadError() error {
38+
return packageIndexLoadError
39+
}

Diff for: check/checkdata/packageindex_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// This file is part of arduino-check.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-check.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package checkdata
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-check/project"
22+
"github.com/arduino/arduino-check/project/projecttype"
23+
"github.com/arduino/go-paths-helper"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
var packageIndexTestDataPath *paths.Path
28+
29+
func init() {
30+
workingDirectory, err := paths.Getwd()
31+
if err != nil {
32+
panic(err)
33+
}
34+
packageIndexTestDataPath = workingDirectory.Join("testdata", "packageindexes")
35+
}
36+
37+
func TestInitializeForPackageIndex(t *testing.T) {
38+
testTables := []struct {
39+
testName string
40+
path *paths.Path
41+
packageIndexAssertion assert.ValueAssertionFunc
42+
packageIndexLoadErrorAssertion assert.ValueAssertionFunc
43+
}{
44+
{"Valid", packageIndexTestDataPath.Join("valid-package-index", "package_foo_index.json"), assert.NotNil, assert.Nil},
45+
{"Invalid package index", packageIndexTestDataPath.Join("invalid-package-index", "package_foo_index.json"), assert.Nil, assert.NotNil},
46+
{"Invalid JSON", packageIndexTestDataPath.Join("invalid-JSON", "package_foo_index.json"), assert.Nil, assert.NotNil},
47+
}
48+
49+
for _, testTable := range testTables {
50+
51+
testProject := project.Type{
52+
Path: testTable.path,
53+
ProjectType: projecttype.PackageIndex,
54+
SuperprojectType: projecttype.PackageIndex,
55+
}
56+
Initialize(testProject, nil)
57+
58+
testTable.packageIndexLoadErrorAssertion(t, PackageIndexLoadError(), testTable.testName)
59+
if PackageIndexLoadError() == nil {
60+
testTable.packageIndexAssertion(t, PackageIndex(), testTable.testName)
61+
}
62+
}
63+
}

Diff for: check/checkdata/platform.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of arduino-check.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-check.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package checkdata
17+
18+
import (
19+
"github.com/arduino/arduino-check/project"
20+
"github.com/arduino/arduino-check/project/platform/boardstxt"
21+
"github.com/arduino/go-properties-orderedmap"
22+
)
23+
24+
// Initialize gathers the platform check data for the specified project.
25+
func InitializeForPlatform(project project.Type) {
26+
boardsTxt, boardsTxtLoadError = boardstxt.Properties(ProjectPath())
27+
}
28+
29+
var boardsTxt *properties.Map
30+
31+
// BoardsTxt returns the data from the boards.txt configuration file.
32+
func BoardsTxt() *properties.Map {
33+
return boardsTxt
34+
}
35+
36+
var boardsTxtLoadError error
37+
38+
// BoardsTxtLoadError returns the error output from loading the boards.txt configuration file.
39+
func BoardsTxtLoadError() error {
40+
return boardsTxtLoadError
41+
}

Diff for: check/checkdata/platform_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// This file is part of arduino-check.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-check.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package checkdata
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-check/project"
22+
"github.com/arduino/arduino-check/project/projecttype"
23+
"github.com/arduino/go-paths-helper"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
var platformTestDataPath *paths.Path
28+
29+
func init() {
30+
workingDirectory, err := paths.Getwd()
31+
if err != nil {
32+
panic(err)
33+
}
34+
platformTestDataPath = workingDirectory.Join("testdata", "platforms")
35+
}
36+
37+
func TestInitializeForPlatform(t *testing.T) {
38+
testTables := []struct {
39+
testName string
40+
platformFolderName string
41+
boardsTxtAssertion assert.ValueAssertionFunc
42+
boardsTxtLoadErrorAssertion assert.ValueAssertionFunc
43+
}{
44+
{"Valid", "valid-boards.txt", assert.NotNil, assert.Nil},
45+
{"Invalid", "invalid-boards.txt", assert.Nil, assert.NotNil},
46+
{"Missing", "missing-boards.txt", assert.NotNil, assert.Nil},
47+
}
48+
49+
for _, testTable := range testTables {
50+
51+
testProject := project.Type{
52+
Path: platformTestDataPath.Join(testTable.platformFolderName),
53+
ProjectType: projecttype.Platform,
54+
SuperprojectType: projecttype.Platform,
55+
}
56+
Initialize(testProject, nil)
57+
58+
testTable.boardsTxtLoadErrorAssertion(t, BoardsTxtLoadError(), testTable.testName)
59+
if BoardsTxtLoadError() == nil {
60+
testTable.boardsTxtAssertion(t, BoardsTxt(), testTable.testName)
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"foo": "bar"
4+
},
5+
{
6+
"baz": "bat"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"foo": "bar"
4+
},
5+
{
6+
"baz": "bat"
7+
}
8+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "myboard",
5+
"maintainer": "Jane Developer",
6+
"websiteURL": "https://github.com/janedeveloper/myboard",
7+
"email": "[email protected]",
8+
"help": {
9+
"online": "http://example.com/forum/myboard"
10+
},
11+
"platforms": [
12+
{
13+
"name": "My Board",
14+
"architecture": "avr",
15+
"version": "1.0.0",
16+
"category": "Contributed",
17+
"help": {
18+
"online": "http://example.com/forum/myboard"
19+
},
20+
"url": "https://janedeveloper.github.io/myboard/myboard-1.0.0.zip",
21+
"archiveFileName": "myboard-1.0.0.zip",
22+
"checksum": "SHA-256:ec3ff8a1dc96d3ba6f432b9b837a35fd4174a34b3d2927de1d51010e8b94f9f1",
23+
"size": "15005",
24+
"boards": [{ "name": "My Board" }, { "name": "My Board Pro" }],
25+
"toolsDependencies": [
26+
{
27+
"packager": "arduino",
28+
"name": "avr-gcc",
29+
"version": "4.8.1-arduino5"
30+
},
31+
{
32+
"packager": "arduino",
33+
"name": "avrdude",
34+
"version": "6.0.1-arduino5"
35+
}
36+
]
37+
},
38+
{
39+
"name": "My Board",
40+
"architecture": "avr",
41+
"version": "1.0.1",
42+
"category": "Contributed",
43+
"help": {
44+
"online": "http://example.com/forum/myboard"
45+
},
46+
"url": "https://janedeveloper.github.io/myboard/myboard-1.0.1.zip",
47+
"archiveFileName": "myboard-1.0.1.zip",
48+
"checksum": "SHA-256:9c86ee28a7ce9fe33e8b07ec643316131e0031b0d22e63bb398902a5fdadbca9",
49+
"size": "15125",
50+
"boards": [{ "name": "My Board" }, { "name": "My Board Pro" }],
51+
"toolsDependencies": [
52+
{
53+
"packager": "arduino",
54+
"name": "avr-gcc",
55+
"version": "4.8.1-arduino5"
56+
},
57+
{
58+
"packager": "arduino",
59+
"name": "avrdude",
60+
"version": "6.0.1-arduino5"
61+
}
62+
]
63+
}
64+
],
65+
"tools": []
66+
}
67+
]
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This makes the format invalid

Diff for: check/checkdata/testdata/platforms/missing-boards.txt/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)