Unverified Commit 445c8f28 authored by Dimitris Koutsogiorgas's avatar Dimitris Koutsogiorgas Committed by GitHub

Merge pull request #7253 from dnkoutso/swift_version_support

Integrate `swift_version` DSL support into pod targets
parents 507e17b0 4ded31d6
......@@ -8,6 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Enhancements
* Integrate `swift_version` DSL support into pod targets
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#7134](https://github.com/CocoaPods/CocoaPods/issues/7134)
* Add color indication to output of `pod outdated`
[iv-mexx](https://github.com/iv-mexx)
[#7204](https://github.com/CocoaPods/CocoaPods/pull/7204)
......
......@@ -7,7 +7,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/Core.git
revision: 8cf88a076d916cf80821744a59ca1c431ccc046f
revision: 494334921393bfaed90fe97a224cabca14aad418
branch: master
specs:
cocoapods-core (1.4.0.beta.2)
......
......@@ -95,10 +95,12 @@ module Pod
end
end
# @return [String] the Swift version for the target.
# @return [String] the Swift version for the target. If the pod author has provided a swift version
# then that is the one returned, otherwise the Swift version is determined by the user
# targets that include this pod target.
#
def swift_version
target_definitions.map(&:swift_version).compact.uniq.first
root_spec.swift_version || target_definitions.map(&:swift_version).compact.uniq.first
end
# @note The deployment target for the pod target is the maximum of all
......
......@@ -257,8 +257,8 @@ module Pod
#
def swift_version
return @swift_version unless @swift_version.nil?
if version = dot_swift_version
@swift_version = version
if (version = spec.swift_version) || (version = dot_swift_version)
@swift_version = version.to_s
else
DEFAULT_SWIFT_VERSION
end
......@@ -395,19 +395,37 @@ module Pod
# Performs validation for which version of Swift is used during validation.
#
# An error will be displayed if the user has provided a `swift_version` attribute within the podspec but is also
# using either `--swift-version` parameter or a `.swift-version with a different Swift version.
#
# The user will be warned that the default version of Swift was used if the following things are true:
# - The project uses Swift at all
# - The user did not supply a Swift version via a parameter
# - There is no `swift_version` attribute set within the specification
# - There is no `.swift-version` file present either.
#
def validate_swift_version
if uses_swift? && @swift_version.nil? && dot_swift_version.nil?
warning(:swift_version,
return unless uses_swift?
spec_swift_version = spec.swift_version
unless spec_swift_version.nil?
message = nil
if !dot_swift_version.nil? && dot_swift_version != spec_swift_version.to_s
message = "Specification `#{spec.name}` specifies an inconsistent `swift_version` (`#{spec_swift_version}`) compared to the one present in your `.swift-version` file (`#{dot_swift_version}`). " \
'Please remove the `.swift-version` file which is now deprecated and only use the `swift_version` attribute within your podspec.'
elsif !@swift_version.nil? && @swift_version != spec_swift_version.to_s
message = "Specification `#{spec.name}` specifies an inconsistent `swift_version` (`#{spec_swift_version}`) compared to the one passed during lint (`#{@swift_version}`)."
end
unless message.nil?
error('swift', message)
return
end
end
if @swift_version.nil? && spec_swift_version.nil? && dot_swift_version.nil?
warning('swift',
'The validator used ' \
"Swift #{DEFAULT_SWIFT_VERSION} by default because no Swift version was specified. " \
'If you want to use a different version of Swift during validation, then either use the `--swift-version` parameter ' \
'or use a `.swift-version` file to set the version of Swift to use for ' \
'your Pod. For example to use Swift 4.0, run: `echo "4.0" > .swift-version`.')
'To specify a Swift version during validation, add the `swift_version` attribute in your podspec. ' \
'Note that usage of the `--swift-version` parameter or a `.swift-version` file is now deprecated.')
end
end
......@@ -471,12 +489,17 @@ module Pod
perform_post_install_actions).each { |m| @installer.send(m) }
deployment_target = spec.subspec_by_name(subspec_name).deployment_target(consumer.platform_name)
@installer.aggregate_targets.each do |target|
configure_pod_targets(@installer.aggregate_targets, deployment_target)
@installer.pods_project.save
end
def configure_pod_targets(targets, deployment_target)
targets.each do |target|
target.pod_targets.each do |pod_target|
next unless (native_target = pod_target.native_target)
native_target.build_configuration_list.build_configurations.each do |build_configuration|
(build_configuration.build_settings['OTHER_CFLAGS'] ||= '$(inherited)') << ' -Wincomplete-umbrella'
build_configuration.build_settings['SWIFT_VERSION'] = swift_version if pod_target.uses_swift?
build_configuration.build_settings['SWIFT_VERSION'] = (pod_target.swift_version || swift_version) if pod_target.uses_swift?
end
if pod_target.uses_swift?
pod_target.test_native_targets.each do |test_native_target|
......@@ -492,7 +515,6 @@ module Pod
error('swift', 'Swift support uses dynamic frameworks and is therefore only supported on iOS > 8.') unless uses_xctest
end
end
@installer.pods_project.save
end
def validate_vendored_dynamic_frameworks
......
......@@ -144,6 +144,20 @@ module Pod
end
end
describe 'swift version' do
it 'uses the swift version defined in the specification' do
@pod_target.root_spec.stubs(:swift_version).returns('3.0')
@target_definition.stubs(:swift_version).returns('2.3')
@pod_target.swift_version.should == '3.0'
end
it 'uses the swift version defined by the target definitions if no swift version is specifed in the spec' do
@pod_target.root_spec.stubs(:swift_version).returns(nil)
@target_definition.stubs(:swift_version).returns('2.3')
@pod_target.swift_version.should == '2.3'
end
end
describe 'Support files' do
it 'returns the absolute path of the xcconfig file' do
@pod_target.xcconfig_path('Release').to_s.should.include?(
......
......@@ -887,9 +887,55 @@ module Pod
result.type.should == :warning
result.message.should == 'The validator used ' \
'Swift 3.2 by default because no Swift version was specified. ' \
'If you want to use a different version of Swift during validation, then either use the `--swift-version` parameter ' \
'or use a `.swift-version` file to set the version of Swift to use for ' \
'your Pod. For example to use Swift 4.0, run: `echo "4.0" > .swift-version`.'
'To specify a Swift version during validation, add the `swift_version` attribute in your podspec. ' \
'Note that usage of the `--swift-version` parameter or a `.swift-version` file is now deprecated.'
end
it 'errors when swift version spec attribute does not match dot swift version' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
Specification.any_instance.stubs(:swift_version).returns(Version.new('4.0'))
validator = test_swiftpod_with_dot_swift_version('3.2')
validator.validate
validator.results.count.should == 1
result = validator.results.first
result.type.should == :error
result.message.should == 'Specification `JSONKit` specifies an inconsistent `swift_version` (`4.0`) compared to the one present in your `.swift-version` file (`3.2`). ' \
'Please remove the `.swift-version` file which is now deprecated and only use the `swift_version` attribute within your podspec.'
end
it 'does not error when swift version spec attribute matches dot swift version' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
Specification.any_instance.stubs(:swift_version).returns(Version.new('4.0'))
validator = test_swiftpod_with_dot_swift_version('4.0')
validator.validate
validator.results.count.should == 0
end
it 'errors when swift version spec attribute does not match parameter based swift version' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
Specification.any_instance.stubs(:swift_version).returns(Version.new('4.0'))
validator = test_swiftpod
validator.swift_version = '3.2'
validator.validate
validator.results.count.should == 1
result = validator.results.first
result.type.should == :error
result.message.should == 'Specification `JSONKit` specifies an inconsistent `swift_version` (`4.0`) compared to the one passed during lint (`3.2`).'
end
it 'does not error when swift version spec attribute matches parameter based swift version' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
Specification.any_instance.stubs(:swift_version).returns(Version.new('4.0'))
validator = test_swiftpod
validator.swift_version = '4.0'
validator.validate
validator.results.count.should == 0
end
it 'does not warn for Swift if version was set by a dot swift version file' do
......@@ -918,7 +964,13 @@ module Pod
validator.swift_version.should == '3.2'
end
it 'allows the user to set the version' do
it 'uses the Swift version specified by the swift_version attribute in the spec' do
validator = test_swiftpod
validator.spec.swift_version = '4.0'
validator.swift_version.should == '4.0'
end
it 'allows the user to set the Swift version using a .swift-version file' do
validator = test_swiftpod
validator.stubs(:dot_swift_version).returns('3.0')
validator.swift_version = '4.0'
......@@ -979,6 +1031,22 @@ module Pod
validator.uses_swift?.should.be.false
end
it 'honors swift version set by the pod target for dependencies' do
validator = test_swiftpod
consumer = stub(:platform_name => 'iOS')
validator.instance_variable_set(:@consumer, consumer)
debug_configuration_one = stub(:build_settings => {})
debug_configuration_two = stub(:build_settings => {})
native_target_one = stub(:build_configuration_list => stub(:build_configurations => [debug_configuration_one]))
native_target_two = stub(:build_configuration_list => stub(:build_configurations => [debug_configuration_two]))
pod_target_one = stub(:uses_swift? => true, :swift_version => '4.0', :native_target => native_target_one, :test_native_targets => [])
pod_target_two = stub(:uses_swift? => true, :swift_version => '3.2', :native_target => native_target_two, :test_native_targets => [])
aggregate_target = stub(:pod_targets => [pod_target_one, pod_target_two])
validator.send(:configure_pod_targets, [aggregate_target], '9.0')
debug_configuration_one.build_settings['SWIFT_VERSION'].should == '4.0'
debug_configuration_two.build_settings['SWIFT_VERSION'].should == '3.2'
end
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