Skip to content

Commit

Permalink
file_reference: Remove all build files when file reference is removed.
Browse files Browse the repository at this point in the history
A build file doesn't have any meaning without its underyling file
reference, as it can't be built.
In this commit, when a file reference is removed, in addition to the
previouls file reference removal logic, the build files that refer to
the file references are removed as well.
  • Loading branch information
byohay committed Dec 16, 2021
1 parent a28d6c6 commit daeb352
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/xcodeproj/project/object/file_reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ def target_dependency_proxies
end

# In addition to removing the file reference, this will also remove any
# items related to this reference in case it represents an external
# Xcode project.
# items related to this reference.
#
# @see AbstractObject#remove_from_project
#
Expand All @@ -327,6 +326,8 @@ def remove_from_project
project_reference[:product_group].remove_from_project
project.root_object.project_references.delete(project_reference)
end

build_files.each(&:remove_from_project)
super
end

Expand Down
8 changes: 8 additions & 0 deletions spec/project/object/file_reference_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ module ProjectSpecs
@file.comments.should == 'This file was automatically generated.'
end

it 'removes the build files when removing the file reference' do
@target = @project.new_target(:static_library, 'Pods', :ios)
@target.build_phases[0].add_file_reference(@file)

@file.remove_from_project
@target.build_phases[0].files.should.be.empty
end

describe 'concerning proxies' do
it 'returns that it is not a proxy' do
@file.should.not.be.a.proxy
Expand Down

0 comments on commit daeb352

Please sign in to comment.