From daeb35205391b6c03da307a7dfc236b049bd9ebf Mon Sep 17 00:00:00 2001 From: Ben Yohay Date: Sun, 24 Oct 2021 15:02:14 +0300 Subject: [PATCH] file_reference: Remove all build files when file reference is removed. 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. --- lib/xcodeproj/project/object/file_reference.rb | 5 +++-- spec/project/object/file_reference_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/xcodeproj/project/object/file_reference.rb b/lib/xcodeproj/project/object/file_reference.rb index 0cf00436c..5a2b5ea53 100644 --- a/lib/xcodeproj/project/object/file_reference.rb +++ b/lib/xcodeproj/project/object/file_reference.rb @@ -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 # @@ -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 diff --git a/spec/project/object/file_reference_spec.rb b/spec/project/object/file_reference_spec.rb index 96a3691f0..cc2f2cd90 100644 --- a/spec/project/object/file_reference_spec.rb +++ b/spec/project/object/file_reference_spec.rb @@ -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