Skip to content

Commit

Permalink
✨ Ruby string replacement for :defines & :flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarlesky committed May 23, 2024
1 parent 4b2dbd3 commit 7ce8c3b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/ceedling/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = []

Expand All @@ -498,6 +513,7 @@ def collect_path_list( container )
return paths.flatten()
end


def eval_path_entries( container )
paths = []

Expand All @@ -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

2 changes: 2 additions & 0 deletions lib/ceedling/setupinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit 7ce8c3b

Please sign in to comment.