Commit 0ea0d99c authored by Daniel Tomlinson's avatar Daniel Tomlinson Committed by Danielle Tomlinson

[Installer] Set SWIFT_VERSION on generated targets

parent c5d3cc85
......@@ -32,6 +32,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Mark Schall](https://github.com/maschall)
[#5572](https://github.com/CocoaPods/CocoaPods/pull/5572)
* [Installer] Set the SWIFT_VERSION for CocoaPods generated targets.
[Danielle Tomlinson](https://github.com/DanToml)
[#5540](https://github.com/CocoaPods/CocoaPods/pulls/5540)
##### Bug Fixes
* Fix local pod platform conflict error message.
......
......@@ -7,7 +7,7 @@ GIT
GIT
remote: https://github.com/CocoaPods/Core.git
revision: 628a2e908dff578db6e59b1ac6aec99b6f45cb95
revision: 56a87a1597533b33e7467f92429a0aded4f32ef0
branch: master
specs:
cocoapods-core (1.0.1)
......
......@@ -294,7 +294,7 @@ module Pod
distinct_targets = specs_by_target.each_with_object({}) do |dependency, hash|
target_definition, dependent_specs = *dependency
dependent_specs.group_by(&:root).each do |root_spec, specs|
pod_variant = PodVariant.new(specs, target_definition.platform, target_definition.uses_frameworks?)
pod_variant = PodVariant.new(specs, target_definition.platform, target_definition.uses_frameworks?, target_definition.swift_version)
hash[root_spec] ||= {}
(hash[root_spec][pod_variant] ||= []) << target_definition
end
......
......@@ -16,6 +16,10 @@ module Pod
attr_accessor :requires_frameworks
alias_method :requires_frameworks?, :requires_frameworks
# @return [String] the Swift version
#
attr_accessor :swift_version
# @return [Specification] the root specification
#
def root_spec
......@@ -28,10 +32,11 @@ module Pod
# @param [Platform] platform @see #platform
# @param [Bool] requires_frameworks @see #requires_frameworks?
#
def initialize(specs, platform, requires_frameworks = false)
def initialize(specs, platform, requires_frameworks = false, swift_version = nil)
self.specs = specs
self.platform = platform
self.requires_frameworks = requires_frameworks
self.swift_version = swift_version
end
# @return [Bool] whether the {PodVariant} is equal to another taking all
......@@ -41,7 +46,8 @@ module Pod
self.class == other.class &&
specs == other.specs &&
platform == other.platform &&
requires_frameworks == other.requires_frameworks
requires_frameworks == other.requires_frameworks &&
swift_version == other.swift_version
end
alias_method :eql?, :==
......@@ -51,7 +57,7 @@ module Pod
#
# @!visibility private
def hash
[specs, platform, requires_frameworks].hash
[specs, platform, requires_frameworks, swift_version].hash
end
end
end
......
......@@ -44,6 +44,7 @@ module Pod
result.platform = compute_platform(targets)
result.archs = compute_archs(targets)
result.project = user_project
result.target_definition.swift_version = compute_swift_version_from_targets(targets)
result
end
......@@ -205,6 +206,29 @@ module Pod
end
end
end
# Compute the Swift version for the target build configurations. If more
# than one Swift version is defined for a given target, then it will raise.
#
# @param [Array<PBXNativeTarget>] targets
# the targets that are checked for Swift versions.
#
# @return [String] the targets Swift version or nil
#
def compute_swift_version_from_targets(targets)
versions = targets.flat_map(&:build_configurations).
flat_map { |config| config.build_settings['SWIFT_VERSION'] }.
compact.
uniq
case versions.count
when 0
nil
when 1
versions.first
else
raise Informative, 'There may only be up to 1 unique SWIFT_VERSION per target.'
end
end
end
end
end
......
......@@ -108,7 +108,6 @@ module Pod
def prepare
UI.message '- Creating Pods project' do
@project = create_project
analysis_result.all_user_build_configurations.each do |name, type|
@project.add_build_configuration(name, type)
end
......
......@@ -55,6 +55,9 @@ module Pod
settings['PUBLIC_HEADERS_FOLDER_PATH'] = ''
end
settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = ''
if target.swift_version
settings['SWIFT_VERSION'] = target.swift_version
end
settings
end
......
......@@ -81,6 +81,12 @@ module Pod
end
end
# @return [String] the Swift version for the target.
#
def swift_version
target_definitions.map(&:swift_version).compact.uniq.first
end
# @note The deployment target for the pod target is the maximum of all
# the deployment targets for the current platform of the target
# (or the minimum required to support the current installation
......
......@@ -12,6 +12,7 @@ module Pod
variant.specs.should == @specs
variant.platform.should == @platform
variant.requires_frameworks.should == false
variant.swift_version.should.nil?
end
it 'can be initialized with specs, platform and whether it requires frameworks' do
......@@ -19,6 +20,15 @@ module Pod
variant.specs.should == @specs
variant.platform.should == @platform
variant.requires_frameworks.should == true
variant.swift_version.should.nil?
end
it 'can be initialized with specs, platform, whether it requires frameworks, and a Swift version' do
variant = PodVariant.new(@specs, @platform, true, '2.3')
variant.specs.should == @specs
variant.platform.should == @platform
variant.requires_frameworks.should == true
variant.swift_version.should == '2.3'
end
it 'can return the root spec' do
......@@ -27,11 +37,12 @@ module Pod
variant.root_spec.should == spec
end
it 'can be compared for equality with another variant with the same specs, platform and value for whether it requires frameworks' do
spec = PodVariant.new(@specs, @platform, false)
spec.should == PodVariant.new(@specs, @platform, false)
it 'can be compared for equality with another variant with the same specs, platform, value for whether it requires frameworks and Swift version' do
spec = PodVariant.new(@specs, @platform, false, '2.3')
spec.should == PodVariant.new(@specs, @platform, false, '2.3')
spec.should.not == PodVariant.new(@specs, @platform, false, '3.0')
spec.should.not == PodVariant.new([@specs.first], @platform, false)
spec.should.not == PodVariant.new(@specs, Platform.osx, false)
spec.should.not == PodVariant.new(@specs, Platform.osx, false, '2.3')
spec.should.not == PodVariant.new(@specs, @platform, true)
end
......
......@@ -284,5 +284,48 @@ module Pod
message.should.include('Unable to determine the platform for the `default` target.')
end
end
#--------------------------------------#
describe '#compute_swift_version_from_targets' do
it 'returns the user defined SWIFT_VERSION if only one unique version is defined' do
user_project = Xcodeproj::Project.new('path')
target = user_project.new_target(:application, 'Target', :ios)
target.build_configuration_list.set_setting('SWIFT_VERSION', '2.3')
target_definition = Podfile::TargetDefinition.new(:default, nil)
user_targets = [target]
target_inspector = TargetInspector.new(target_definition, config.installation_root)
target_inspector.send(:compute_swift_version_from_targets, user_targets).should.equal '2.3'
end
it 'returns nil if the version is not defined' do
user_project = Xcodeproj::Project.new('path')
target = user_project.new_target(:application, 'Target', :ios)
target.build_configuration_list.set_setting('SWIFT_VERSION', nil)
target_definition = Podfile::TargetDefinition.new(:default, nil)
user_targets = [target]
target_inspector = TargetInspector.new(target_definition, config.installation_root)
target_inspector.send(:compute_swift_version_from_targets, user_targets).should.equal nil
end
it 'raises if the user defined SWIFT_VERSION contains multiple unique versions are defined' do
user_project = Xcodeproj::Project.new('path')
target = user_project.new_target(:application, 'Target', :ios)
target.build_configuration_list.build_configurations.first.build_settings['SWIFT_VERSION'] = '2.3'
target.build_configuration_list.build_configurations.last.build_settings['SWIFT_VERSION'] = '3.0'
target_definition = Podfile::TargetDefinition.new(:default, nil)
user_targets = [target]
target_inspector = TargetInspector.new(target_definition, config.installation_root)
should.raise(Informative) do
target_inspector.send(:compute_swift_version_from_targets, user_targets)
end.message.should.include 'There may only be up to 1 unique SWIFT_VERSION per target.'
end
end
end
end
......@@ -113,6 +113,25 @@ module Pod
#--------------------------------------#
describe 'setting the SWIFT_VERSION' do
it 'does not set the version if not included by the target definition' do
@installer.install!
@project.targets.first.build_configurations.each do |config|
config.build_settings.should.not.include?('SWIFT_VERSION')
end
end
it 'sets the version to the one specified in the target definition' do
@target_definition.swift_version = '3.0'
@installer.install!
@project.targets.first.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'].should == '3.0'
end
end
end
#--------------------------------------#
it 'adds the source files of each pod to the target of the Pod library' do
@installer.install!
names = @installer.target.native_target.source_build_phase.files.map { |bf| bf.file_ref.display_name }
......
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