Skip to content

Commit

Permalink
Merge pull request #6258 from dnkoutso/master
Browse files Browse the repository at this point in the history
Output Swift targets when multiple versions of Swift are detected.
  • Loading branch information
endocrimes committed Dec 7, 2016
2 parents 2b8e42f + 4842c43 commit d645df5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`

##### 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
[Mark Schall](https://github.com/maschall)
[#5809](https://github.com/CocoaPods/CocoaPods/pull/5809)
Expand Down
30 changes: 24 additions & 6 deletions lib/cocoapods/installer/analyzer/target_inspector.rb
Expand Up @@ -216,16 +216,34 @@ def compute_recommends_frameworks(target_definition, native_targets)
# @return [String] the targets Swift version or nil
#
def compute_swift_version_from_targets(targets)
versions = targets.flat_map do |target|
target.resolved_build_setting('SWIFT_VERSION').values
end.flatten.compact.uniq
case versions.count
versions_to_targets = targets.inject({}) do |memo, target|
versions = target.resolved_build_setting('SWIFT_VERSION').values
versions.each do |version|
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
nil
when 1
versions.first
versions_to_targets.keys.first
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
Expand Down
25 changes: 24 additions & 1 deletion spec/unit/installer/analyzer/target_inspector_spec.rb
Expand Up @@ -322,9 +322,32 @@ module Pod
user_targets = [target]

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
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

it 'returns the project-level SWIFT_VERSION if the target-level SWIFT_VERSION is not defined' do
Expand Down

0 comments on commit d645df5

Please sign in to comment.