Skip to content

Commit

Permalink
restore ability to do deep include tracking (now called :use_deep_pre…
Browse files Browse the repository at this point in the history
…processor). This is primarily to handle situations where mocks need includes further down the include chain.
  • Loading branch information
mvandervoord committed Dec 27, 2024
1 parent cd39b0c commit dbfb641
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 45 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ gem "constructor", "~> 2"
gem "thor", "~> 1.3"
gem "deep_merge", "~> 1.2"
gem "unicode-display_width", "~> 3.1"
gem "erb", "~> 4.0"

#these will be used if present, but ignored otherwise
#gem "curses"
Expand Down
7 changes: 4 additions & 3 deletions assets/project_as_gem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

# optional features. If you don't need them, keep them turned off for performance
:use_mocks: TRUE
:use_test_preprocessor: :none
:use_backtrace: :simple
:use_decorators: :auto #Decorate Ceedling's output text. Your options are :auto, :all, or :none
:use_test_preprocessor: :none # options are :none, :mocks, :tests, or :all
:use_deep_preprocessor: :mocks # options are :none, :mocks, :tests, or :all
:use_backtrace: :simple # options are :none, :simple, or :gdb
:use_decorators: :auto # decorate Ceedling's output text. options are :auto, :all, or :none

# tweak the way ceedling handles automatic tasks
:build_root: build
Expand Down
7 changes: 4 additions & 3 deletions assets/project_with_guts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

# optional features. If you don't need them, keep them turned off for performance
:use_mocks: TRUE
:use_test_preprocessor: :none
:use_backtrace: :simple
:use_decorators: :auto #Decorate Ceedling's output text. Your options are :auto, :all, or :none
:use_test_preprocessor: :none # options are :none, :mocks, :tests, or :all
:use_deep_preprocessor: :mocks # options are :none, :mocks, :tests, or :all
:use_backtrace: :simple # options are :none, :simple, or :gdb
:use_decorators: :auto # decorate Ceedling's output text. options are :auto, :all, or :none

# tweak the way ceedling handles automatic tasks
:build_root: build
Expand Down
7 changes: 5 additions & 2 deletions examples/temp_sensor/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@

# optional features. If you don't need them, keep them turned off for performance
:use_mocks: TRUE
:use_test_preprocessor: :all
:use_backtrace: :none
:use_test_preprocessor: :all # options are :none, :mocks, :tests, or :all
:use_deep_preprocessor: :mocks # options are :none, :mocks, :tests, or :all
:use_backtrace: :none # options are :none, :simple, or :gdb
:use_decorators: :auto # decorate Ceedling's output text. options are :auto, :all, or :none


# tweak the way ceedling handles automatic tasks
:build_root: build
Expand Down
1 change: 1 addition & 0 deletions lib/ceedling/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
:compile_threads => 1,
:test_threads => 1,
:use_test_preprocessor => :none,
:use_deep_preprocessor => :none,
:test_file_prefix => 'test_',
:release_build => false,
:use_backtrace => :simple
Expand Down
22 changes: 16 additions & 6 deletions lib/ceedling/preprocessinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setup
end


def preprocess_includes(filepath:, test:, flags:, include_paths:, defines:)
def preprocess_includes(filepath:, test:, flags:, include_paths:, defines:, deep: false)
includes_list_filepath = @file_path_utils.form_preprocessed_includes_list_filepath( filepath, test )

includes = []
Expand Down Expand Up @@ -66,7 +66,8 @@ def preprocess_includes(filepath:, test:, flags:, include_paths:, defines:)
test: test,
flags: flags,
include_paths: include_paths,
defines: defines
defines: defines,
deep: deep
)

msg = "Extracted #include list from #{filepath}:"
Expand All @@ -92,6 +93,9 @@ def preprocess_includes(filepath:, test:, flags:, include_paths:, defines:)
def preprocess_mockable_header_file(filepath:, test:, flags:, include_paths:, defines:)
preprocessed_filepath = @file_path_utils.form_preprocessed_file_filepath( filepath, test )

# Check if we're using deep define processing for mocks
preprocess_deep = !@configurator.project_use_deep_preprocessor.nil? && [:mocks, :all].include?(@configurator.project_use_deep_preprocessor)

