Skip to content

Commit f27a8cc

Browse files
committed
Provide check data for platforms
1 parent 7f71b8b commit f27a8cc

File tree

7 files changed

+144
-0
lines changed

7 files changed

+144
-0
lines changed

Diff for: check/checkdata/checkdata.go

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func Initialize(project project.Type, schemasPath *paths.Path) {
3535
case projecttype.Library:
3636
InitializeForLibrary(project, schemasPath)
3737
case projecttype.Platform:
38+
InitializeForPlatform(project)
3839
case projecttype.PackageIndex:
3940
var err error
4041
// 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.

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 @@
1+
This makes the format invalid

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

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
uno.name=Arduino Uno
2+
3+
uno.build.core=arduino
4+
uno.build.variant=standard
5+
6+
uno.upload.tool=avrdude
7+
uno.upload.maximum_size=32256
8+
uno.upload.maximum_data_size=2048

Diff for: project/platform/boardstxt/boardstxt.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
/*
17+
Package boardstxt provides functions specific to checking the boards.txt configuration files of Arduino boards platforms.
18+
See: https://arduino.github.io/arduino-cli/latest/platform-specification/#boardstxt
19+
*/
20+
package boardstxt
21+
22+
import (
23+
"github.com/arduino/go-paths-helper"
24+
"github.com/arduino/go-properties-orderedmap"
25+
)
26+
27+
// Properties parses the library.properties from the given path and returns the data.
28+
func Properties(platformPath *paths.Path) (*properties.Map, error) {
29+
return properties.SafeLoadFromPath(platformPath.Join("boards.txt"))
30+
}

0 commit comments

Comments
 (0)