Commit 51575f5f authored by Danielle Tomlinson's avatar Danielle Tomlinson Committed by GitHub

Merge pull request #6733 from dnkoutso/swift_check_later

Only check for valid Swift version for pod targets that use Swift
parents 643f1a4e f97d247c
......@@ -18,6 +18,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes
* Only check for valid Swift version for pod targets that use Swift
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6733](https://github.com/CocoaPods/CocoaPods/pull/6733)
* Fix pod install error from 1.2.1 when working with static lib-only projects.
[Ben Asher](https://github.com/benasher44)
[#6673](https://github.com/CocoaPods/CocoaPods/issues/6673)
......
......@@ -367,7 +367,6 @@ module Pod
#
def generate_targets
specs_by_target = result.specs_by_target.reject { |td, _| td.abstract? }
check_pod_target_swift_versions(specs_by_target)
pod_targets = generate_pod_targets(specs_by_target)
aggregate_targets = specs_by_target.keys.map do |target_definition|
generate_target(target_definition, pod_targets)
......@@ -435,39 +434,6 @@ module Pod
target
end
# Verify that targets using a pod have the same swift version
#
# @param [Hash{Podfile::TargetDefinition => Array<Specification>}] specs_by_target
# the resolved specifications grouped by target.
#
# @note raises Informative if targets using a pod do not have
# the same swift version
#
def check_pod_target_swift_versions(specs_by_target)
targets_by_spec = {}
specs_by_target.each do |target, specs|
specs.each do |spec|
(targets_by_spec[spec] ||= []) << target
end
end
error_message_for_target = lambda do |target|
"#{target.name} (Swift #{target.swift_version})"
end
error_messages = targets_by_spec.map do |spec, targets|
swift_targets = targets.reject { |target| target.swift_version.blank? }
next if swift_targets.empty? || swift_targets.uniq(&:swift_version).count == 1
target_errors = swift_targets.map(&error_message_for_target).join(', ')
"- #{spec.name} required by #{target_errors}"
end.compact
unless error_messages.empty?
raise Informative, 'The following pods are integrated into targets ' \
"that do not have the same Swift version:\n\n#{error_messages.join("\n")}"
end
end
# Setup the pod targets for an aggregate target. Deduplicates resulting
# targets by grouping by platform and subspec by their root
# to create a {PodTarget} for each spec.
......
......@@ -34,6 +34,7 @@ module Pod
def validate!
verify_no_duplicate_framework_and_library_names
verify_no_static_framework_transitive_dependencies
verify_no_pods_used_with_multiple_swift_versions
verify_framework_usage
end
......@@ -84,6 +85,24 @@ module Pod
end
end
def verify_no_pods_used_with_multiple_swift_versions
error_message_for_target = lambda do |target|
"#{target.name} (Swift #{target.swift_version})"
end
swift_pod_targets = pod_targets.select(&:uses_swift?)
error_messages = swift_pod_targets.map do |pod_target|
swift_target_definitions = pod_target.target_definitions.reject { |target| target.swift_version.blank? }
next if swift_target_definitions.empty? || swift_target_definitions.uniq(&:swift_version).count == 1
target_errors = swift_target_definitions.map(&error_message_for_target).join(', ')
"- #{pod_target.name} required by #{target_errors}"
end.compact
unless error_messages.empty?
raise Informative, 'The following pods are integrated into targets ' \
"that do not have the same Swift version:\n\n#{error_messages.join("\n")}"
end
end
def verify_framework_usage
aggregate_targets.each do |aggregate_target|
next if aggregate_target.requires_frameworks?
......
......@@ -662,40 +662,6 @@ module Pod
should.raise(Informative) { analyzer.analyze }
end
it 'raises when targets integrate the same swift pod but have different swift versions' do
podfile = Podfile.new do
source SpecHelper.test_repo_url
project 'SampleProject/SampleProject'
platform :ios, '8.0'
pod 'OrangeFramework'
target 'SampleProject'
target 'TestRunner'
end
podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
podfile.target_definitions['TestRunner'].stubs(:swift_version).returns('2.3')
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
should.raise Informative do
analyzer.analyze
end.message.should.match /The following pods are integrated into targets that do not have the same Swift version:/
end
it 'does not raise when targets integrate the same pod but only one of the targets is a swift target' do
podfile = Podfile.new do
source SpecHelper.test_repo_url
project 'SampleProject/SampleProject'
platform :ios, '8.0'
pod 'OrangeFramework'
target 'SampleProject'
target 'TestRunner'
end
podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
# when the swift version is unset at the project level, but set in one target, swift_version is nil
podfile.target_definitions['TestRunner'].stubs(:swift_version).returns(nil)
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
lambda { analyzer.analyze }.should.not.raise
end
#--------------------------------------#
it 'computes the state of the Sandbox respect to the resolved dependencies' do
......
......@@ -143,6 +143,86 @@ module Pod
#-------------------------------------------------------------------------#
describe '#verify_no_pods_used_with_multiple_swift_versions' do
it 'raises when targets integrate the same swift pod but have different swift versions' do
fixture_path = ROOT + 'spec/fixtures'
config.repos_dir = fixture_path + 'spec-repos'
podfile = Podfile.new do
project 'SampleProject/SampleProject'
platform :ios, '8.0'
use_frameworks!
pod 'OrangeFramework', :path => (fixture_path + 'orange-framework').to_s
pod 'matryoshka', :path => (fixture_path + 'matryoshka').to_s
target 'SampleProject'
target 'TestRunner'
end
podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
podfile.target_definitions['TestRunner'].stubs(:swift_version).returns('2.3')
orangeframework_pod_target = stub(:name => 'OrangeFramework', :uses_swift? => true, :target_definitions => [podfile.target_definitions['SampleProject'], podfile.target_definitions['TestRunner']])
matryoshka_pod_target = stub(:name => 'matryoshka', :uses_swift? => false, :target_definitions => [podfile.target_definitions['SampleProject'], podfile.target_definitions['TestRunner']])
@validator = TargetValidator.new([], [orangeframework_pod_target, matryoshka_pod_target])
e = should.raise Informative do
@validator.validate!
end
e.message.should.match /The following pods are integrated into targets that do not have the same Swift version:/
e.message.should.include 'OrangeFramework required by SampleProject (Swift 3.0), TestRunner (Swift 2.3)'
e.message.should.not.include 'matryoshka required by SampleProject (Swift 3.0), TestRunner (Swift 2.3)'
end
it 'does not raise when targets integrate the same pod but only one of the targets is a swift target' do
fixture_path = ROOT + 'spec/fixtures'
config.repos_dir = fixture_path + 'spec-repos'
podfile = Podfile.new do
project 'SampleProject/SampleProject'
use_frameworks!
platform :ios, '8.0'
pod 'OrangeFramework', :path => (fixture_path + 'orange-framework').to_s
pod 'matryoshka', :path => (fixture_path + 'matryoshka').to_s
target 'SampleProject'
target 'TestRunner'
end
podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
# when the swift version is unset at the project level, but set in one target, swift_version is nil
podfile.target_definitions['TestRunner'].stubs(:swift_version).returns(nil)
orangeframework_pod_target = stub(:name => 'OrangeFramework', :uses_swift? => true, :target_definitions => [podfile.target_definitions['SampleProject'], podfile.target_definitions['TestRunner']])
matryoshka_pod_target = stub(:name => 'matryoshka', :uses_swift? => true, :target_definitions => [podfile.target_definitions['SampleProject'], podfile.target_definitions['TestRunner']])
@validator = TargetValidator.new([], [orangeframework_pod_target, matryoshka_pod_target])
lambda { @validator.validate! }.should.not.raise
end
it 'does not raise when targets integrate the same pod but none of the pod targets use swift' do
fixture_path = ROOT + 'spec/fixtures'
config.repos_dir = fixture_path + 'spec-repos'
podfile = Podfile.new do
project 'SampleProject/SampleProject'
use_frameworks!
platform :ios, '8.0'
pod 'OrangeFramework', :path => (fixture_path + 'orange-framework').to_s
pod 'matryoshka', :path => (fixture_path + 'matryoshka').to_s
target 'SampleProject'
target 'TestRunner'
end
podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
podfile.target_definitions['TestRunner'].stubs(:swift_version).returns('2.3')
# Pretend none of the pod targets use swift, even if the target definitions they are linked with do have different Swift versions.
orangeframework_pod_target = stub(:name => 'OrangeFramework', :uses_swift? => false, :target_definitions => [podfile.target_definitions['SampleProject'], podfile.target_definitions['TestRunner']])
matryoshka_pod_target = stub(:name => 'matryoshka', :uses_swift? => false, :target_definitions => [podfile.target_definitions['SampleProject'], podfile.target_definitions['TestRunner']])
@validator = TargetValidator.new([], [orangeframework_pod_target, matryoshka_pod_target])
lambda { @validator.validate! }.should.not.raise
end
end
#-------------------------------------------------------------------------#
describe '#verify_framework_usage' do
it 'raises when Swift pods are used without explicit `use_frameworks!`' do
fixture_path = ROOT + 'spec/fixtures'
......
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