Skip to content

Commit 0001550

Browse files
committed
Expose more information about config overrides
1 parent e53358d commit 0001550

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99
### Added
1010
- C++ definitions of `ARDUINO_CI_COMPILATION_MOCKS` and `ARDUINO_CI_GODMODE` to aid in compilation macros
11+
- `CIConfig.available_override_config_path()` to search for available override files in standard locations
12+
- `CIConfig.override_file_from_project_library` and `CIConfig.override_file_from_example` to expose config locations
1113

1214
### Changed
1315
- `CIConfig` now uses `Pathname` instead of strings
1416

1517
### Deprecated
1618

1719
### Removed
20+
- `CIConfig.with_config`, which was only used internally
1821

1922
### Fixed
2023
- `arduino_ci.rb --help` no longer crashes

Diff for: lib/arduino_ci/ci_config.rb

+26-16
Original file line numberDiff line numberDiff line change
@@ -196,35 +196,45 @@ def with_override_config(config_hash)
196196
overridden_config
197197
end
198198

199-
# Get the config file at a given path, if it exists, and pass that to a block.
200-
# Many config files may exist, but only the first match is used
199+
# Get available configuration file, if one exists
201200
# @param base_dir [String] The directory in which to search for a config file
202-
# @param val_when_no_match [Object] The value to return if no config files are found
203-
# @yield [path] Process the configuration file at the given path
204-
# @yieldparam [String] The path of an existing config file
205-
# @yieldreturn [ArduinoCI::CIConfig] a settings object
206-
# @return [ArduinoCI::CIConfig]
207-
def with_config(base_dir, val_when_no_match)
208-
CONFIG_FILENAMES.each do |f|
209-
path = base_dir.nil? ? Pathname.new(f) : base_dir + f
210-
return (yield path) if path.exist?
211-
end
212-
val_when_no_match
201+
# @return [Pathname] the first available config file we could find, or nil
202+
def available_override_config_path(base_dir = nil)
203+
CONFIG_FILENAMES.map { |f| base_dir.nil? ? Pathname.new(f) : base_dir + f }.find(&:exist?)
204+
end
205+
206+
# Find an available override file from the project directory
207+
#
208+
# @todo this is currently reliant on launching the arduino_ci.rb test runner from
209+
# the correct working directory
210+
# @return [Pathname] A file that can override project config, or nil if none was found
211+
def override_file_from_project_library
212+
available_override_config_path(nil)
213+
end
214+
215+
# Find an available override file from an example sketch
216+
#
217+
# @param path [Pathname] the path to the example or example directory
218+
# @return [Pathname] A file that can override project config, or nil if none was found
219+
def override_file_from_example(example_path)
220+
base_dir = example_path.directory? ? example_path : example_path.dirname
221+
available_override_config_path(base_dir)
213222
end
214223

215224
# Produce a configuration, assuming the CI script runs from the working directory of the base project
216225
# @return [ArduinoCI::CIConfig] the new settings object
217226
def from_project_library
218-
with_config(nil, self) { |path| with_override(path) }
227+
ovr = override_file_from_project_library
228+
ovr.nil? ? self : with_override(ovr)
219229
end
220230

221231
# Produce a configuration override taken from an Arduino library example path
222232
# handle either path to example file or example dir
223233
# @param path [Pathname] the path to the settings yaml file
224234
# @return [ArduinoCI::CIConfig] the new settings object
225235
def from_example(example_path)
226-
base_dir = example_path.directory? ? example_path : example_path.dirname
227-
with_config(base_dir, self) { |path| with_override(path) }
236+
ovr = override_file_from_example(example_path)
237+
ovr.nil? ? self : with_override(ovr)
228238
end
229239

230240
# get information about a given platform: board name, package name, compiler stuff, etc

Diff for: spec/ci_config_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,14 @@
121121
end
122122
end
123123

124-
context "with_config" do
124+
context "with overrides from files" do
125125
it "loads from yaml" do
126126
override_dir = Pathname.new(__dir__) + "yaml" + "override1"
127127
base_config = ArduinoCI::CIConfig.default
128+
found_override_file = base_config.override_file_from_example(override_dir)
129+
expect(found_override_file).to_not be(nil)
130+
expect(found_override_file).to be_a(Pathname)
131+
expect(found_override_file).to exist
128132
combined_config = base_config.from_example(override_dir)
129133

130134
expect(combined_config).not_to be nil

0 commit comments

Comments
 (0)