Skip to content

Commit c46ae30

Browse files
committed
Make config yaml path version-aware
1 parent cd889d7 commit c46ae30

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

lib/arduino_ci/arduino_backend.rb

+24-8
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ def initialize(binary_path)
4848
@last_out = ""
4949
@last_err = ""
5050
@last_msg = ""
51+
@config_dir_hack = false
5152
end
5253

5354
def _wrap_run(work_fn, *args, **kwargs)
5455
# do some work to extract & merge environment variables if they exist
5556
has_env = !args.empty? && args[0].instance_of?(Hash)
5657
env_vars = has_env ? args[0] : {}
5758
actual_args = has_env ? args[1..-1] : args # need to shift over if we extracted args
58-
custom_config = @config_dir.nil? ? [] : ["--config-file", config_file_cli_param.to_s]
59+
custom_config = []
60+
custom_config += ["--config-file", config_file_cli_param.to_s] unless @config_dir_hack || @config_dir.nil?
5961
full_args = [binary_path.to_s, "--format", "json"] + custom_config + actual_args
6062
full_cmd = env_vars.empty? ? full_args : [env_vars] + full_args
6163

@@ -91,12 +93,11 @@ def config_file_path=(rhs)
9193

9294
# The config file to be used as a CLI param
9395
#
94-
# Apparently Linux wants the whole path, and OSX wants just the directory as of 0.29.0,
95-
# it's all very annoying. See unit tests.
96+
# This format changes based on version, whcih is very annoying. See unit tests.
9697
#
9798
# @return [Pathname] the path to use for a given OS
9899
def config_file_cli_param
99-
OS.osx? ? @config_dir : config_file_path
100+
should_use_config_dir? ? @config_dir : config_file_path
100101
end
101102

102103
# Get an acceptable filename for use as a config file
@@ -307,14 +308,29 @@ def last_bytes_usage
307308
Hash[mem_info.names.map(&:to_sym).zip(mem_info.captures.map(&:to_i))]
308309
end
309310

310-
private
311+
# @return [String] the arduino-cli version that the backend is using, as String
312+
def version_str
313+
capture_json("version")[:json]["VersionString"]
314+
end
315+
316+
# @return [Gem::Version] the arduino-cli version that the backend is using, as a semver object
317+
def version
318+
Gem::Version.new(version_str)
319+
end
311320

312321
# Since the dry-run behavior became default in arduino-cli 0.14, the command line flag was removed
313322
# @return [Bool] whether the --dry-run flag is available for this arduino-cli version
314323
def should_use_dry_run?
315-
ret = capture_json("version")
316-
version = ret[:json]["VersionString"]
317-
Gem::Version.new(version) < Gem::Version.new('0.14')
324+
version < Gem::Version.new('0.14')
325+
end
326+
327+
# Since the config dir behavior has changed from a directory to a file (At some point??)
328+
# @return [Bool] whether to specify configuration by directory or filename
329+
def should_use_config_dir?
330+
@config_dir_hack = true # prevent an infinite loop when trying to run the command
331+
version < Gem::Version.new('0.14')
332+
ensure
333+
@config_dir_hack = false
318334
end
319335
end
320336
end

spec/arduino_installation_spec.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ def with_tmp_file(desired_filename = nil)
2525
end
2626

2727
def config_success_msg(config_file)
28-
config_file_str = config_file.to_s
29-
config_file_str = config_file_str.gsub('/', '\\') if OS.windows?
30-
"Using config file: #{config_file}"
28+
config_file_str = OS.windows? ? ArduinoCI::Host.pathname_to_windows(config_file) : config_file
29+
"Using config file: #{config_file_str}"
3130
end
3231

3332
def config_fail_msg
@@ -80,7 +79,7 @@ def config_fail_msg
8079
expect(config_dir).to exist
8180
expect(config_file).to exist
8281
ret = ArduinoCI::Host.run_and_capture(*bug_753_cmd(backend, config_file))
83-
if OS.osx?
82+
if backend.should_use_config_dir?
8483
expect(ret[:out].lines[0]).to include(config_fail_msg)
8584
else
8685
expect(ret[:out].lines[0]).to include(config_success_msg(config_file))
@@ -104,7 +103,7 @@ def config_fail_msg
104103
expect(config_dir).to exist
105104
expect(config_file).to exist
106105
ret = ArduinoCI::Host.run_and_capture(*bug_753_cmd(backend, config_dir))
107-
if OS.osx?
106+
if backend.should_use_config_dir?
108107
expect(ret[:out].lines[0]).to include(config_success_msg(config_file))
109108
else
110109
expect(ret[:out].lines[0]).to include(config_fail_msg)

0 commit comments

Comments
 (0)