Unverified Commit d0318657 authored by D. Koutsogiorgas's avatar D. Koutsogiorgas Committed by GitHub

Merge pull request #7777 from dnkoutso/swift_version_empty_message

Raise an error if user target `SWIFT_VERSION` is missing
parents f64b8171 caba66ef
......@@ -24,6 +24,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### 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
[chuganzy](https://github.com/chuganzy)
[#7724](https://github.com/CocoaPods/CocoaPods/pull/7724)
......
......@@ -34,7 +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_swift_pods_swift_version
verify_swift_pods_have_module_dependencies
end
......@@ -91,22 +91,28 @@ 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})"
def verify_swift_pods_swift_version
error_message_for_target_definition = lambda do |target_definition|
"`#{target_definition.name}` (Swift #{target_definition.swift_version})"
end
swift_pod_targets = pod_targets.select(&:uses_swift?)
error_messages = swift_pod_targets.map do |pod_target|
next unless pod_target.spec_swift_version.nil?
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}"
next if swift_target_definitions.uniq(&:swift_version).count == 1
if swift_target_definitions.empty?
"- `#{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
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")}"
raise Informative, "Unable to determine Swift version for the following pods:\n\n #{error_messages.join('\n')}"
end
end
......
......@@ -475,7 +475,8 @@ module Pod
def create_app_project
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.recreate_user_schemes
end
......@@ -485,7 +486,6 @@ module Pod
app_target = app_project.targets.first
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_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') } }
app_project.save
Xcodeproj::XCScheme.share_scheme(app_project.path, 'App')
......
Subproject commit 79d702f5c41e042672f0605437ce472b0d36a7a0
Subproject commit c3633bdbd40e8a75af860439c98c119bb60b9fa3
......@@ -139,6 +139,8 @@ module Pod
pod 'monkey', :path => (fixture_path + 'monkey').to_s
target 'SampleProject'
end
@podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
@lockfile = generate_lockfile
@file = Pathname('/yolo.m')
......@@ -190,6 +192,8 @@ module Pod
pod 'monkey', :path => (fixture_path + 'monkey').to_s
target 'SampleProject'
end
@podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
@lockfile = generate_lockfile
@file = Pathname('/yolo.m')
......@@ -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
fixture_path = ROOT + 'spec/fixtures'
config.repos_dir = fixture_path + 'spec-repos'
......@@ -283,9 +287,43 @@ module Pod
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)'
e.message.should.match /Unable to determine Swift version for the following pods:/
e.message.should.include '`OrangeFramework` is integrated by multiple targets that use a different Swift version: ' \
'`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
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
@validator = TargetValidator.new([], [orangeframework_pod_target, matryoshka_pod_target])
lambda { @validator.validate! }.should.not.raise
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
fixture_path = ROOT + 'spec/fixtures'
config.repos_dir = fixture_path + 'spec-repos'
......@@ -387,7 +427,7 @@ module Pod
EOS
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'
config.repos_dir = fixture_path + 'spec-repos'
podfile = Podfile.new do
......
......@@ -278,6 +278,8 @@ module Pod
pod 'monkey', :path => (fixture_path + 'monkey').to_s
end
end
podfile.target_definitions['SampleProject'].stubs(:swift_version).returns('3.0')
lockfile = generate_lockfile
@installer = Installer.new(config.sandbox, podfile, lockfile)
......
......@@ -914,7 +914,7 @@ module Pod
end
end
describe 'wihout a user provided swift version' do
describe 'without a user provided swift version' do
it 'warns for Swift Pods' do
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