Skip to content

Commit 48321a3

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

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

Diff for: lib/arduino_ci/arduino_backend.rb

+25-7
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,31 @@ def last_bytes_usage
307308
Hash[mem_info.names.map(&:to_sym).zip(mem_info.captures.map(&:to_i))]
308309
end
309310

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
320+
310321
private
311322

312323
# Since the dry-run behavior became default in arduino-cli 0.14, the command line flag was removed
313324
# @return [Bool] whether the --dry-run flag is available for this arduino-cli version
314325
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')
326+
version < Gem::Version.new('0.14')
327+
end
328+
329+
# Since the config dir behavior has changed from a directory to a file (At some point??)
330+
# @return [Bool] whether to specify configuration by directory or filename
331+
def should_use_config_dir?
332+
@config_dir_hack = true # prevent an infinite loop when trying to run the command
333+
version < Gem::Version.new('0.14')
334+
ensure
335+
@config_dir_hack = false
318336
end
319337
end
320338
end

Diff for: spec/arduino_installation_spec.rb

+2-3
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

0 commit comments

Comments
 (0)