Skip to content

Commit

Permalink
file ref: Remove build files that refer to it when removed.
Browse files Browse the repository at this point in the history
`PBXReferenceProxy` and `PBXGroup`  might have build files that refer
to it, and as mentioned in the previous commit, they don't have any
meaning without it. Therefore everything that can be a file reference
removes the build files that refer to it.
  • Loading branch information
byohay committed Oct 31, 2021
1 parent 943852a commit 7253a62
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/xcodeproj/project/object/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,25 @@ def sort(options = nil)
result
end
end

# @return [Array<PBXBuildFile>] the build files associated with the
# current reference proxy.
#
def build_files
referrers.grep(PBXBuildFile)
end

# In addition to removing the reference proxy, this will also remove any
# items related to this reference.
#
# @see AbstractObject#remove_from_project
#
# @return [void]
#
def remove_from_project
build_files.each(&:remove_from_project)
super
end
end

#-----------------------------------------------------------------------#
Expand Down
19 changes: 19 additions & 0 deletions lib/xcodeproj/project/object/reference_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ def display_name
return path if path
super
end

# @return [Array<PBXBuildFile>] the build files associated with the
# current reference proxy.
#
def build_files
referrers.grep(PBXBuildFile)
end

# In addition to removing the reference proxy, this will also remove any
# items related to this reference.
#
# @see AbstractObject#remove_from_project
#
# @return [void]
#
def remove_from_project
build_files.each(&:remove_from_project)
super
end
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/project/object/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ module ProjectSpecs
end
end

it 'removes the build files when removing the group' do
@target = @project.new_target(:static_library, 'Pods', :ios)
build_file = @project.new(Xcodeproj::Project::PBXBuildFile)
build_file.file_ref = @group
@target.build_phases[0].files << build_file

@group.remove_from_project
@target.build_phases[0].files.should.be.empty
end
#-------------------------------------------------------------------------#
end
end
8 changes: 8 additions & 0 deletions spec/project/object/reference_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@ module ProjectSpecs
@proxy.path = 'Path/To/Proxy'
@proxy.display_name.should == 'Path/To/Proxy'
end

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

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

0 comments on commit 7253a62

Please sign in to comment.