Class: FileFinder

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

Instance Method Summary collapse

Instance Method Details

#find_assembly_file(filepath, complain = :error) ⇒ Object



174
175
176
177
# File 'lib/ceedling/file_finder.rb', line 174

def find_assembly_file(filepath, complain = :error)
  assembly_file = File.basename(filepath).ext(@configurator.extension_assembly)
  return @file_finder_helper.find_file_in_collection(assembly_file, @configurator.collection_all_assembly, complain, filepath)
end

#find_build_input_file(filepath:, complain: :error, context:) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/ceedling/file_finder.rb', line 50

def find_build_input_file(filepath:, complain: :error, context:)
  release = (context == RELEASE_SYM)

  found_file = nil

  # Strip off file extension
  source_file = File.basename(filepath).ext('')

  # We only collect files that already exist when we start up.
  # FileLists can produce undesired results for dynamically generated files depending on when they're accessed.
  # So collect mocks and runners separately and right now.
  # Assume that project configuration options will have already filtered out any files that should not be searched for.

  # Note: We carefully add file extensions below with string addition instead of using .ext()
  #       Some legacy files can include naming conventions like <name>.##.<ext> for versioning.
  #       If we use .ext() below we'll clobber the dotted portion of the filename

  # Generated test runners
  if (!release) and (source_file =~ /^#{@configurator.project_test_file_prefix}.+#{@configurator.test_runner_file_suffix}$/)
    _source_file = source_file + EXTENSION_CORE_SOURCE
    found_file =
      @file_finder_helper.find_file_in_collection(
        _source_file,
        @file_wrapper.directory_listing( File.join(@configurator.project_test_runners_path, '*') ),
        complain,
        filepath)

  # Generated mocks
  elsif (!release) and (source_file =~ /^#{@configurator.cmock_mock_prefix}/)
    _source_file = source_file + EXTENSION_CORE_SOURCE
    found_file =
      @file_finder_helper.find_file_in_collection(
        _source_file,
        @file_wrapper.directory_listing( File.join(@configurator.cmock_mock_path, '**/*') ),
        complain,
        filepath)

  # Vendor framework sources (unity.c, cmock.c, cexception.c, etc.)
  # Note: Taking a small chance by mixing test and release frameworks without smart checks on test/release build
  elsif (@configurator.collection_vendor_framework_sources.include?(source_file.ext(EXTENSION_CORE_SOURCE)))
    _source_file = source_file + EXTENSION_CORE_SOURCE
    found_file =
      @file_finder_helper.find_file_in_collection(
        _source_file,
        @configurator.collection_existing_test_build_input,
        complain,
        filepath)

  end

  if !found_file.nil?
    return found_file
  end

  #
  # Above we can confidently rely on the complain parameter passed to file_finder_helper because
  # we know the specific type of file being searched for.
  #
  # Below we ignore file misses because of lgoical complexities of searching for potentially either 
  # assmebly or C files, including C files that may not exist (counterparts to header files by convention).
  # We save the existence handling until the end.
  #

  # Assembly files for release build 
  if release and @configurator.release_build_use_assembly
    _source_file = source_file + @configurator.extension_assembly
    found_file =
      @file_finder_helper.find_file_in_collection(
        _source_file,
        @configurator.collection_release_build_input,
        :ignore,
        filepath)

  # Assembly files for test build 
  elsif (!release) and @configurator.test_build_use_assembly
    _source_file = source_file + @configurator.extension_assembly
    found_file =
      @file_finder_helper.find_file_in_collection(
        _source_file,
        @configurator.collection_existing_test_build_input,
        :ignore,
        filepath)
  end

  if !found_file.nil?
      return found_file
  end

  # Release build C files
  if release
    _source_file = source_file + @configurator.extension_source
    found_file =
      @file_finder_helper.find_file_in_collection(
        _source_file,
        @configurator.collection_release_build_input,
        :ignore,
        filepath)
      
  # Test build C files
  else
    _source_file = source_file + @configurator.extension_source
    found_file =
      @file_finder_helper.find_file_in_collection(
        _source_file,
        @configurator.collection_existing_test_build_input,
        :ignore,
        filepath)
  end

  if found_file.nil?
    _source_file += " or #{_source_file.ext(@configurator.extension_assembly)}" if @configurator.release_build_use_assembly
    @file_finder_helper.handle_missing_file(_source_file, complain)
  end

  return found_file
end

#find_file_from_list(filepath, file_list, complain) ⇒ Object



179
180
181
# File 'lib/ceedling/file_finder.rb', line 179

def find_file_from_list(filepath, file_list, complain)
  return @file_finder_helper.find_file_in_collection(filepath, file_list, complain, filepath)
end

#find_header_input_for_mock(mock_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ceedling/file_finder.rb', line 17

def find_header_input_for_mock(mock_name)
  # Mock name => <mock prefix><header filename without extension>
  # Examples: 'Mockfoo' or 'mock_Bar'
  # Note: In some rare cases, a mock name may include a dot (ex. Sensor.44) because of versioning file naming convention
  #       Be careful about assuming the end of the name has any sort of file extension

  header = mock_name.sub(/#{@configurator.cmock_mock_prefix}/, '') + @configurator.extension_header

  found_path = @file_finder_helper.find_file_in_collection(header, @configurator.collection_all_headers, :error, mock_name)

  return found_path
end

#find_source_file(filepath, complain = :error) ⇒ Object



168
169
170
171
# File 'lib/ceedling/file_finder.rb', line 168

def find_source_file(filepath, complain = :error)
  source_file = File.basename(filepath).ext(@configurator.extension_source)
  return @file_finder_helper.find_file_in_collection(source_file, @configurator.collection_all_source, complain, filepath)
end

#find_test_file_from_filepath(filepath) ⇒ Object

Find test filepath from another filepath (e.g. test executable with same base name, a/path/test_foo.exe)



32
33
34
35
36
37
# File 'lib/ceedling/file_finder.rb', line 32

def find_test_file_from_filepath(filepath)
  # Strip filepath down to filename and remove file extension
  name = File.basename( filepath ).ext('')

  return find_test_file_from_name( name )
end

#find_test_file_from_name(name) ⇒ Object

Find test filepath from only the base name of a test file (e.g. ‘test_foo’)



41
42
43
44
45
46
47
# File 'lib/ceedling/file_finder.rb', line 41

def find_test_file_from_name(name)
  test_file = name + @configurator.extension_source

  found_path = @file_finder_helper.find_file_in_collection(test_file, @configurator.collection_all_tests, :error, name)

  return found_path
end