Skip to content

Commit

Permalink
Patched FileList behavior for :files handling
Browse files Browse the repository at this point in the history
- FileList’s behavior with relative file paths is not good. Until we can replace FileList fully, reworked `:files` file list revision to be properly robust.
  • Loading branch information
mkarlesky committed Feb 1, 2024
1 parent 9e4fe67 commit 94b5ce5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 38 deletions.
69 changes: 38 additions & 31 deletions lib/ceedling/configurator_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,10 @@ def collect_tests(in_hash)
all_tests.include( File.join(path, "#{in_hash[:project_test_file_prefix]}*#{in_hash[:extension_source]}") )
end

@file_path_collection_utils.revise_filelist( all_tests, in_hash[:files_test] )

return {:collection_all_tests => all_tests}
return {
# Add / subtract files via :files ↳ :test
:collection_all_tests => @file_path_collection_utils.revise_filelist( all_tests, in_hash[:files_test] )
}
end


Expand All @@ -332,10 +333,11 @@ def collect_assembly(in_hash)
all_assembly.include( File.join(path, "*#{in_hash[:extension_assembly]}") )
end

# Also add files that we are explicitly adding via :files:assembly: section
@file_path_collection_utils.revise_filelist( all_assembly, in_hash[:files_assembly] )
return {
# Add / subtract files via :files ↳ :assembly
:collection_all_assembly => @file_path_collection_utils.revise_filelist( all_assembly, in_hash[:files_assembly] )
}

return {:collection_all_assembly => all_assembly}
end


Expand All @@ -346,9 +348,10 @@ def collect_source(in_hash)
all_source.include( File.join(path, "*#{in_hash[:extension_source]}") )
end

@file_path_collection_utils.revise_filelist( all_source, in_hash[:files_source] )

return {:collection_all_source => all_source}
return {
# Add / subtract files via :files ↳ :source
:collection_all_source => @file_path_collection_utils.revise_filelist( all_source, in_hash[:files_source] )
}
end


Expand All @@ -364,9 +367,10 @@ def collect_headers(in_hash)
all_headers.include( File.join(path, "*#{in_hash[:extension_header]}") )
end

@file_path_collection_utils.revise_filelist( all_headers, in_hash[:files_include] )

return {:collection_all_headers => all_headers}
return {
# Add / subtract files via :files ↳ :include
:collection_all_headers => @file_path_collection_utils.revise_filelist( all_headers, in_hash[:files_include] )
}
end


Expand All @@ -387,10 +391,13 @@ def collect_release_build_input(in_hash)
release_input.include( File.join(path, "*#{in_hash[:extension_assembly]}") ) if in_hash[:release_build_use_assembly]
end

@file_path_collection_utils.revise_filelist( release_input, in_hash[:files_source] )
@file_path_collection_utils.revise_filelist( release_input, in_hash[:files_assembly] ) if in_hash[:release_build_use_assembly]
# Add / subtract files via :files ↳ :source & :files ↳ :assembly
revisions = in_hash[:files_source]
revisions += in_hash[:files_assembly] if in_hash[:release_build_use_assembly]

return {:collection_release_build_input => release_input}
return {
:collection_release_build_input => @file_path_collection_utils.revise_filelist( release_input, revisions )
}
end


Expand Down Expand Up @@ -420,12 +427,15 @@ def collect_existing_test_build_input(in_hash)
all_input.include( File.join(path, "*#{in_hash[:extension_assembly]}") ) if in_hash[:test_build_use_assembly]
end

@file_path_collection_utils.revise_filelist( all_input, in_hash[:files_test] )
@file_path_collection_utils.revise_filelist( all_input, in_hash[:files_support] )
@file_path_collection_utils.revise_filelist( all_input, in_hash[:files_source] )
@file_path_collection_utils.revise_filelist( all_input, in_hash[:files_assembly] ) if in_hash[:test_build_use_assembly]
# Add / subtract files via :files entries
revisions = in_hash[:files_test]
revisions += in_hash[:files_support]
revisions += in_hash[:files_source]
revisions += in_hash[:files_assembly] if in_hash[:test_build_use_assembly]

return {:collection_existing_test_build_input => all_input}
return {
:collection_existing_test_build_input => @file_path_collection_utils.revise_filelist( all_input, revisions )
}
end


Expand All @@ -451,10 +461,7 @@ def collect_test_fixture_extra_link_objects(in_hash)
support.include( File.join(path, "*#{in_hash[:extension_assembly]}") ) if in_hash[:test_build_use_assembly]
end

