Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expose more information about config overrides
  • Loading branch information
ianfixes committed Dec 31, 2022
commit 0001550ee43083392a3d4d01ba326feb85a23003
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- C++ definitions of `ARDUINO_CI_COMPILATION_MOCKS` and `ARDUINO_CI_GODMODE` to aid in compilation macros
- `CIConfig.available_override_config_path()` to search for available override files in standard locations
- `CIConfig.override_file_from_project_library` and `CIConfig.override_file_from_example` to expose config locations

### Changed
- `CIConfig` now uses `Pathname` instead of strings

### Deprecated

### Removed
- `CIConfig.with_config`, which was only used internally

### Fixed
- `arduino_ci.rb --help` no longer crashes
Expand Down
42 changes: 26 additions & 16 deletions lib/arduino_ci/ci_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,35 +196,45 @@ def with_override_config(config_hash)
overridden_config
end

# Get the config file at a given path, if it exists, and pass that to a block.
# Many config files may exist, but only the first match is used
# Get available configuration file, if one exists
# @param base_dir [String] The directory in which to search for a config file
# @param val_when_no_match [Object] The value to return if no config files are found
# @yield [path] Process the configuration file at the given path
# @yieldparam [String] The path of an existing config file
# @yieldreturn [ArduinoCI::CIConfig] a settings object
# @return [ArduinoCI::CIConfig]
def with_config(base_dir, val_when_no_match)
CONFIG_FILENAMES.each do |f|
path = base_dir.nil? ? Pathname.new(f) : base_dir + f
return (yield path) if path.exist?
end
val_when_no_match
# @return [Pathname] the first available config file we could find, or nil
def available_override_config_path(base_dir = nil)
CONFIG_FILENAMES.map { |f| base_dir.nil? ? Pathname.new(f) : base_dir + f }.find(&:exist?)
end

# Find an available override file from the project directory
#
# @todo this is currently reliant on launching the arduino_ci.rb test runner from
# the correct working directory
# @return [Pathname] A file that can override project config, or nil if none was found
def override_file_from_project_library
available_override_config_path(nil)
end

# Find an available override file from an example sketch
#
# @param path [Pathname] the path to the example or example directory
# @return [Pathname] A file that can override project config, or nil if none was found
def override_file_from_example(example_path)
base_dir = example_path.directory? ? example_path : example_path.dirname
available_override_config_path(base_dir)
end

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

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

# get information about a given platform: board name, package name, compiler stuff, etc
Expand Down
6 changes: 5 additions & 1 deletion spec/ci_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,14 @@
end
end

context "with_config" do
context "with overrides from files" do
it "loads from yaml" do
override_dir = Pathname.new(__dir__) + "yaml" + "override1"
base_config = ArduinoCI::CIConfig.default
found_override_file = base_config.override_file_from_example(override_dir)
expect(found_override_file).to_not be(nil)
expect(found_override_file).to be_a(Pathname)
expect(found_override_file).to exist
combined_config = base_config.from_example(override_dir)

expect(combined_config).not_to be nil
Expand Down