Commit 0aefe207 authored by AliSoftware's avatar AliSoftware

[xcassets] Remove resources from Resource Build Phase of *deintegrated* targets

parent f4c64317
......@@ -113,13 +113,56 @@ module Pod
targets_to_integrate.sort_by(&:name).each do |target|
TargetIntegrator.new(target).integrate!
end
# TODO: If a previously integrated target is removed from the Podfile,
# we should remove its resources from the deintegrated target
# TODO: Remove the file_refs in Pods/Resources if they are not linked
# to any native_target anymore (which can happen after a target deintegration)
# TODO: Remove the Pods/Resources group if empty
target_uuids_to_integrate = targets_to_integrate.flat_map(&:user_target_uuids).uniq
user_project_paths.each do |user_project_path|
project = Xcodeproj::Project.open(user_project_path)
# TODO: Remove xcconfig files from targets_not_integrated
# targets_not_integrated = project.targets.reject do |user_target|
# target_uuids_to_integrate.include?(user_target.uuid)
# end
clean_deintegrated_targets_resources(project, target_uuids_to_integrate)
end
end
def clean_deintegrated_targets_resources(project, target_uuids_to_keep)
is_dirty = false
TargetIntegrator.each_pods_resources(project) do |file_ref|
puts "Analyzing Pods/Resources/#{file_ref}"
file_in_at_least_one_target = false
project.targets.each do |user_target|
# Seems like user_target.resources_build_phase.include?(file_ref) does not work as expected here :(
file_is_in_target = user_target.resources_build_phase.files_references.any? { |f| f.path == file_ref.path }
next unless file_is_in_target
if target_uuids_to_keep.include?(user_target.uuid)
# This target is one to integrate, the resource will be kept in there
file_in_at_least_one_target = true
UI.puts " - Should be kept in for target #{user_target}"
else
UI.puts " - Removing #{file_ref} from #{user_target} because target not integrated anymore."
user_target.resources_build_phase.remove_file_reference(file_ref)
is_dirty = true
end
end
unless file_in_at_least_one_target
# TODO: Remove the file_refs in Pods/Resources if they are not linked
# to any native_target anymore (which can happen after a target deintegration)
UI.puts " -> File #{file_ref} is not in any user target anymore, remove it from the project"
file_ref.remove_from_project
is_dirty = true
end
end
# TODO: Iterate over each subgroup of the Pods/Resources group, removing them if empty.
# TODO: Also remove Pods/Resources group itself if it ends up empty.
if is_dirty
project.save
end
end
# Warns the user if the podfile is empty.
......
......@@ -182,7 +182,6 @@ module Pod
refs_to_remove.each do |file_ref|
native_targets.each do |user_target|
UI.puts " - Removing #{file_ref} from #{user_target} because it is no longer needed."
# FIXME: XcodeProj issue? The PBXBuildFile is replaced with (null) instead of being removed
user_target.resources_build_phase.remove_file_reference(file_ref)
dirty = true
end
......@@ -195,23 +194,35 @@ module Pod
dirty
end
# Remove the 'Pods/Resources' group and all the pods resources from the user target
# Remove the pods resources from the user target's Copy Resource Build Phase
#
# @return [Boolean] true if user project has been modified
#
def remove_pods_resources
pods_group = user_project['Pods']
TargetIntegrator.each_pods_resources(user_project) do |file_ref|
native_targets.each do |user_target|
UI.puts " - Removing #{file_ref} from #{user_target} because it is no longer needed."
user_target.resources_build_phase.remove_file_reference(file_ref)
end
end
end
# Iterate over each file in the 'Pods/Resources' group of the given `project`
#
# @param [XcodeProj::Project] project
# The user project
#
# TODO: Probably move this elsewhere
#
def self.each_pods_resources(project)
return false unless block_given?
pods_group = project['Pods']
return false unless pods_group
resources_group = pods_group['Resources']
return false unless resources_group
# Remove each resource from every "Copy Bundle Resources" phases (as XcodeProj does not to it itself)
resources_files = resources_group.groups.flat_map(&:files)
native_targets.each do |user_target|
resources_files.each do |file_ref|
UI.puts " - Removing #{file_ref} from #{user_target} because it is no longer needed."
# FIXME: XcodeProj issue? The PBXBuildFile is replaced with (null) instead of being removed
user_target.resources_build_phase.remove_file_reference(file_ref)
end
resources_files.each do |file_ref|
yield file_ref
end
true
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment