Commit 8e4d8157 authored by Samuel Giddins's avatar Samuel Giddins Committed by GitHub

Merge pull request #5726 from benasher44/basher_messages_application

Added support for message extensions embedded in messages applications
parents 0fec0e09 91fadc6d
...@@ -16,6 +16,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -16,6 +16,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[yanzhiwei147](https://github.com/yanzhiwei147) [yanzhiwei147](https://github.com/yanzhiwei147)
[#5510](https://github.com/CocoaPods/CocoaPods/pull/5510) [#5510](https://github.com/CocoaPods/CocoaPods/pull/5510)
* Add support for messages applications.
[benasher44](https://github.com/benasher44)
[#5726](https://github.com/CocoaPods/CocoaPods/pull/5726)
##### Bug Fixes ##### Bug Fixes
* Hash scope suffixes if they are over 50 characters to prevent file paths from being too long. * Hash scope suffixes if they are over 50 characters to prevent file paths from being too long.
......
...@@ -257,7 +257,8 @@ module Pod ...@@ -257,7 +257,8 @@ module Pod
end end
# Raises an error if there are embedded targets in the Podfile, but # Raises an error if there are embedded targets in the Podfile, but
# their host targets have not been declared in the Podfile # their host targets have not been declared in the Podfile. As it
# finds host targets, it collection information on host target types.
# #
# @param [Array<AggregateTarget>] aggregate_targets the generated # @param [Array<AggregateTarget>] aggregate_targets the generated
# aggregate targets # aggregate targets
...@@ -265,14 +266,19 @@ module Pod ...@@ -265,14 +266,19 @@ module Pod
# @param [Array<AggregateTarget>] embedded_aggregate_targets the aggregate targets # @param [Array<AggregateTarget>] embedded_aggregate_targets the aggregate targets
# representing the embedded targets to be integrated # representing the embedded targets to be integrated
# #
def verify_host_targets_in_podfile(aggregate_targets, embedded_aggregate_targets) def analyze_host_targets_in_podfile(aggregate_targets, embedded_aggregate_targets)
aggregate_target_uuids = Set.new aggregate_targets.map(&:user_targets).flatten.map(&:uuid) aggregate_target_uuids = Set.new aggregate_targets.map(&:user_targets).flatten.map(&:uuid)
aggregate_target_user_projects = aggregate_targets.map(&:user_project) aggregate_target_user_projects = aggregate_targets.map(&:user_project)
embedded_targets_missing_hosts = [] embedded_targets_missing_hosts = []
embedded_aggregate_targets.each do |target| embedded_aggregate_targets.each do |target|
host_uuids = aggregate_target_user_projects.product(target.user_targets).map do |user_project, user_target| host_uuids = []
user_project.host_targets_for_embedded_target(user_target).map(&:uuid) aggregate_target_user_projects.product(target.user_targets).each do |user_project, user_target|
end.flatten host_targets = user_project.host_targets_for_embedded_target(user_target)
host_targets.map(&:symbol_type).each do |product_type|
target.add_host_target_product_type(product_type)
end
host_uuids += host_targets.map(&:uuid)
end
embedded_targets_missing_hosts << target unless host_uuids.any? do |uuid| embedded_targets_missing_hosts << target unless host_uuids.any? do |uuid|
aggregate_target_uuids.include? uuid aggregate_target_uuids.include? uuid
end end
...@@ -295,7 +301,7 @@ module Pod ...@@ -295,7 +301,7 @@ module Pod
if installation_options.integrate_targets? if installation_options.integrate_targets?
# Copy embedded target pods that cannot have their pods embedded as frameworks to their host targets # Copy embedded target pods that cannot have their pods embedded as frameworks to their host targets
embedded_targets = aggregate_targets.select(&:requires_host_target?).select(&:requires_frameworks?) embedded_targets = aggregate_targets.select(&:requires_host_target?).select(&:requires_frameworks?)
verify_host_targets_in_podfile(aggregate_targets, embedded_targets) analyze_host_targets_in_podfile(aggregate_targets, embedded_targets)
aggregate_targets.each do |target| aggregate_targets.each do |target|
copy_embedded_target_pod_targets_to_host(target, embedded_targets) copy_embedded_target_pod_targets_to_host(target, embedded_targets)
end end
......
...@@ -21,9 +21,11 @@ module Pod ...@@ -21,9 +21,11 @@ module Pod
# frameworks are embedded in the output directory / product bundle. # frameworks are embedded in the output directory / product bundle.
# #
# @note This does not include :app_extension or :watch_extension because # @note This does not include :app_extension or :watch_extension because
# these types must have their frameworks embedded in their host targets # these types must have their frameworks embedded in their host targets.
# For messages extensions, this only applies if it's embedded in a messages
# application.
# #
EMBED_FRAMEWORK_TARGET_TYPES = [:application, :unit_test_bundle, :ui_test_bundle, :watch2_extension].freeze EMBED_FRAMEWORK_TARGET_TYPES = [:application, :unit_test_bundle, :ui_test_bundle, :watch2_extension, :messages_extension].freeze
# @return [String] the name of the embed frameworks phase # @return [String] the name of the embed frameworks phase
# #
...@@ -121,6 +123,7 @@ module Pod ...@@ -121,6 +123,7 @@ module Pod
# will have their frameworks embedded in their host targets. # will have their frameworks embedded in their host targets.
# #
def remove_embed_frameworks_script_phase_from_embedded_targets def remove_embed_frameworks_script_phase_from_embedded_targets
return unless target.requires_host_target?
native_targets.each do |native_target| native_targets.each do |native_target|
if AggregateTarget::EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES.include? native_target.symbol_type if AggregateTarget::EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES.include? native_target.symbol_type
remove_embed_frameworks_script_phase(native_target) remove_embed_frameworks_script_phase(native_target)
...@@ -201,6 +204,7 @@ module Pod ...@@ -201,6 +204,7 @@ module Pod
# directory / product bundle. # directory / product bundle.
# #
def native_targets_to_embed_in def native_targets_to_embed_in
return [] if target.requires_host_target?
native_targets.select do |target| native_targets.select do |target|
EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type) EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type)
end end
......
...@@ -8,6 +8,9 @@ module Pod ...@@ -8,6 +8,9 @@ module Pod
attr_reader :target_definition attr_reader :target_definition
# Product types where the product's frameworks must be embedded in a host target # Product types where the product's frameworks must be embedded in a host target
#
# @note :messages_extension only applies when it is embedded in an app (as opposed to a messages app)
#
EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES = [:app_extension, :framework, :messages_extension, :watch_extension].freeze EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES = [:app_extension, :framework, :messages_extension, :watch_extension].freeze
# Initialize a new instance # Initialize a new instance
...@@ -24,6 +27,21 @@ module Pod ...@@ -24,6 +27,21 @@ module Pod
@search_paths_aggregate_targets = [] @search_paths_aggregate_targets = []
@file_accessors = [] @file_accessors = []
@xcconfigs = {} @xcconfigs = {}
@host_target_types = Set.new # Product types of the host target, if this target is embedded
end
# Adds product type to the list of product types for the host
# targets, in which this target will be embedded
#
# @param [Symbol] product_type Product type (symbol representation)
# of a host, in which this target will be embedded
#
# @note This is important for messages extensions, since a messages
# extension has its frameworks embedded in its host when
# its host is an app but not when it's a messages app
#
def add_host_target_product_type(product_type)
@host_target_types << product_type
end end
# @return [Boolean] True if the user_target's pods are # @return [Boolean] True if the user_target's pods are
...@@ -39,7 +57,7 @@ module Pod ...@@ -39,7 +57,7 @@ module Pod
return false if user_project.nil? return false if user_project.nil?
symbol_types = user_targets.map(&:symbol_type).uniq symbol_types = user_targets.map(&:symbol_type).uniq
raise ArgumentError, "Expected single kind of user_target for #{name}. Found #{symbol_types.join(', ')}." unless symbol_types.count == 1 raise ArgumentError, "Expected single kind of user_target for #{name}. Found #{symbol_types.join(', ')}." unless symbol_types.count == 1
EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES.include? symbol_types[0] EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES.include?(symbol_types[0]) && !@host_target_types.include?(:messages_application)
end end
# @return [String] the label for the target. # @return [String] the label for the target.
......
...@@ -173,6 +173,25 @@ module Pod ...@@ -173,6 +173,25 @@ module Pod
phase.nil?.should == false phase.nil?.should == false
end end
it 'does not add an embed frameworks build phase if the target to integrate is a messages extension for an iOS app' do
@pod_bundle.stubs(:requires_frameworks? => true)
target = @target_integrator.send(:native_targets).first
target.stubs(:symbol_type).returns(:messages_extension)
@target_integrator.integrate!
phase = target.shell_script_build_phases.find { |bp| bp.name == @embed_framework_phase_name }
phase.nil?.should == true
end
it 'adds an embed frameworks build phase if the target to integrate is a messages extension for a messages application' do
@pod_bundle.stubs(:requires_frameworks? => true)
@pod_bundle.stubs(:requires_host_target? => false) # Messages extensions for messages applications do not require a host target
target = @target_integrator.send(:native_targets).first
target.stubs(:symbol_type).returns(:messages_extension)
@target_integrator.integrate!
phase = target.shell_script_build_phases.find { |bp| bp.name == @embed_framework_phase_name }
phase.nil?.should == false
end
it 'adds an embed frameworks build phase if the target to integrate is a UI Test bundle' do it 'adds an embed frameworks build phase if the target to integrate is a UI Test bundle' do
@pod_bundle.stubs(:requires_frameworks? => true) @pod_bundle.stubs(:requires_frameworks? => true)
target = @target_integrator.send(:native_targets).first target = @target_integrator.send(:native_targets).first
...@@ -226,6 +245,31 @@ module Pod ...@@ -226,6 +245,31 @@ module Pod
phase.nil?.should == true phase.nil?.should == true
end end
it 'removes embed frameworks build phases from messages extension targets that are used in an iOS app' do
@pod_bundle.stubs(:requires_frameworks? => true)
@target_integrator.integrate!
target = @target_integrator.send(:native_targets).first
phase = target.shell_script_build_phases.find { |bp| bp.name == @embed_framework_phase_name }
phase.nil?.should == false
target.stubs(:symbol_type).returns(:messages_extension)
@target_integrator.integrate!
phase = target.shell_script_build_phases.find { |bp| bp.name == @embed_framework_phase_name }
phase.nil?.should == true
end
it 'does not remove embed frameworks build phases from messages extension targets that are used in a messages app' do
@pod_bundle.stubs(:requires_frameworks? => true)
@target_integrator.integrate!
target = @target_integrator.send(:native_targets).first
phase = target.shell_script_build_phases.find { |bp| bp.name == @embed_framework_phase_name }
phase.nil?.should == false
target.stubs(:symbol_type).returns(:messages_extension)
@pod_bundle.stubs(:requires_host_target? => false) # Messages extensions for messages applications do not require a host target
@target_integrator.integrate!
phase = target.shell_script_build_phases.find { |bp| bp.name == @embed_framework_phase_name }
phase.nil?.should == false
end
it 'removes embed frameworks build phases from framework targets' do it 'removes embed frameworks build phases from framework targets' do
@pod_bundle.stubs(:requires_frameworks? => true) @pod_bundle.stubs(:requires_frameworks? => true)
@target_integrator.integrate! @target_integrator.integrate!
......
...@@ -224,6 +224,12 @@ module Pod ...@@ -224,6 +224,12 @@ module Pod
@target.requires_host_target?.should == true @target.requires_host_target?.should == true
end end
it 'does not require a host target for messages extension targets embedded in messages applications' do
@target.add_host_target_product_type(:messages_application)
@target.user_targets.first.stubs(:symbol_type).returns(:messages_extension)
@target.requires_host_target?.should == false
end
it 'does not require a host target for watch 2 extension targets' do it 'does not require a host target for watch 2 extension targets' do
@target.user_targets.first.stubs(:symbol_type).returns(:watch2_extension) @target.user_targets.first.stubs(:symbol_type).returns(:watch2_extension)
@target.requires_host_target?.should == false @target.requires_host_target?.should == false
......
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