Skip to content

Commit

Permalink
Merge pull request #2 from igor-makarov/fix-file-refs
Browse files Browse the repository at this point in the history
Disambiguate file refs better
  • Loading branch information
igor-makarov authored Aug 5, 2021
2 parents a4ef245 + 8f41009 commit d6ab105
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/censorius.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,18 @@ def generate_paths_group(group)
end
end

def generate_paths_file_reference(file_reference)
def generate_paths_file_reference(file_reference) # rubocop:disable Metrics/AbcSize
project_path = @paths_by_object[file_reference.project.root_object]
@paths_by_object[file_reference] = "#{project_path}/PBXFileReference(#{file_reference.full_path})"
params = []
if !file_reference.name.nil? &&
!file_reference.name.empty? &&
file_reference.name != File.basename(file_reference.full_path, '.*') &&
file_reference.name != File.basename(file_reference.full_path)
params << "name: #{file_reference.name}"
end
params << file_reference.full_path.to_s

@paths_by_object[file_reference] = "#{project_path}/PBXFileReference(#{params.join(', ')})"
end

def generate_paths_target_dependency(dependency, parent_path)
Expand Down
10 changes: 8 additions & 2 deletions spec/censorius_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ def recursive_add_file(path)
recursive_add_file('group/in_group.txt')
recursive_add_file('path/to/nested/group/nested.txt')
@project.new_file('built_product.txt', :built_products)
with_different_name = @project.new_file('different_file.txt')
with_different_name.name = 'different_name'

@generator.generate!

expect(@project.sorted_md5s).to eq %W[
expect(@project.sorted_md5s).to eq (%W[
PBXProject(#{@spec_safe_name})
PBXProject(#{@spec_safe_name})/PBXFileReference(${BUILT_PRODUCTS_DIR}/built_product.txt)
PBXProject(#{@spec_safe_name})/PBXFileReference(at_root.txt)
PBXProject(#{@spec_safe_name})/PBXFileReference(group/in_group.txt)
] + [
"PBXProject(#{@spec_safe_name})/PBXFileReference(name: different_name, different_file.txt)"
] + %W[
PBXProject(#{@spec_safe_name})/PBXGroup(/)
PBXProject(#{@spec_safe_name})/PBXGroup(/Frameworks)
PBXProject(#{@spec_safe_name})/PBXGroup(/Products)
Expand All @@ -68,7 +74,7 @@ def recursive_add_file(path)
PBXProject(#{@spec_safe_name})/XCConfigurationList
PBXProject(#{@spec_safe_name})/XCConfigurationList/XCBuildConfiguration(Debug)
PBXProject(#{@spec_safe_name})/XCConfigurationList/XCBuildConfiguration(Release)
].sorted_md5s
]).sorted_md5s
end

it 'generates UUIDs for build configurations' do
Expand Down

0 comments on commit d6ab105

Please sign in to comment.