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..33ef4302 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) + + ret = if should_use_dry_run? + run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", "--dry-run", path.to_s) + else + run_and_capture("compile", "--fqbn", boardname, "--warnings", "all", path.to_s) + end @last_msg = ret[:out] ret[:success] end @@ -235,5 +240,15 @@ def install_local_library(path) Host.symlink(src_path, destination_path) cpp_library 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"] + 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