Skip to content

Commit

Permalink
Merge pull request #4028 from CocoaPods/mr-target-integrator-migration
Browse files Browse the repository at this point in the history
[TargetIntegrator] Remove embed frameworks build phase where not needed
  • Loading branch information
segiddins committed Aug 16, 2015
2 parents b8f6bd8 + 9794fea commit 22ff251
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -46,6 +46,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[#3190](https://github.com/CocoaPods/CocoaPods/issues/3190)
[#3792](https://github.com/CocoaPods/CocoaPods/pull/3792)

* Remove embed frameworks build phase from target types, where it is not required.
[Marius Rackwitz](https://github.com/mrackwitz)
[#3905](https://github.com/CocoaPods/CocoaPods/issues/3905)
[#4028](https://github.com/CocoaPods/CocoaPods/pull/4028)


## 0.38.2

Expand Down
Expand Up @@ -14,6 +14,10 @@ class TargetIntegrator
#
EMBED_FRAMEWORK_TARGET_TYPES = [:application, :unit_test_bundle].freeze

# @return [String] the name of the embed frameworks phase
#
EMBED_FRAMEWORK_PHASE_NAME = 'Embed Pods Frameworks'.freeze

# @return [AggregateTarget] the target that should be integrated.
#
attr_reader :target
Expand All @@ -38,6 +42,7 @@ def integrate!
project_is_dirty = [
XCConfigIntegrator.integrate(target, native_targets),
update_to_cocoapods_0_34,
update_to_cocoapods_0_37_1,
remove_embed_frameworks_script_phases,
unless native_targets_to_integrate.empty?
add_pods_library
Expand Down Expand Up @@ -100,6 +105,18 @@ def update_to_cocoapods_0_34
changes
end

# Removes the embed frameworks phase for target types.
#
# @return [Bool] whether any changes to the project were made.
#
# @todo This can be removed for CocoaPods 1.0
#
def update_to_cocoapods_0_37_1
(native_targets - native_targets_to_embed_in).any? do |native_target|
remove_embed_frameworks_script_phase(native_target)
end
end

# Adds spec product reference to the frameworks build phase of the
# {TargetDefinition} integration libraries. Adds a file reference to
# the frameworks group of the project and adds it to the frameworks
Expand Down Expand Up @@ -142,11 +159,8 @@ def add_pods_library
# @return [void]
#
def add_embed_frameworks_script_phase
targets_to_embed_in = native_targets_to_integrate.select do |target|
EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type)
end
targets_to_embed_in.each do |native_target|
phase = create_or_update_build_phase(native_target, 'Embed Pods Frameworks')
native_targets_to_embed_in.each do |native_target|
phase = create_or_update_build_phase(native_target, EMBED_FRAMEWORK_PHASE_NAME)
script_path = target.embed_frameworks_script_relative_path
phase.shell_script = %("#{script_path}"\n)
end
Expand All @@ -160,18 +174,22 @@ def add_embed_frameworks_script_phase
#
def remove_embed_frameworks_script_phases
return false if target.requires_frameworks?

phase_name = 'Embed Pods Frameworks'
result = false

native_targets.each do |native_target|
embed_build_phase = native_target.shell_script_build_phases.find { |bp| bp.name == phase_name }
next unless embed_build_phase.present?
native_target.build_phases.delete(embed_build_phase)
result = true
native_targets.any? do |native_target|
remove_embed_frameworks_script_phase(native_target)
end
end

result
# Delete a 'Embed Pods Frameworks' Copy Files Build Phase if present
#
# @param [PBXNativeTarget] native_target
#
# @return [Bool] whether any changes to the project were made.
#
def remove_embed_frameworks_script_phase(native_target)
embed_build_phase = native_target.shell_script_build_phases.find { |bp| bp.name == EMBED_FRAMEWORK_PHASE_NAME }
return false unless embed_build_phase.present?
native_target.build_phases.delete(embed_build_phase)
true
end

# Adds a shell script build phase responsible to copy the resources
Expand Down Expand Up @@ -227,6 +245,16 @@ def native_targets
@native_targets ||= target.user_targets(user_project)
end

# @return [Array<PBXNativeTarget>] The list of all the targets that
# require that the pod frameworks are embedded in the output
# directory / product bundle.
#
def native_targets_to_embed_in
native_targets_to_integrate.select do |target|
EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type)
end
end

# @return [Array<PBXNativeTarget>] The list of the targets
# that have not been integrated by past installations
# of
Expand Down

0 comments on commit 22ff251

Please sign in to comment.