Raise an error if user target `SWIFT_VERSION` is missing

parent f64b8171
...@@ -24,6 +24,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -24,6 +24,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes ##### Bug Fixes
* Raise an error if user target `SWIFT_VERSION` is missing
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#7770](https://github.com/CocoaPods/CocoaPods/issues/7770)
* Umbrella header import path gets wrong when `header_dir` is specified in PodSpec + try to build statically + Modular header is enabled * Umbrella header import path gets wrong when `header_dir` is specified in PodSpec + try to build statically + Modular header is enabled
[chuganzy](https://github.com/chuganzy) [chuganzy](https://github.com/chuganzy)
[#7724](https://github.com/CocoaPods/CocoaPods/pull/7724) [#7724](https://github.com/CocoaPods/CocoaPods/pull/7724)
......
...@@ -34,7 +34,7 @@ module Pod ...@@ -34,7 +34,7 @@ module Pod
def validate! def validate!
verify_no_duplicate_framework_and_library_names verify_no_duplicate_framework_and_library_names
verify_no_static_framework_transitive_dependencies verify_no_static_framework_transitive_dependencies
verify_no_pods_used_with_multiple_swift_versions verify_swift_pods_swift_version
verify_swift_pods_have_module_dependencies verify_swift_pods_have_module_dependencies
end end
...@@ -91,22 +91,28 @@ module Pod ...@@ -91,22 +91,28 @@ module Pod
end end
end end
def verify_no_pods_used_with_multiple_swift_versions def verify_swift_pods_swift_version
error_message_for_target = lambda do |target| error_message_for_target_definition = lambda do |target_definition|
"#{target.name} (Swift #{target.swift_version})" "`#{target_definition.name}` (Swift #{target_definition.swift_version})"
end end
swift_pod_targets = pod_targets.select(&:uses_swift?) swift_pod_targets = pod_targets.select(&:uses_swift?)
error_messages = swift_pod_targets.map do |pod_target| error_messages = swift_pod_targets.map do |pod_target|
next unless pod_target.spec_swift_version.nil? next unless pod_target.spec_swift_version.nil?
swift_target_definitions = pod_target.target_definitions.reject { |target| target.swift_version.blank? } 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 next if swift_target_definitions.uniq(&:swift_version).count == 1
target_errors = swift_target_definitions.map(&error_message_for_target).join(', ') if swift_target_definitions.empty?
"- #{pod_target.name} required by #{target_errors}" "- `#{pod_target.name}` does not specify a Swift version and none of the targets " \
"(#{pod_target.target_definitions.map { |td| "`#{td.name}`" }.to_sentence}) integrating it have the " \
'`SWIFT_VERSION` attribute set. Please contact the author or set the `SWIFT_VERSION` attribute in at ' \
'least one of the targets that integrate this pod.'
else
target_errors = swift_target_definitions.map(&error_message_for_target_definition).to_sentence
"- `#{pod_target.name}` is integrated by multiple targets that use a different Swift version: #{target_errors}."
end
end.compact end.compact
unless error_messages.empty? unless error_messages.empty?
raise Informative, 'The following pods are integrated into targets ' \ raise Informative, "Unable to determine Swift version for the following pods:\n\n #{error_messages.join('\n')}"
"that do not have the same Swift version:\n\n#{error_messages.join("\n")}"
end end
end end
......
...@@ -475,7 +475,8 @@ module Pod ...@@ -475,7 +475,8 @@ module Pod
def create_app_project def create_app_project
app_project = Xcodeproj::Project.new(validation_dir + 'App.xcodeproj') app_project = Xcodeproj::Project.new(validation_dir + 'App.xcodeproj')
Pod::Generator::AppTargetHelper.add_app_target(app_project, consumer.platform_name, deployment_target) app_target = Pod::Generator::AppTargetHelper.add_app_target(app_project, consumer.platform_name, deployment_target)
Pod::Generator::AppTargetHelper.add_swift_version(app_target, swift_version)
app_project.save app_project.save
app_project.recreate_user_schemes app_project.recreate_user_schemes
end end
...@@ -485,7 +486,6 @@ module Pod ...@@ -485,7 +486,6 @@ module Pod
app_target = app_project.targets.first app_target = app_project.targets.first
pod_target = @installer.pod_targets.find { |pt| pt.pod_name == spec.root.name } pod_target = @installer.pod_targets.find { |pt| pt.pod_name == spec.root.name }
Pod::Generator::AppTargetHelper.add_app_project_import(app_project, app_target, pod_target, consumer.platform_name, use_frameworks) Pod::Generator::AppTargetHelper.add_app_project_import(app_project, app_target, pod_target, consumer.platform_name, use_frameworks)
Pod::Generator::AppTargetHelper.add_swift_version(app_target, swift_version)
Pod::Generator::AppTargetHelper.add_xctest_search_paths(app_target) if @installer.pod_targets.any? { |pt| pt.spec_consumers.any? { |c| c.frameworks.include?('XCTest') } } Pod::Generator::AppTargetHelper.add_xctest_search_paths(app_target) if @installer.pod_targets.any? { |pt| pt.spec_consumers.any? { |c| c.frameworks.include?('XCTest') } }
app_project.save app_project.save
Xcodeproj::XCScheme.share_scheme(app_project.path, 'App') Xcodeproj::XCScheme.share_scheme(app_project.path, 'App')
......
Subproject commit 79d702f5c41e042672f0605437ce472b0d36a7a0 Subproject commit c3633bdbd40e8a75af860439c98c119bb60b9fa3
...@@ -139,6 +139,8 @@ module Pod ...@@ -139,6 +139,8 @@ module Pod
pod 'monkey', :path => (fixture_path + 'monkey').to_s pod 'monkey', :path => (fixture_path + 'monkey').to_s
target 'SampleProject' target 'SampleProject'
end end
@podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
@lockfile = generate_lockfile @lockfile = generate_lockfile
@file = Pathname('/yolo.m') @file = Pathname('/yolo.m')
...@@ -190,6 +192,8 @@ module Pod ...@@ -190,6 +192,8 @@ module Pod
pod 'monkey', :path => (fixture_path + 'monkey').to_s pod 'monkey', :path => (fixture_path + 'monkey').to_s
target 'SampleProject' target 'SampleProject'
end end
@podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
@lockfile = generate_lockfile @lockfile = generate_lockfile
@file = Pathname('/yolo.m') @file = Pathname('/yolo.m')
...@@ -259,7 +263,7 @@ module Pod ...@@ -259,7 +263,7 @@ module Pod
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
describe '#verify_no_pods_used_with_multiple_swift_versions' do describe '#verify_swift_pods_swift_version' do
it 'raises when targets integrate the same swift pod but have different swift versions' do it 'raises when targets integrate the same swift pod but have different swift versions' do
fixture_path = ROOT + 'spec/fixtures' fixture_path = ROOT + 'spec/fixtures'
config.repos_dir = fixture_path + 'spec-repos' config.repos_dir = fixture_path + 'spec-repos'
...@@ -283,9 +287,43 @@ module Pod ...@@ -283,9 +287,43 @@ module Pod
e = should.raise Informative do e = should.raise Informative do
@validator.validate! @validator.validate!
end end
e.message.should.match /The following pods are integrated into targets that do not have the same Swift version:/ e.message.should.match /Unable to determine Swift version for the following pods:/
e.message.should.include 'OrangeFramework required by SampleProject (Swift 3.0), TestRunner (Swift 2.3)' e.message.should.include '`OrangeFramework` is integrated by multiple targets that use a different Swift version: ' \
e.message.should.not.include 'matryoshka required by SampleProject (Swift 3.0), TestRunner (Swift 2.3)' '`SampleProject` (Swift 3.0) and `TestRunner` (Swift 2.3).'
e.message.should.not.include '`matryoshka` is integrated by multiple targets that use a different Swift version: ' \
'`SampleProject` (Swift 3.0) and `TestRunner` (Swift 2.3).'
end
it 'raises when swift pods integrated into targets that do not specify a swift version' 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(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']], :spec_swift_version => nil, :dependent_targets => [])
matryoshka_pod_target = stub(:name => 'matryoshka', :uses_swift? => true, :target_definitions => [podfile.target_definitions['SampleProject'], podfile.target_definitions['TestRunner']], :spec_swift_version => nil, :dependent_targets => [])
@validator = TargetValidator.new([], [orangeframework_pod_target, matryoshka_pod_target])
e = should.raise Informative do
@validator.validate!
end
e.message.should.match /Unable to determine Swift version for the following pods:/
e.message.should.include '`OrangeFramework` does not specify a Swift version and none of the targets ' \
'(`SampleProject` and `TestRunner`) integrating it have the `SWIFT_VERSION` attribute set. Please contact ' \
'the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.'
e.message.should.include '`matryoshka` does not specify a Swift version and none of the targets ' \
'(`SampleProject` and `TestRunner`) integrating it have the `SWIFT_VERSION` attribute set. Please contact ' \
'the author or set the `SWIFT_VERSION` attribute in at least one of the targets that integrate this pod.'
end end
it 'does not raise when targets integrate the same pod but only one of the targets is a swift target' do it 'does not raise when targets integrate the same pod but only one of the targets is a swift target' do
...@@ -358,7 +396,9 @@ module Pod ...@@ -358,7 +396,9 @@ module Pod
@validator = TargetValidator.new([], [orangeframework_pod_target, matryoshka_pod_target]) @validator = TargetValidator.new([], [orangeframework_pod_target, matryoshka_pod_target])
lambda { @validator.validate! }.should.not.raise lambda { @validator.validate! }.should.not.raise
end end
end
describe '#verify_swift_pods_have_module_dependencies' do
it 'raises when a swift target depends upon a target that does not define a module' do it 'raises when a swift target depends upon a target that does not define a module' do
fixture_path = ROOT + 'spec/fixtures' fixture_path = ROOT + 'spec/fixtures'
config.repos_dir = fixture_path + 'spec-repos' config.repos_dir = fixture_path + 'spec-repos'
...@@ -387,7 +427,7 @@ module Pod ...@@ -387,7 +427,7 @@ module Pod
EOS EOS
end end
it 'does not raise when a swift target depends upon a target thatis not built' do it 'does not raise when a swift target depends upon a target that is not built' do
fixture_path = ROOT + 'spec/fixtures' fixture_path = ROOT + 'spec/fixtures'
config.repos_dir = fixture_path + 'spec-repos' config.repos_dir = fixture_path + 'spec-repos'
podfile = Podfile.new do podfile = Podfile.new do
......
...@@ -278,6 +278,8 @@ module Pod ...@@ -278,6 +278,8 @@ module Pod
pod 'monkey', :path => (fixture_path + 'monkey').to_s pod 'monkey', :path => (fixture_path + 'monkey').to_s
end end
end end
podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
lockfile = generate_lockfile lockfile = generate_lockfile
@installer = Installer.new(config.sandbox, podfile, lockfile) @installer = Installer.new(config.sandbox, podfile, lockfile)
......
...@@ -914,7 +914,7 @@ module Pod ...@@ -914,7 +914,7 @@ module Pod
end end
end end
describe 'wihout a user provided swift version' do describe 'without a user provided swift version' do
it 'warns for Swift Pods' do it 'warns for Swift Pods' do
Specification.any_instance.stubs(:deployment_target).returns('9.0') Specification.any_instance.stubs(:deployment_target).returns('9.0')
......
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