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`
[yanzhiwei147](https://github.com/yanzhiwei147)
[#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
* Hash scope suffixes if they are over 50 characters to prevent file paths from being too long.
......
......@@ -257,7 +257,8 @@ module Pod
end
# 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
# aggregate targets
......@@ -265,14 +266,19 @@ module Pod
# @param [Array<AggregateTarget>] embedded_aggregate_targets the aggregate targets
# 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_user_projects = aggregate_targets.map(&:user_project)
embedded_targets_missing_hosts = []
embedded_aggregate_targets.each do |target|
host_uuids = aggregate_target_user_projects.product(target.user_targets).map do |user_project, user_target|
user_project.host_targets_for_embedded_target(user_target).map(&:uuid)
end.flatten
host_uuids = []
aggregate_target_user_projects.product(target.user_targets).each do |user_project, user_target|
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|
aggregate_target_uuids.include? uuid
end
......@@ -295,7 +301,7 @@ module Pod
if installation_options.integrate_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?)
verify_host_targets_in_podfile(aggregate_targets, embedded_targets)
analyze_host_targets_in_podfile(aggregate_targets, embedded_targets)
aggregate_targets.each do |target|
copy_embedded_target_pod_targets_to_host(target, embedded_targets)
end
......
......@@ -21,9 +21,11 @@ module Pod
# frameworks are embedded in the output directory / product bundle.
#
# @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
#
......@@ -121,6 +123,7 @@ module Pod
# will have their frameworks embedded in their host targets.
#
def remove_embed_frameworks_script_phase_from_embedded_targets
return unless target.requires_host_target?
native_targets.each do |native_target|
if AggregateTarget::EMBED_FRAMEWORKS_IN_HOST_TARGET_TYPES.include? native_target.symbol_type
remove_embed_frameworks_script_phase(native_target)
......@@ -201,6 +204,7 @@ module Pod
# directory / product bundle.
#
def native_targets_to_embed_in
return [] if target.requires_host_target?
native_targets.select do |target|
EMBED_FRAMEWORK_TARGET_TYPES.include?(target.symbol_type)
end
......
......@@ -8,6 +8,9 @@ module Pod
attr_reader :target_definition
# 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
# Initialize a new instance
......@@ -24,6 +27,21 @@ module Pod
@search_paths_aggregate_targets = []
@file_accessors = []
@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
# @return [Boolean] True if the user_target's pods are
......@@ -39,7 +57,7 @@ module Pod
return false if user_project.nil?
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
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
# @return [String] the label for the target.
......
......@@ -173,6 +173,25 @@ module Pod
phase.nil?.should == false
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
@pod_bundle.stubs(:requires_frameworks? => true)
target = @target_integrator.send(:native_targets).first
......@@ -226,6 +245,31 @@ module Pod
phase.nil?.should == true
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
@pod_bundle.stubs(:requires_frameworks? => true)
@target_integrator.integrate!
......
......@@ -224,6 +224,12 @@ module Pod
@target.requires_host_target?.should == true
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
@target.user_targets.first.stubs(:symbol_type).returns(:watch2_extension)
@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