Commit 345bc370 authored by Samuel E. Giddins's avatar Samuel E. Giddins

[TargetIntegrator] Refactor create or update of build phase logic

parent 725ec0b7
...@@ -142,19 +142,13 @@ module Pod ...@@ -142,19 +142,13 @@ module Pod
# @return [void] # @return [void]
# #
def add_embed_frameworks_script_phase def add_embed_frameworks_script_phase
phase_name = 'Embed Pods Frameworks'
targets_to_embed_in = native_targets_to_integrate.select do |target| targets_to_embed_in = native_targets_to_integrate.select do |target|
EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type) EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type)
end end
targets_to_embed_in.each do |native_target| targets_to_embed_in.each do |native_target|
embed_build_phase = native_target.shell_script_build_phases.find { |bp| bp.name == phase_name } phase = create_or_update_build_phase(native_target, 'Embed Pods Frameworks')
unless embed_build_phase.present?
UI.message("Adding Build Phase '#{phase_name}' to project.")
embed_build_phase = native_target.new_shell_script_build_phase(phase_name)
end
script_path = target.embed_frameworks_script_relative_path script_path = target.embed_frameworks_script_relative_path
embed_build_phase.shell_script = %("#{script_path}"\n) phase.shell_script = %("#{script_path}"\n)
embed_build_phase.show_env_vars_in_log = '0'
end end
end end
...@@ -189,11 +183,9 @@ module Pod ...@@ -189,11 +183,9 @@ module Pod
def add_copy_resources_script_phase def add_copy_resources_script_phase
phase_name = 'Copy Pods Resources' phase_name = 'Copy Pods Resources'
native_targets_to_integrate.each do |native_target| native_targets_to_integrate.each do |native_target|
phase = native_target.shell_script_build_phases.find { |bp| bp.name == phase_name } phase = create_or_update_build_phase(native_target, phase_name)
phase ||= native_target.new_shell_script_build_phase(phase_name)
script_path = target.copy_resources_script_relative_path script_path = target.copy_resources_script_relative_path
phase.shell_script = %("#{script_path}"\n) phase.shell_script = %("#{script_path}"\n)
phase.show_env_vars_in_log = '0'
end end
end end
...@@ -209,11 +201,8 @@ module Pod ...@@ -209,11 +201,8 @@ module Pod
def add_check_manifest_lock_script_phase def add_check_manifest_lock_script_phase
phase_name = 'Check Pods Manifest.lock' phase_name = 'Check Pods Manifest.lock'
native_targets_to_integrate.each do |native_target| native_targets_to_integrate.each do |native_target|
phase = native_target.shell_script_build_phases.find { |phase| phase.name == phase_name } phase = create_or_update_build_phase(native_target, phase_name)
phase ||= native_target.project.new(Xcodeproj::Project::Object::PBXShellScriptBuildPhase).tap do |phase| native_target.build_phases.unshift(phase).uniq!
native_target.build_phases.unshift(phase)
end
phase.name = phase_name
phase.shell_script = <<-EOS.strip_heredoc phase.shell_script = <<-EOS.strip_heredoc
diff "${PODS_ROOT}/../Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null diff "${PODS_ROOT}/../Podfile.lock" "${PODS_ROOT}/Manifest.lock" > /dev/null
if [[ $? != 0 ]] ; then if [[ $? != 0 ]] ; then
...@@ -223,7 +212,6 @@ module Pod ...@@ -223,7 +212,6 @@ module Pod
exit 1 exit 1
fi fi
EOS EOS
phase.show_env_vars_in_log = '0'
end end
end end
...@@ -279,6 +267,17 @@ module Pod ...@@ -279,6 +267,17 @@ module Pod
"Integrating target `#{target.name}` " \ "Integrating target `#{target.name}` " \
"(#{UI.path target.user_project_path} project)" "(#{UI.path target.user_project_path} project)"
end end
def create_or_update_build_phase(target, phase_name, phase_class = Xcodeproj::Project::Object::PBXShellScriptBuildPhase)
phase = target.build_phases.grep(phase_class).find { |phase| phase.name == phase_name } ||
(target.project.new(phase_class).tap do |phase|
UI.message("Adding Build Phase '#{phase_name}' to project.") do
phase.name = phase_name
phase.show_env_vars_in_log = '0'
target.build_phases << phase
end
end)
end
end end
end end
end 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