From 7ce8c3b894545364b81d9a0ae2fa9849c67a5d01 Mon Sep 17 00:00:00 2001 From: Mike Karlesky Date: Wed, 22 May 2024 22:00:09 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Ruby=20string=20replacement=20for?= =?UTF-8?q?=20:defines=20&=20:flags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ceedling/configurator.rb | 37 ++++++++++++++++++++++++++++++++++++ lib/ceedling/setupinator.rb | 2 ++ 2 files changed, 39 insertions(+) diff --git a/lib/ceedling/configurator.rb b/lib/ceedling/configurator.rb index d7140464..76eb90d5 100644 --- a/lib/ceedling/configurator.rb +++ b/lib/ceedling/configurator.rb @@ -352,6 +352,20 @@ def eval_paths(config) end + # Handle any Ruby string replacement for :flags string arrays + def eval_flags(config) + # Descend down to array of command line flags strings regardless of depth in config block + traverse_hash_eval_string_arrays( config[:flags] ) + end + + + # Handle any Ruby string replacement for :defines string arrays + def eval_defines(config) + # Descend down to array of #define strings regardless of depth in config block + traverse_hash_eval_string_arrays( config[:defines] ) + end + + def standardize_paths(config) # Individual paths that don't follow `_path` convention processed here paths = [ @@ -486,6 +500,7 @@ def reform_path_entries_as_lists( container, entry, value ) container[entry] = [value] if value.kind_of?( String ) end + def collect_path_list( container ) paths = [] @@ -498,6 +513,7 @@ def collect_path_list( container ) return paths.flatten() end + def eval_path_entries( container ) paths = [] @@ -513,5 +529,26 @@ def eval_path_entries( container ) end end + + # Traverse configuration tree recursively to find terminal leaf nodes that are a list of strings; + # expand in place any string with the Ruby string replacement pattern. + def traverse_hash_eval_string_arrays(config) + case config + + when Array + # If it's an array of strings, process it + if config.all? { |item| item.is_a?( String ) } + # Expand in place each string item in the array + config.each do |item| + item.replace( @system_wrapper.module_eval( item ) ) if (item =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + end + + when Hash + # Recurse + config.each_value { |value| traverse_hash_eval_string_arrays( value ) } + end + end + end diff --git a/lib/ceedling/setupinator.rb b/lib/ceedling/setupinator.rb index 31af7330..92ddb617 100644 --- a/lib/ceedling/setupinator.rb +++ b/lib/ceedling/setupinator.rb @@ -42,6 +42,8 @@ def do_setup( app_cfg ) @ceedling[:configurator].configure_test_runner_generation( config_hash ) @ceedling[:configurator].eval_environment_variables( config_hash ) @ceedling[:configurator].eval_paths( config_hash ) + @ceedling[:configurator].eval_flags( config_hash ) + @ceedling[:configurator].eval_defines( config_hash ) @ceedling[:configurator].standardize_paths( config_hash ) @ceedling[:configurator].find_and_merge_plugins( app_cfg[:ceedling_plugins_path], config_hash ) @ceedling[:configurator].tools_setup( config_hash )