Better warning message for which Swift version was used during validation

parent 8b75633c
...@@ -30,6 +30,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -30,6 +30,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes ##### Bug Fixes
* Better warning message for which Swift version was used during validation
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#7121](https://github.com/CocoaPods/CocoaPods/issues/7121)
* Strip vendored dSYMs during embed script phase * Strip vendored dSYMs during embed script phase
[Dimitris Koutsogiorgas](https://github.com/dnkoutso) [Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#7111](https://github.com/CocoaPods/CocoaPods/issues/7111) [#7111](https://github.com/CocoaPods/CocoaPods/issues/7111)
...@@ -139,7 +143,7 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -139,7 +143,7 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
* Fix validation warnings when using --swift-version * Fix validation warnings when using --swift-version
[Danielle Tomlinson](https://github.com/dantoml) [Danielle Tomlinson](https://github.com/dantoml)
[#6971](https://github.com/CocoaPods/CocoaPods/issue/6971) [#6971](https://github.com/CocoaPods/CocoaPods/pull/6971)
* Fix xcconfig boolean merging when substrings include yes or no * Fix xcconfig boolean merging when substrings include yes or no
[Paul Beusterien](https://github.com/paulb777) [Paul Beusterien](https://github.com/paulb777)
......
...@@ -99,6 +99,7 @@ module Pod ...@@ -99,6 +99,7 @@ module Pod
# @return [void] # @return [void]
# #
def self.add_swift_version(target, swift_version) def self.add_swift_version(target, swift_version)
raise 'Cannot set empty Swift version to target.' if swift_version.blank?
target.build_configurations.each do |configuration| target.build_configurations.each do |configuration|
configuration.build_settings['SWIFT_VERSION'] = swift_version configuration.build_settings['SWIFT_VERSION'] = swift_version
end end
......
...@@ -256,7 +256,7 @@ module Pod ...@@ -256,7 +256,7 @@ module Pod
# @return [String] the SWIFT_VERSION to use for validation. # @return [String] the SWIFT_VERSION to use for validation.
# #
def swift_version def swift_version
return @swift_version if defined?(@swift_version) return @swift_version unless @swift_version.nil?
if version = dot_swift_version if version = dot_swift_version
@swift_version = version @swift_version = version
else else
...@@ -277,11 +277,10 @@ module Pod ...@@ -277,11 +277,10 @@ module Pod
swift_version_path.read.strip swift_version_path.read.strip
end end
# @return [String] A string representing the Swift version used during linting # @return [Boolean] Whether any of the pod targets part of this validator use Swift or not.
# or nil, if Swift was not used.
# #
def used_swift_version def uses_swift?
swift_version if @installer.pod_targets.any?(&:uses_swift?) @installer.pod_targets.any?(&:uses_swift?)
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -318,7 +317,7 @@ module Pod ...@@ -318,7 +317,7 @@ module Pod
download_pod download_pod
check_file_patterns check_file_patterns
install_pod install_pod
validate_dot_swift_version validate_swift_version
add_app_project_import add_app_project_import
validate_vendored_dynamic_frameworks validate_vendored_dynamic_frameworks
build_pod build_pod
...@@ -394,14 +393,21 @@ module Pod ...@@ -394,14 +393,21 @@ module Pod
validate_url(spec.documentation_url) if spec.documentation_url validate_url(spec.documentation_url) if spec.documentation_url
end end
def validate_dot_swift_version # Performs validation for which version of Swift is used during validation.
if !used_swift_version.nil? && @swift_version.nil? #
# 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` file present either.
#
def validate_swift_version
if uses_swift? && @swift_version.nil? && dot_swift_version.nil?
warning(:swift_version, warning(:swift_version,
'The validator for Swift projects uses ' \ 'The validator used ' \
'Swift 3.0 by default, if you are using a different version of ' \ "Swift #{DEFAULT_SWIFT_VERSION} by default because no Swift version was specified. " \
'swift you can use a `.swift-version` file to set the version for ' \ 'If you want to use a different version of Swift during validation, then either use the `--swift-version` parameter ' \
"your Pod. For example to use Swift 2.3, run: \n" \ 'or use a `.swift-version` file to set the version of Swift to use for ' \
' `echo "2.3" > .swift-version`') 'your Pod. For example to use Swift 2.3, run: `echo "2.3" > .swift-version`.')
end end
end end
......
...@@ -885,11 +885,29 @@ module Pod ...@@ -885,11 +885,29 @@ module Pod
result = validator.results.first result = validator.results.first
result.type.should == :warning result.type.should == :warning
result.message.should == 'The validator for ' \ result.message.should == 'The validator used ' \
'Swift projects uses Swift 3.0 by default, if you are using a ' \ 'Swift 3.0 by default because no Swift version was specified. ' \
'different version of swift you can use a `.swift-version` file ' \ 'If you want to use a different version of Swift during validation, then either use the `--swift-version` parameter ' \
'to set the version for your Pod. For example to use Swift 2.3, ' \ 'or use a `.swift-version` file to set the version of Swift to use for ' \
"run: \n `echo \"2.3\" > .swift-version`" 'your Pod. For example to use Swift 2.3, run: `echo "2.3" > .swift-version`.'
end
it 'does not warn for Swift if version was set by a dot swift version file' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
validator = test_swiftpod_with_dot_swift_version
validator.validate
validator.results.count.should == 0
end
it 'does not warn for Swift if version was set as a parameter' do
Specification.any_instance.stubs(:deployment_target).returns('9.0')
validator = test_swiftpod
validator.stubs(:dot_swift_version).returns(nil)
validator.swift_version = '3.1.0'
validator.validate
validator.results.count.should == 0
end end
end end
...@@ -950,7 +968,7 @@ module Pod ...@@ -950,7 +968,7 @@ module Pod
validator.instance_variable_set(:@installer, installer) validator.instance_variable_set(:@installer, installer)
validator.stubs(:dot_swift_version).returns('1.2.3') validator.stubs(:dot_swift_version).returns('1.2.3')
validator.used_swift_version.should == '1.2.3' validator.uses_swift?.should.be.true
end end
it 'returns the swift_version when a target has used Swift' do it 'returns the swift_version when a target has used Swift' do
...@@ -959,7 +977,7 @@ module Pod ...@@ -959,7 +977,7 @@ module Pod
installer = stub(:pod_targets => [pod_target]) installer = stub(:pod_targets => [pod_target])
validator.instance_variable_set(:@installer, installer) validator.instance_variable_set(:@installer, installer)
validator.used_swift_version.should.nil? validator.uses_swift?.should.be.false
end end
end 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