Skip to content

Commit

Permalink
🐛 Preprocessing + CMock :treat_inlines
Browse files Browse the repository at this point in the history
- Mock output paths are now high up in the search path ordering to facilitate CMock-generated header files being found first
- Preprocessing of header files before mocking now removes paths of #include directives that gcc expands
  • Loading branch information
mkarlesky committed Jul 15, 2024
1 parent d4bbc17 commit ab5427f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion lib/ceedling/preprocessinator_file_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def preprocess_header_file(source_filepath:, preprocessed_filepath:, includes:,
guardname = '_' + filename.gsub(/\W/, '_').upcase + '_'

forward_guards = [
"#ifndef #{guardname} // Ceedling-generated guard",
"#ifndef #{guardname} // Ceedling-generated include guard",
"#define #{guardname}",
''
]
Expand All @@ -58,6 +58,12 @@ def preprocess_header_file(source_filepath:, preprocessed_filepath:, includes:,
# ----------------------------------------------------
contents = contents.join("\n")
contents.gsub!( /(\h*\n){3,}/, "\n\n" )

# Remove paths from expanded #include directives
# ----------------------------------------------------
# - We rely on search paths at compilation rather than explicit #include paths
# - Match (#include ")((path/)+)(file") and reassemble string using first and last matching groups
contents.gsub!( /(#include\s+")(([^\/]+\/)+)(.+")/, '\1\4' )

@file_wrapper.write( preprocessed_filepath, contents )

Expand Down
7 changes: 5 additions & 2 deletions lib/ceedling/test_invoker_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,14 @@ def validate_build_directive_source_files(test:, filepath:)
end

def search_paths(filepath, subdir)
paths = @include_pathinator.lookup_test_directive_include_paths( filepath )
paths = []

# Start with mock path to ensure any CMock-reworked header files are encountered first
paths << File.join( @configurator.cmock_mock_path, subdir ) if @configurator.project_use_mocks
paths += @include_pathinator.lookup_test_directive_include_paths( filepath )
paths += @include_pathinator.collect_test_include_paths()
paths += @configurator.collection_paths_support
paths += @configurator.collection_paths_include
paths << File.join( @configurator.cmock_mock_path, subdir ) if @configurator.project_use_mocks
paths += @configurator.collection_paths_libraries
paths += @configurator.collection_paths_vendor
paths += @configurator.collection_paths_test_toolchain_include
Expand Down

0 comments on commit ab5427f

Please sign in to comment.