Output Swift targets when multiple versions of Swift are detected.

parent 2b8e42fb
...@@ -8,6 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -8,6 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Enhancements ##### Enhancements
* Output Swift targets when multiple versions of Swift are detected.
[Justin Martin](https://github.com/justinseanmartin) & [Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6191](https://github.com/CocoaPods/CocoaPods/issues/6191)
* [update] adding --sources to specify to only update pods from a repo * [update] adding --sources to specify to only update pods from a repo
[Mark Schall](https://github.com/maschall) [Mark Schall](https://github.com/maschall)
[#5809](https://github.com/CocoaPods/CocoaPods/pull/5809) [#5809](https://github.com/CocoaPods/CocoaPods/pull/5809)
......
...@@ -216,16 +216,34 @@ module Pod ...@@ -216,16 +216,34 @@ module Pod
# @return [String] the targets Swift version or nil # @return [String] the targets Swift version or nil
# #
def compute_swift_version_from_targets(targets) def compute_swift_version_from_targets(targets)
versions = targets.flat_map do |target| versions_to_targets = targets.inject({}) do |memo, target|
target.resolved_build_setting('SWIFT_VERSION').values versions = target.resolved_build_setting('SWIFT_VERSION').values
end.flatten.compact.uniq versions.each do |version|
case versions.count memo[version] = [] if memo[version].nil?
memo[version] << target.name unless memo[version].include? target.name
end
memo
end
case versions_to_targets.count
when 0 when 0
nil nil
when 1 when 1
versions.first versions_to_targets.keys.first
else else
raise Informative, 'There may only be up to 1 unique SWIFT_VERSION per target.' target_version_pairs = versions_to_targets.map do |version_names, target_names|
target_names.map { |target_name| [target_name, version_names] }
end
sorted_pairs = target_version_pairs.flat_map { |i| i }.sort_by do |target_name, version_name|
"#{target_name} #{version_name}"
end
formatted_output = sorted_pairs.map do |target, version_name|
"#{target}: Swift #{version_name}"
end.join("\n")
raise Informative, "There may only be up to 1 unique SWIFT_VERSION per target. Found target(s) with multiple Swift versions:\n#{formatted_output}"
end end
end end
end end
......
...@@ -322,9 +322,32 @@ module Pod ...@@ -322,9 +322,32 @@ module Pod
user_targets = [target] user_targets = [target]
target_inspector = TargetInspector.new(target_definition, config.installation_root) target_inspector = TargetInspector.new(target_definition, config.installation_root)
expected_versions_string = "Target: Swift 2.3\nTarget: Swift 3.0"
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. Found target(s) with multiple Swift versions:\n#{expected_versions_string}"
end
it 'raises if the user defined SWIFT_VERSION contains multiple unique versions are defined on different targets' 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')
target2 = user_project.new_target(:application, 'Target2', :ios)
target2.build_configuration_list.set_setting('SWIFT_VERSION', '3.0')
target_definition = Podfile::TargetDefinition.new(:default, nil)
user_targets = [target, target2]
target_inspector = TargetInspector.new(target_definition, config.installation_root)
expected_versions_string = "Target: Swift 2.3\nTarget2: Swift 3.0"
should.raise(Informative) do should.raise(Informative) do
target_inspector.send(:compute_swift_version_from_targets, user_targets) 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.message.should.include "There may only be up to 1 unique SWIFT_VERSION per target. Found target(s) with multiple Swift versions:\n#{expected_versions_string}"
end end
it 'returns the project-level SWIFT_VERSION if the target-level SWIFT_VERSION is not defined' do it 'returns the project-level SWIFT_VERSION if the target-level SWIFT_VERSION is not defined' do
......
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