Class: Defineinator

Inherits:
Object show all
Defined in:
lib/ceedling/defineinator.rb

Overview

:defines:

:test:                               # Equivalent to [test]['*'] -- i.e. same defines for all test executables
  - TEST
  - PLATFORM_B

Instance Method Summary collapse

Instance Method Details

#defines(topkey: @topkey, subkey:, filepath: nil, default: []) ⇒ Object

Defaults to inspecting configurations beneath top-level :defines (But, we can also lookup defines symbol lists within framework configurations–:unity, :cmock, :cexception)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ceedling/defineinator.rb', line 39

def defines(topkey:@topkey, subkey:, filepath:nil, default:[])
  defines = @config_matchinator.get_config(primary:topkey, secondary:subkey)

  if defines == nil then return default
  # Flatten to handle list-nested YAML aliasing (should have already been flattened during validation)
  elsif defines.is_a?(Array) then return defines.flatten
  elsif defines.is_a?(Hash)
    arg_hash = {
      hash: defines,
      filepath: filepath,
      section: topkey,
      context: subkey
    }

    return @config_matchinator.matches?(**arg_hash)
  end

  # Handle unexpected config element type
  return []
end

#defines_defined?(context:) ⇒ Boolean



33
34
35
# File 'lib/ceedling/defineinator.rb', line 33

def defines_defined?(context:)
  return @config_matchinator.config_include?(primary:@topkey, secondary:context)
end

#generate_test_definition(filepath:) ⇒ Object

Optionally create a command line compilation symbol that is a test file’s sanitized/converted name



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ceedling/defineinator.rb', line 61

def generate_test_definition(filepath:)
  defines = []

  if @configurator.defines_use_test_definition
    # Get filename with no path or extension
    test_def = File.basename(filepath, '.*').strip

    # Replace any non-ASCII characters with underscores
    test_def = test_def.encode("ASCII", "UTF-8", invalid: :replace, undef: :replace, replace: "_")

    # Replace all non-alphanumeric characters (including spaces/punctuation but excluding underscores) with underscores
    test_def.gsub!(/[^0-9a-z_]/i, '_')

    # Convert to all caps
    test_def.upcase!

    # Add leading and trailiing underscores unless they already exist
    test_def = test_def.start_with?('_') ? test_def : ('_' + test_def)
    test_def = test_def.end_with?('_') ? test_def : (test_def + '_')

    # Add the test filename as a #define symbol to the array
    defines << test_def
  end

  return defines
end

#setupObject



29
30
31
# File 'lib/ceedling/defineinator.rb', line 29

def setup
  @topkey = :defines
end