From 8e6d45218d77bdc155ad63635abe845950ec9ed5 Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 1 Feb 2022 13:21:30 +0100 Subject: [PATCH 1/4] add check on arduino-cli version used --- cmd/compile.go | 11 ++++++++++- go.mod | 1 + go.sum | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/compile.go b/cmd/compile.go index b7f50d2..3e02bb5 100644 --- a/cmd/compile.go +++ b/cmd/compile.go @@ -15,6 +15,7 @@ import ( "github.com/arduino/go-paths-helper" "github.com/sirupsen/logrus" "github.com/spf13/cobra" + semver "go.bug.st/relaxed-semver" ) var fqbn string @@ -90,7 +91,15 @@ func compileSketch(cmd *cobra.Command, args []string) { } var unmarshalledOutput map[string]interface{} json.Unmarshal(cmdOutput, &unmarshalledOutput) - logrus.Infof("arduino-cli version: %s", unmarshalledOutput["VersionString"]) + currentCliVersion := fmt.Sprint(unmarshalledOutput["VersionString"]) + logrus.Infof("arduino-cli version: %s", currentCliVersion) + if strings.Compare(currentCliVersion, "git-snapshot") != 0 { + version := semver.ParseRelaxed(currentCliVersion) + minimumVersion := semver.ParseRelaxed("0.20.2") + if version.LessThanOrEqual(minimumVersion) { + logrus.Fatalf("please use a version > %s of the arduino-cli, installed version: %s", minimumVersion, version) + } + } // let's check if gcc-ar version cmdOutput, err = exec.Command("gcc-ar", "--version").CombinedOutput() diff --git a/go.mod b/go.mod index 1d8192e..8afdb0d 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( require ( github.com/pkg/errors v0.9.1 // indirect + go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18 // indirect golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect ) diff --git a/go.sum b/go.sum index f454faf..4c6f7ef 100644 --- a/go.sum +++ b/go.sum @@ -332,6 +332,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18 h1:F1qxtaFuewctYc/SsHRn+Q7Dtwi+yJGPgVq8YLtQz98= +go.bug.st/relaxed-semver v0.0.0-20190922224835-391e10178d18/go.mod h1:Cx1VqMtEhE9pIkEyUj3LVVVPkv89dgW8aCKrRPDR/uE= go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.1/go.mod h1:pMEacxZW7o8pg4CrFE7pquyCJJzZvkvdD2RibOCCCGs= From 7e283448aae218dac2d493e612c85bba2ff5327f Mon Sep 17 00:00:00 2001 From: Umberto Baldi <34278123+umbynos@users.noreply.github.com> Date: Tue, 1 Feb 2022 15:33:33 +0100 Subject: [PATCH 2/4] Update cmd/compile.go Co-authored-by: per1234 --- cmd/compile.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/compile.go b/cmd/compile.go index 3e02bb5..0f12aee 100644 --- a/cmd/compile.go +++ b/cmd/compile.go @@ -95,9 +95,9 @@ func compileSketch(cmd *cobra.Command, args []string) { logrus.Infof("arduino-cli version: %s", currentCliVersion) if strings.Compare(currentCliVersion, "git-snapshot") != 0 { version := semver.ParseRelaxed(currentCliVersion) - minimumVersion := semver.ParseRelaxed("0.20.2") - if version.LessThanOrEqual(minimumVersion) { - logrus.Fatalf("please use a version > %s of the arduino-cli, installed version: %s", minimumVersion, version) + incompatibleVersion := semver.ParseRelaxed("0.20.2") + if version.LessThanOrEqual(incompatibleVersion) { + logrus.Fatalf("please use a version > %s of the arduino-cli, installed version: %s", incompatibleVersion, version) } } From 69dcc8d828ededc29d13229125abbd0bbc86ebab Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 1 Feb 2022 18:37:23 +0100 Subject: [PATCH 3/4] use `Parse()` instead of `ParseRelaxed()`, skip the check on the version if the cli build is not a stable one --- cmd/compile.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/compile.go b/cmd/compile.go index 0f12aee..3b4cbdf 100644 --- a/cmd/compile.go +++ b/cmd/compile.go @@ -93,13 +93,17 @@ func compileSketch(cmd *cobra.Command, args []string) { json.Unmarshal(cmdOutput, &unmarshalledOutput) currentCliVersion := fmt.Sprint(unmarshalledOutput["VersionString"]) logrus.Infof("arduino-cli version: %s", currentCliVersion) - if strings.Compare(currentCliVersion, "git-snapshot") != 0 { - version := semver.ParseRelaxed(currentCliVersion) - incompatibleVersion := semver.ParseRelaxed("0.20.2") + version, err := semver.Parse(currentCliVersion) + if err == nil { + // do the check + incompatibleVersion, _ := semver.Parse("0.20.2") if version.LessThanOrEqual(incompatibleVersion) { logrus.Fatalf("please use a version > %s of the arduino-cli, installed version: %s", incompatibleVersion, version) } - } + } // we continue the execution, it means that the version could be one of: + // - git-snapshot - local build using task build + // - nightly- - nightly build + // - test--git-snapshot - tester builds generated by the CI system // let's check if gcc-ar version cmdOutput, err = exec.Command("gcc-ar", "--version").CombinedOutput() From 090a2a62f7838423fc77ef8b82828faef82cdd76 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Wed, 2 Feb 2022 11:04:28 +0100 Subject: [PATCH 4/4] put the logic in a separate function for readability --- cmd/compile.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/cmd/compile.go b/cmd/compile.go index 3b4cbdf..fc5275e 100644 --- a/cmd/compile.go +++ b/cmd/compile.go @@ -92,18 +92,7 @@ func compileSketch(cmd *cobra.Command, args []string) { var unmarshalledOutput map[string]interface{} json.Unmarshal(cmdOutput, &unmarshalledOutput) currentCliVersion := fmt.Sprint(unmarshalledOutput["VersionString"]) - logrus.Infof("arduino-cli version: %s", currentCliVersion) - version, err := semver.Parse(currentCliVersion) - if err == nil { - // do the check - incompatibleVersion, _ := semver.Parse("0.20.2") - if version.LessThanOrEqual(incompatibleVersion) { - logrus.Fatalf("please use a version > %s of the arduino-cli, installed version: %s", incompatibleVersion, version) - } - } // we continue the execution, it means that the version could be one of: - // - git-snapshot - local build using task build - // - nightly- - nightly build - // - test--git-snapshot - tester builds generated by the CI system + checkCliVersion(currentCliVersion) // let's check if gcc-ar version cmdOutput, err = exec.Command("gcc-ar", "--version").CombinedOutput() @@ -157,6 +146,24 @@ func compileSketch(cmd *cobra.Command, args []string) { createLib(sketchName, buildMcu, fqbn, returnJson, objFilePaths) } +// checkCliVersion will check if the version of the arduino-cli used is the correct one. +// It will skip the check if the version comes from a non stable release +// The version must be > 0.20.2 +func checkCliVersion(currentCliVersion string) { + logrus.Infof("arduino-cli version: %s", currentCliVersion) + version, err := semver.Parse(currentCliVersion) + if err == nil { + // do the check + incompatibleVersion, _ := semver.Parse("0.20.2") + if version.LessThanOrEqual(incompatibleVersion) { + logrus.Fatalf("please use a version > %s of the arduino-cli, installed version: %s", incompatibleVersion, version) + } + } // we continue the execution, it means that the version could be one of: + // - git-snapshot - local build using task build + // - nightly- - nightly build + // - test--git-snapshot - tester builds generated by the CI system +} + // parseCliCompileOutput function takes cmdOutToParse as argument, // cmdOutToParse is the json output captured from the command run // the function extracts and returns the paths of the .o files