@@ -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
0 commit comments