Skip to content

Commit 55f9652

Browse files
umbynosper1234
andauthored
add check on arduino-cli version used (#18)
* add check on arduino-cli version used * Update cmd/compile.go Co-authored-by: per1234 <[email protected]> * use `Parse()` instead of `ParseRelaxed()`, skip the check on the version if the cli build is not a stable one * put the logic in a separate function for readability Co-authored-by: per1234 <[email protected]>
1 parent 15ceb91 commit 55f9652

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

cmd/compile.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/arduino/go-paths-helper"
1616
"github.com/sirupsen/logrus"
1717
"github.com/spf13/cobra"
18+
semver "go.bug.st/relaxed-semver"
1819
)
1920

2021
var fqbn string
@@ -90,7 +91,8 @@ func compileSketch(cmd *cobra.Command, args []string) {
9091
}
9192
var unmarshalledOutput map[string]interface{}
9293
json.Unmarshal(cmdOutput, &unmarshalledOutput)
93-
logrus.Infof("arduino-cli version: %s", unmarshalledOutput["VersionString"])
94+
currentCliVersion := fmt.Sprint(unmarshalledOutput["VersionString"])
95+
checkCliVersion(currentCliVersion)
9496

9597
// let's check if gcc-ar version
9698
cmdOutput, err = exec.Command("gcc-ar", "--version").CombinedOutput()
@@ -144,6 +146,24 @@ func compileSketch(cmd *cobra.Command, args []string) {
144146
createLib(sketchName, buildMcu, fqbn, returnJson, objFilePaths)
145147
}
146148

149+
// checkCliVersion will check if the version of the arduino-cli used is the correct one.
150+
// It will skip the check if the version comes from a non stable release
151+
// The version must be > 0.20.2
152+
func checkCliVersion(currentCliVersion string) {
153+
logrus.Infof("arduino-cli version: %s", currentCliVersion)
154+
version, err := semver.Parse(currentCliVersion)
155+
if err == nil {
156+
// do the check
157+
incompatibleVersion, _ := semver.Parse("0.20.2")
158+
if version.LessThanOrEqual(incompatibleVersion) {
159+
logrus.Fatalf("please use a version > %s of the arduino-cli, installed version: %s", incompatibleVersion, version)
160+
}
161+
} // we continue the execution, it means that the version could be one of:
162+
// - git-snapshot - local build using task build
163+
// - nightly-<date> - nightly build
164+
// - test-<hash>-git-snapshot - tester builds generated by the CI system
165+
}
166+
147167
// parseCliCompileOutput function takes cmdOutToParse as argument,
148168
// cmdOutToParse is the json output captured from the command run
149169
// the function extracts and returns the paths of the .o files

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99

1010
require (
1111
github.com/pkg/errors v0.9.1 // indirect
12+
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18 // indirect
1213
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
1314
)
1415

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
332332
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
333333
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
334334
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
335+
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18 h1:F1qxtaFuewctYc/SsHRn+Q7Dtwi+yJGPgVq8YLtQz98=
336+
go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE=
335337
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
336338
go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
337339
go.etcd.io/etcd/client/v2 v2.305.1/go.mod h1:pMEacxZW7o8pg4CrFE7pquyCJJzZvkvdD2RibOCCCGs=

0 commit comments

Comments
 (0)