From 3cf8115a363da7b98c5dc9cf88fbb80cab80b717 Mon Sep 17 00:00:00 2001 From: Helmi Date: Sat, 5 Mar 2022 17:28:20 +0700 Subject: [PATCH 1/3] Remove flag `--no-dry-run` for `arduino-ci >= 0.14.0` --- CHANGELOG.md | 1 + lib/arduino_ci/arduino_backend.rb | 15 ++++++++++- spec/arduino_backend_spec.rb | 43 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fdbffad..ae02a175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Support for `dtostrf()` - Added a CI workflow to lint the code base - Added a CI workflow to check for spelling errors +- Remove `--dry-run` flag for `arduino-cli` version `>= 0.14.0` ### Changed - We now compile a shared library to be used for each test. diff --git a/lib/arduino_ci/arduino_backend.rb b/lib/arduino_ci/arduino_backend.rb index e67710bf..a045b728 100644 --- a/lib/arduino_ci/arduino_backend.rb +++ b/lib/arduino_ci/arduino_backend.rb @@ -163,7 +163,12 @@ def compile_sketch(path, boardname) @last_msg = "Can't compile Sketch at nonexistent path '#{path}'!" return false end - ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", "--dry-run", path.to_s) + use_dry_run = should_use_dry_run? + if use_dry_run + ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", "--dry-run", path.to_s) + else + ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", path.to_s) + end @last_msg = ret[:out] ret[:success] end @@ -235,5 +240,13 @@ def install_local_library(path) Host.symlink(src_path, destination_path) cpp_library end + + private + + def should_use_dry_run? + ret = capture_json("version") + version = ret[:json]["VersionString"] + Gem::Version.new(version) < Gem::Version.new('0.14') + end end end diff --git a/spec/arduino_backend_spec.rb b/spec/arduino_backend_spec.rb index 5b654d5b..e8e685fa 100644 --- a/spec/arduino_backend_spec.rb +++ b/spec/arduino_backend_spec.rb @@ -103,5 +103,48 @@ def get_sketch(dir, file) it "Passes a simple INO sketch at #{sketch_path_ino}" do expect(backend.compile_sketch(sketch_path_ino, "arduino:avr:uno")).to be true end + + context "--dry-run flags" do + before { allow(backend).to receive(:run_and_capture).and_call_original } + + it "Uses --dry-run flag for arduino-cli version < 0.14.0" do + parsed_stdout = JSON.parse('{ "VersionString": "0.13.6" }') + cli_version_output = { + json: parsed_stdout + } + allow(backend).to receive(:capture_json).and_return cli_version_output + + backend.compile_sketch(sketch_path_ino, "arduino:avr:uno") + + expect(backend).to have_received(:run_and_capture).with( + "compile", + "--fqbn", + "arduino:avr:uno", + "--warnings", + "all", + "--dry-run", + sketch_path_ino + ) + end + + it "Does not use --dry-run flag for arduino-cli version >= 0.14.0" do + parsed_stdout = JSON.parse('{ "VersionString": "0.14.0" }') + cli_version_output = { + json: parsed_stdout + } + allow(backend).to receive(:capture_json).and_return cli_version_output + + backend.compile_sketch(sketch_path_ino, "arduino:avr:uno") + + expect(backend).to have_received(:run_and_capture).with( + "compile", + "--fqbn", + "arduino:avr:uno", + "--warnings", + "all", + sketch_path_ino + ) + end + end end end From 15a8201c2cd96d4fb641f75c5d3c58bfc6895757 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 11 Mar 2022 09:48:40 -0500 Subject: [PATCH 2/3] Add comments, avoid unnecessary assignments --- lib/arduino_ci/arduino_backend.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/arduino_ci/arduino_backend.rb b/lib/arduino_ci/arduino_backend.rb index a045b728..355417cb 100644 --- a/lib/arduino_ci/arduino_backend.rb +++ b/lib/arduino_ci/arduino_backend.rb @@ -163,11 +163,11 @@ def compile_sketch(path, boardname) @last_msg = "Can't compile Sketch at nonexistent path '#{path}'!" return false end - use_dry_run = should_use_dry_run? - if use_dry_run - ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", "--dry-run", path.to_s) + + ret = if should_use_dry_run? + run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", "--dry-run", path.to_s) else - ret = run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", path.to_s) + run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", path.to_s) end @last_msg = ret[:out] ret[:success] @@ -242,7 +242,9 @@ def install_local_library(path) end private - + + # Since the dry-run behavior became default in arduino-cli 0.14, the command line flag was removed + # @return [Bool] whether the --dry-run flag is available for this arduino-cli version def should_use_dry_run? ret = capture_json("version") version = ret[:json]["VersionString"] From 7ed0bcd1ffcdea4d902e6178e95bd51b3f09fc60 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 11 Mar 2022 09:51:23 -0500 Subject: [PATCH 3/3] whitespace --- lib/arduino_ci/arduino_backend.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arduino_ci/arduino_backend.rb b/lib/arduino_ci/arduino_backend.rb index 355417cb..33ef4302 100644 --- a/lib/arduino_ci/arduino_backend.rb +++ b/lib/arduino_ci/arduino_backend.rb @@ -242,7 +242,7 @@ def install_local_library(path) end private - + # Since the dry-run behavior became default in arduino-cli 0.14, the command line flag was removed # @return [Bool] whether the --dry-run flag is available for this arduino-cli version def should_use_dry_run?