plugin_arg_hash = {
header_file: filepath,
preprocessed_header_file: preprocessed_filepath,
Expand All @@ -109,7 +113,8 @@ def preprocess_mockable_header_file(filepath:, test:, flags:, include_paths:, de
test: test,
flags: flags,
include_paths: include_paths,
defines: defines
defines: defines,
deep: preprocess_deep
}

# Extract includes & log progress and details
Expand Down Expand Up @@ -151,6 +156,9 @@ def preprocess_mockable_header_file(filepath:, test:, flags:, include_paths:, de
def preprocess_test_file(filepath:, test:, flags:, include_paths:, defines:)
preprocessed_filepath = @file_path_utils.form_preprocessed_file_filepath( filepath, test )

# Check if we're using deep define processing for mocks
preprocess_deep = !@configurator.project_use_deep_preprocessor.nil? && [:tests, :all].include?(@configurator.project_use_deep_preprocessor)

plugin_arg_hash = {
test_file: filepath,
preprocessed_test_file: preprocessed_filepath,
Expand All @@ -168,7 +176,8 @@ def preprocess_test_file(filepath:, test:, flags:, include_paths:, defines:)
test: test,
flags: flags,
include_paths: include_paths,
defines: defines
defines: defines,
deep: preprocess_deep
}

# Extract includes & log progress and info
Expand Down Expand Up @@ -206,7 +215,7 @@ def preprocess_test_file(filepath:, test:, flags:, include_paths:, defines:)
### Private ###
private

def preprocess_file_common(filepath:, test:, flags:, include_paths:, defines:)
def preprocess_file_common(filepath:, test:, flags:, include_paths:, defines:, deep: false)
msg = @reportinator.generate_module_progress(
operation: "Preprocessing",
module_name: test,
Expand All @@ -221,7 +230,8 @@ def preprocess_file_common(filepath:, test:, flags:, include_paths:, defines:)
test: test,
flags: flags,
include_paths: include_paths,
defines: defines)
defines: defines,
deep: deep)

return includes
end
Expand Down
50 changes: 19 additions & 31 deletions lib/ceedling/preprocessinator_includes_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PreprocessinatorIncludesHandler
## should provide the tools to intervene.
##

def extract_includes(filepath:, test:, flags:, include_paths:, defines:)
def extract_includes(filepath:, test:, flags:, include_paths:, defines:, deep: false)
msg = @reportinator.generate_module_progress(
operation: "Extracting #include statements via preprocessor from",
module_name: test,
Expand Down Expand Up @@ -85,7 +85,7 @@ def extract_includes(filepath:, test:, flags:, include_paths:, defines:)
# Return
# - Includes common to shallow and nested results, with paths from nested
# - Add mocks back in (may be empty if mocking not enabled)
return common_includes(shallow:shallow, nested:nested) + mocks
return common_includes(shallow:shallow, nested:nested, deep:deep) + mocks
end

# Write to disk a yaml representation of a list of includes
Expand Down Expand Up @@ -343,7 +343,7 @@ def remove_mocks(includes)
end

# Return includes common in both lists with the full paths of the nested list
def common_includes(shallow:, nested:)
def common_includes(shallow:, nested:, deep: false)
return shallow if nested.empty?
return nested if shallow.empty?

Expand All @@ -354,41 +354,29 @@ def common_includes(shallow:, nested:)
# same directory as the file being processed

# Approach
# 1. Create hashed lists of shallow and nested for easier matching / deletion
# 2. Iterate through nested hash list and extract to common[] any filepath also in shallow
# 3. For each filepath extracted
# a. Delete it from the nested hash list
# b. Delete the corresponding entry in the shallow hash list
# 4. Iterate remaining nested hash list and extract to common[] and filepath whose base
# filename matches a remaining entry in the shallow hash list
# 1. Create hashed lists of shallow and nested for easier matching
# 2. Perform appropriate mix of paths
# a. A union if performing a deep include list
# b. An intersection if performing a shallow include list
# 3. Pick the "fullest" path from the lists (assumes nested list has deeper paths)

common = []

# Hash list
# Hash list for Shallow Search
_shallow = {}
shallow.each { |item| _shallow[item] = nil }
shallow.each { |item| _shallow[ File.basename(item) ] = item }

# Hash list
# Hash list for Nested Search
_nested = {}
nested.each { |item| _nested[item] = nil }

# Iterate each _nested entry and extract filepaths with matching filepath in _shallow list
_nested.each_key do |filepath|
if _shallow.has_key?( filepath )
common << filepath # Copy to common
_shallow.delete(filepath) # Remove matching filepath from _shallow list
end
end
nested.each {|item| _nested[ File.basename(item) ] = item }

# For each mached filepath, remove it from _nested list
common.each { |item| _nested.delete(item) }

# Find any reamining filepaths whose baseneame matches an entry in _shallow
_nested.each_key do |filepath|
common << filepath if _shallow.has_key?( File.basename(filepath) )
# Determine the filenames to include in our list
basenames = if deep
( _nested.to_set.union( _shallow.to_set ) )
else
( _nested.to_set.intersection( _shallow.to_set ) )
end

return common
# Iterate through the basenames and return the fullest version of each
return basenames.map {|v| _nested[v] || _shallow[v] }
end

end

0 comments on commit dbfb641

Please sign in to comment.