From f75275c0d2ffd2b8e4096eb99ab4a23243e5cea8 Mon Sep 17 00:00:00 2001 From: Claudio Emanoel Barbosa Lima Date: Mon, 22 Apr 2024 14:34:55 -0300 Subject: [PATCH] Add @system_wrapper.module_eval to defineinator, flaginator, so enviroment variables, #{ENV['VARIABLE']}, are parsed now. --- lib/ceedling/defineinator.rb | 36 ++++++++++++++++++++++++++++++------ lib/ceedling/flaginator.rb | 34 +++++++++++++++++++++++++++++----- lib/ceedling/objects.yml | 2 ++ 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/lib/ceedling/defineinator.rb b/lib/ceedling/defineinator.rb index a986e24d2..ed739b986 100644 --- a/lib/ceedling/defineinator.rb +++ b/lib/ceedling/defineinator.rb @@ -24,7 +24,7 @@ class Defineinator - constructor :configurator, :streaminator, :config_matchinator + constructor :configurator, :streaminator, :config_matchinator, :system_wrapper def setup @topkey = :defines @@ -38,9 +38,16 @@ def defines_defined?(context:) # (But, we can also lookup defines symbol lists within framework configurations--:unity, :cmock, :cexception) def defines(topkey:@topkey, subkey:, filepath:nil) defines = @config_matchinator.get_config(primary:topkey, secondary:subkey) - - if defines == nil then return [] - elsif defines.is_a?(Array) then return defines.flatten # Flatten to handle list-nested YAML aliases + ret_defines = [] + + if defines == nil + ret_defines = [] + elsif defines.is_a?(Array) + defines_parsed = defines.flatten # Flatten to handle list-nested YAML aliases + defines_parsed.each do |element| + element = element.replace( @system_wrapper.module_eval( element ) ) if (element =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + ret_defines = defines_parsed elsif defines.is_a?(Hash) @config_matchinator.validate_matchers(hash:defines, section:@topkey, context:subkey) @@ -51,11 +58,28 @@ def defines(topkey:@topkey, subkey:, filepath:nil) context: subkey } - return @config_matchinator.matches?(**arg_hash) + defines_parsed = @config_matchinator.matches?(**arg_hash) + defines_parsed.each do |key, value| + key = key.replace( @system_wrapper.module_eval( key ) ) if (key =~ RUBY_STRING_REPLACEMENT_PATTERN) + if value.is_a?(Array) + value.each do |v| + v = v.replace( @system_wrapper.module_eval( v ) ) if (v =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + elsif value.is_a?(Hash) + value.each do |k,v| + k = k.replace( @system_wrapper.module_eval( k ) ) if (k =~ RUBY_STRING_REPLACEMENT_PATTERN) + v = v.replace( @system_wrapper.module_eval( v ) ) if (v =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + else + value = value.replace( @system_wrapper.module_eval( value ) ) if (value =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + end + + ret_defines = defines_parsed end # Handle unexpected config element type - return [] + return ret_defines end # Optionally create a command line compilation symbol that is a test file's sanitized/converted name diff --git a/lib/ceedling/flaginator.rb b/lib/ceedling/flaginator.rb index 3c2cb1a25..cbbb1d61b 100644 --- a/lib/ceedling/flaginator.rb +++ b/lib/ceedling/flaginator.rb @@ -30,7 +30,7 @@ class Flaginator - constructor :configurator, :streaminator, :config_matchinator + constructor :configurator, :streaminator, :config_matchinator, :system_wrapper def setup @section = :flags @@ -42,9 +42,16 @@ def flags_defined?(context:, operation:nil) def flag_down(context:, operation:, filepath:nil) flags = @config_matchinator.get_config(primary:@section, secondary:context, tertiary:operation) + ret_flags = [] - if flags == nil then return [] - elsif flags.is_a?(Array) then return flags.flatten # Flatten to handle list-nested YAML aliases + if flags == nil + ret_flags = [] + elsif flags.is_a?(Array) + flags_parsed = flags.flatten # Flatten to handle list-nested YAML aliases + flags_parsed.each do |element| + element = element.replace( @system_wrapper.module_eval( element ) ) if (element =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + ret_flags = flags_parsed elsif flags.is_a?(Hash) @config_matchinator.validate_matchers(hash:flags, section:@section, context:context, operation:operation) @@ -56,11 +63,28 @@ def flag_down(context:, operation:, filepath:nil) operation: operation } - return @config_matchinator.matches?(**arg_hash) + flags_parsed = @config_matchinator.matches?(**arg_hash) + flags_parsed.each do |key, value| + key = key.replace( @system_wrapper.module_eval( key ) ) if (key =~ RUBY_STRING_REPLACEMENT_PATTERN) + if value.is_a?(Array) + value.each do |v| + v = v.replace( @system_wrapper.module_eval( v ) ) if (v =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + elsif value.is_a?(Hash) + value.each do |k,v| + k = k.replace( @system_wrapper.module_eval( k ) ) if (k =~ RUBY_STRING_REPLACEMENT_PATTERN) + v = v.replace( @system_wrapper.module_eval( v ) ) if (v =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + else + value = value.replace( @system_wrapper.module_eval( value ) ) if (value =~ RUBY_STRING_REPLACEMENT_PATTERN) + end + end + + ret_flags = flags_parsed end # Handle unexpected config element type - return [] + return ret_flags end end diff --git a/lib/ceedling/objects.yml b/lib/ceedling/objects.yml index 6b16b7630..28ee8f95f 100644 --- a/lib/ceedling/objects.yml +++ b/lib/ceedling/objects.yml @@ -205,12 +205,14 @@ flaginator: - configurator - streaminator - config_matchinator + - system_wrapper defineinator: compose: - configurator - streaminator - config_matchinator + - system_wrapper generator: compose: