Commit eae31ef2 authored by Samuel Giddins's avatar Samuel Giddins Committed by GitHub

Merge pull request #5747 from benasher44/basher_fix_pod_target_uniq

Verify embedded target platform/swift matches its host
parents 49b4b5af e4c28fdc
......@@ -11,7 +11,7 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
* Remove references to the pre-1.0 Migrator.
[Danielle Tomlinson](https://github.com/dantoml)
[#5635](https://github.com/CocoaPods/CocoaPods/pull/5635)
* Improve performance of dependency resolution.
[yanzhiwei147](https://github.com/yanzhiwei147)
[#5510](https://github.com/CocoaPods/CocoaPods/pull/5510)
......@@ -24,10 +24,15 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
Improved support for framework-only projects.
[benasher44](https://github.com/benasher44)
[#5733](https://github.com/CocoaPods/CocoaPods/pull/5733)
* Set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES when appropriate.
[benasher44](https://github.com/benasher44)
[#5732](https://github.com/CocoaPods/CocoaPods/pull/5732)
* Verify that embedded target platform and swift version matches the host.
[benasher44](https://github.com/benasher44)
[#5747](https://github.com/CocoaPods/CocoaPods/pull/5747)
##### Bug Fixes
* Hash scope suffixes if they are over 50 characters to prevent file paths from being too long.
......
......@@ -247,7 +247,6 @@ module Pod
next unless embedded_target.user_targets.map(&:uuid).any? do |embedded_uuid|
embedded_uuids.include? embedded_uuid
end
raise Informative, "#{aggregate_target.name} must call use_frameworks! because it is hosting an embedded target that calls use_frameworks!." unless aggregate_target.requires_frameworks?
pod_target_names = aggregate_target.pod_targets.map(&:name)
# This embedded target is hosted by the aggregate target's user_target; copy over the non-duplicate pod_targets
aggregate_target.pod_targets = aggregate_target.pod_targets + embedded_target.pod_targets.select do |pod_target|
......@@ -267,9 +266,15 @@ module Pod
# representing the embedded targets to be integrated
#
def analyze_host_targets_in_podfile(aggregate_targets, embedded_aggregate_targets)
aggregate_target_uuids = Set.new aggregate_targets.map(&:user_targets).flatten.map(&:uuid)
target_definitions_by_uuid = {}
aggregate_targets.each do |target|
target.user_targets.map(&:uuid).each do |uuid|
target_definitions_by_uuid[uuid] = target.target_definition
end
end
aggregate_target_user_projects = aggregate_targets.map(&:user_project)
embedded_targets_missing_hosts = []
host_uuid_to_embedded_target_definitions = {}
embedded_aggregate_targets.each do |target|
host_uuids = []
aggregate_target_user_projects.product(target.user_targets).each do |user_project, user_target|
......@@ -279,10 +284,14 @@ module Pod
end
host_uuids += host_targets.map(&:uuid)
end
host_uuids.each do |uuid|
(host_uuid_to_embedded_target_definitions[uuid] ||= []) << target.target_definition
end
embedded_targets_missing_hosts << target unless host_uuids.any? do |uuid|
aggregate_target_uuids.include? uuid
target_definitions_by_uuid.key? uuid
end
end
unless embedded_targets_missing_hosts.empty?
embedded_targets_missing_hosts_product_types = embedded_targets_missing_hosts.map(&:user_targets).flatten.map(&:symbol_type).uniq
# If the targets missing hosts are only frameworks, then this is likely
......@@ -305,6 +314,28 @@ module Pod
"\n- Messages Extension (except when used with a Messages Application)"
end
end
target_mismatches = []
check_prop = lambda do |target_definition1, target_definition2, attr, msg|
attr1 = target_definition1.send(attr)
attr2 = target_definition2.send(attr)
if attr1 != attr2
target_mismatches << "- #{target_definition1.name} (#{attr1}) and #{target_definition2.name} (#{attr2}) #{msg}."
end
end
host_uuid_to_embedded_target_definitions.each do |uuid, target_definitions|
host_target_definition = target_definitions_by_uuid[uuid]
target_definitions.each do |target_definition|
check_prop.call(host_target_definition, target_definition, :platform, 'do not use the same platform')
check_prop.call(host_target_definition, target_definition, :uses_frameworks?, 'do not both set use_frameworks!')
check_prop.call(host_target_definition, target_definition, :swift_version, 'do not use the same Swift version')
end
end
unless target_mismatches.empty?
heading = 'Unable to integrate the following embedded targets with their respective host targets (a host target is a "parent" target which embeds a "child" target like a framework or extension):'
raise Informative, heading + "\n\n" + target_mismatches.sort.uniq.join("\n")
end
end
# Creates the models that represent the targets generated by CocoaPods.
......
......@@ -783,7 +783,52 @@ module Pod
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
should.raise Informative do
analyzer.analyze
end.message.should.match /Pods-Sample Extensions Project must call use_frameworks! because it is hosting an embedded target that calls use_frameworks!/
end.message.should.match /Sample Extensions Project \(false\) and Today Extension \(true\) do not both set use_frameworks!\./
end
it 'raises when the extension and host target use different swift versions' do
podfile = Pod::Podfile.new do
source SpecHelper.test_repo_url
platform :ios, '8.0'
use_frameworks!
project 'Sample Extensions Project/Sample Extensions Project'
target 'Sample Extensions Project' do
pod 'JSONKit', '1.4'
end
target 'Today Extension' do
pod 'monkey'
end
end
podfile.target_definitions['Sample Extensions Project'].stubs(:swift_version).returns('2.3')
podfile.target_definitions['Today Extension'].stubs(:swift_version).returns('3.0')
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
should.raise Informative do
analyzer.analyze
end.message.should.match /Sample Extensions Project \(2\.3\) and Today Extension \(3\.0\) do not use the same Swift version\./
end
it 'raises when the extension and host target use different platforms' do
podfile = Pod::Podfile.new do
source SpecHelper.test_repo_url
platform :ios, '8.0'
use_frameworks!
project 'Sample Extensions Project/Sample Extensions Project'
target 'Sample Extensions Project' do
pod 'JSONKit', '1.4'
end
target 'Today Extension' do
pod 'monkey'
end
end
podfile.target_definitions['Sample Extensions Project'].stubs(:platform).returns(Platform.new(:osx, '10.6'))
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
should.raise Informative do
analyzer.analyze
end.message.should.match /Sample Extensions Project \(OS X 10\.6\) and Today Extension \(iOS 8\.0\) do not use the same platform\./
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