@file_path_collection_utils.revise_filelist( support, in_hash[:files_support] )

# Ensure FileList patterns & revisions are resolved into full list of filepaths
support.resolve()
support = @file_path_collection_utils.revise_filelist( support, in_hash[:files_support] )

support.each { |file| sources << file }

Expand All @@ -464,9 +471,10 @@ def collect_test_fixture_extra_link_objects(in_hash)
# No build paths here so plugins can remap if necessary (i.e. path mapping happens at runtime)
objects.map! { |object| object.ext(in_hash[:extension_object]) }

return { :collection_all_support => sources,
:collection_test_fixture_extra_link_objects => objects
}
return {
:collection_all_support => sources,
:collection_test_fixture_extra_link_objects => objects
}
end


Expand All @@ -476,10 +484,7 @@ def collect_vendor_framework_sources(in_hash)
filelist = @file_wrapper.instantiate_file_list()

# Vendor paths for frameworks
paths = []
paths << in_hash[:project_build_vendor_unity_path]
paths << in_hash[:project_build_vendor_cexception_path] if (in_hash[:project_use_exceptions])
paths << in_hash[:project_build_vendor_cmock_path] if (in_hash[:project_use_mocks])
paths = get_vendor_paths(in_hash)

# Collect vendor framework code files
paths.each do |path|
Expand All @@ -489,6 +494,8 @@ def collect_vendor_framework_sources(in_hash)
# Ensure FileList patterns & revisions are resolved into full list of filepaths
filelist.resolve()

puts(filelist)

# Extract just source file names
filelist.each do |filepath|
sources << File.basename(filepath)
Expand Down
2 changes: 2 additions & 0 deletions lib/ceedling/configurator_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def validate_required_sections(config)
return true
end


def validate_required_section_values(config)
validation = []
validation << @configurator_validator.exists?(config, :project, :build_root)
Expand All @@ -82,6 +83,7 @@ def validate_required_section_values(config)
return true
end


def validate_paths(config)
valid = true

Expand Down
2 changes: 0 additions & 2 deletions lib/ceedling/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class TestResultsSanityChecks
THOROUGH = 2 # perform checks that require inside knowledge of system workings
end


class StdErrRedirect
NONE = :none
AUTO = :auto
Expand All @@ -32,7 +31,6 @@ class StdErrRedirect
TCSH = :tcsh
end


unless defined?(PROJECT_ROOT)
PROJECT_ROOT = Dir.pwd()
end
Expand Down
40 changes: 35 additions & 5 deletions lib/ceedling/file_path_collection_utils.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'set'
require 'pathname'
require 'fileutils'
require 'rake'
require 'ceedling/file_path_utils'
require 'ceedling/exceptions'

Expand Down Expand Up @@ -81,18 +80,49 @@ def collect_paths(paths)
end


# Given a file list, add to it or remove from it considering (+:/-:) aggregation operators
# Given a file list, add to it or remove from it considering (+:/-:) aggregation operators.
# Rake's FileList does not robustly handle relative filepaths and patterns.
# So, we rebuild the FileList ourselves and return it.
# TODO: Replace FileList with our own, better version.
def revise_filelist(list, revisions)
plus = Set.new # All real, expanded directory paths to add
minus = Set.new # All real, expanded paths to exclude

# Build base plus set for revised path
list.each do |path|
# Start with expanding all list entries to absolute paths
plus << File.expand_path( path )
end

revisions.each do |revision|
# Include or exclude revision in file list
# Include or exclude revisions in file list
path = FilePathUtils.no_aggregation_decorators( revision )

# Working list of revisions
filepaths = []

# Expand path by pattern as needed and add only filepaths to working list
@file_wrapper.directory_listing( path ).each do |entry|
filepaths << File.expand_path( entry ) if !@file_wrapper.directory?( entry )
end

# Handle +: / -: revisions
if FilePathUtils.add_path?( revision )
list.include(path)
plus.merge( filepaths )
else
list.exclude(path)
minus.merge( filepaths )
end
end

# Use Set subtraction operator to remove any excluded paths
paths = (plus - minus).to_a

paths.map! do |path|
# Reform path from full absolute to nice, neat relative path instead
(Pathname.new( path ).relative_path_from( @working_dir_path )).to_s()
end

return FileList.new( paths )
end

end

0 comments on commit 94b5ce5

Please sign in to comment.