Skip to content

Commit

Permalink
Convert ci_config to use pathname
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfixes committed Dec 31, 2022
1 parent 0f47a7e commit e53358d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- C++ definitions of `ARDUINO_CI_COMPILATION_MOCKS` and `ARDUINO_CI_GODMODE` to aid in compilation macros

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

### Deprecated

Expand Down
11 changes: 6 additions & 5 deletions lib/arduino_ci/ci_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'yaml'
require 'pathname'

# base config (platforms)
# project config - .arduino_ci_platforms.yml
Expand Down Expand Up @@ -58,7 +59,7 @@ class << self
def default
ret = new
ret.instance_variable_set("@is_default", true)
ret.load_yaml(File.expand_path("../../misc/default.yml", __dir__))
ret.load_yaml((Pathname.new(__dir__) + "../../misc/default.yml").realpath)
ret
end
end
Expand Down Expand Up @@ -205,8 +206,8 @@ def with_override_config(config_hash)
# @return [ArduinoCI::CIConfig]
def with_config(base_dir, val_when_no_match)
CONFIG_FILENAMES.each do |f|
path = base_dir.nil? ? f : File.join(base_dir, f)
return (yield path) if File.exist?(path)
path = base_dir.nil? ? Pathname.new(f) : base_dir + f
return (yield path) if path.exist?
end
val_when_no_match
end
Expand All @@ -219,10 +220,10 @@ def from_project_library

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

Expand Down
8 changes: 4 additions & 4 deletions spec/ci_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
context "hash" do
it "converts to hash" do
base = ArduinoCI::CIConfig.new
base.load_yaml(File.join(File.dirname(__FILE__), "yaml", "o2.yaml"))
base.load_yaml(Pathname.new(__dir__) + "yaml" + "o2.yaml")

expect(base.to_h).to eq(
packages: {},
Expand Down Expand Up @@ -82,7 +82,7 @@

context "with_override" do
it "loads from yaml" do
override_file = File.join(File.dirname(__FILE__), "yaml", "o1.yaml")
override_file = Pathname.new(__dir__) + "yaml" + "o1.yaml"
base = ArduinoCI::CIConfig.default
expect(base.is_default).to be true
combined_config = base.with_override(override_file)
Expand Down Expand Up @@ -123,7 +123,7 @@

context "with_config" do
it "loads from yaml" do
override_dir = File.join(File.dirname(__FILE__), "yaml", "override1")
override_dir = Pathname.new(__dir__) + "yaml" + "override1"
base_config = ArduinoCI::CIConfig.default
combined_config = base_config.from_example(override_dir)

Expand Down Expand Up @@ -188,7 +188,7 @@
"mars.cpp"
])

override_file = File.join(File.dirname(__FILE__), "yaml", "o1.yaml")
override_file = Pathname.new(__dir__) + "yaml" + "o1.yaml"
combined_config = ArduinoCI::CIConfig.default.with_override(override_file)
expect(combined_config.unittest_info[:testfiles][:select]).to match_array(["*-*.*"])
expect(combined_config.unittest_info[:testfiles][:reject]).to match_array(["sam-squamsh.*"])
Expand Down

0 comments on commit e53358d

Please # to comment.