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`
##### 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
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#7111](https://github.com/CocoaPods/CocoaPods/issues/7111)
......@@ -139,7 +143,7 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
* Fix validation warnings when using --swift-version
[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
[Paul Beusterien](https://github.com/paulb777)
......
......@@ -99,6 +99,7 @@ module Pod
# @return [void]
#
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|
configuration.build_settings['SWIFT_VERSION'] = swift_version
end
......
......@@ -256,7 +256,7 @@ module Pod
# @return [String] the SWIFT_VERSION to use for validation.
#
def swift_version
return @swift_version if defined?(@swift_version)
return @swift_version unless @swift_version.nil?
if version = dot_swift_version
@swift_version = version
else
......@@ -277,11 +277,10 @@ module Pod
swift_version_path.read.strip
end
# @return [String] A string representing the Swift version used during linting
# or nil, if Swift was not used.
# @return [Boolean] Whether any of the pod targets part of this validator use Swift or not.
#
def used_swift_version
swift_version if @installer.pod_targets.any?(&:uses_swift?)
def uses_swift?
@installer.pod_targets.any?(&:uses_swift?)
end
#-------------------------------------------------------------------------#
......@@ -318,7 +317,7 @@ module Pod
download_pod
check_file_patterns
install_pod
validate_dot_swift_version
validate_swift_version
add_app_project_import
validate_vendored_dynamic_frameworks
build_pod
......@@ -394,14 +393,21 @@ module Pod
validate_url(spec.documentation_url) if spec.documentation_url
end
def validate_dot_swift_version
if !used_swift_version.nil? && @swift_version.nil?
# Performs validation for which version of Swift is used during validation.
#
# 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,
'The validator for Swift projects uses ' \
'Swift 3.0 by default, if you are using a different version of ' \
'swift you can use a `.swift-version` file to set the version for ' \
"your Pod. For example to use Swift 2.3, run: \n" \
' `echo "2.3" > .swift-version`')
'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 2.3, run: `echo "2.3" > .swift-version`.')
end
end
......
......@@ -885,11 +885,29 @@ module Pod
result = validator.results.first
result.type.should == :warning
result.message.should == 'The validator for ' \
'Swift projects uses Swift 3.0 by default, if you are using a ' \
'different version of swift you can use a `.swift-version` file ' \
'to set the version for your Pod. For example to use Swift 2.3, ' \
"run: \n `echo \"2.3\" > .swift-version`"
result.message.should == 'The validator used ' \
'Swift 3.0 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 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
......@@ -950,7 +968,7 @@ module Pod
validator.instance_variable_set(:@installer, installer)
validator.stubs(:dot_swift_version).returns('1.2.3')
validator.used_swift_version.should == '1.2.3'
validator.uses_swift?.should.be.true
end
it 'returns the swift_version when a target has used Swift' do
......@@ -959,7 +977,7 @@ module Pod
installer = stub(:pod_targets => [pod_target])
validator.instance_variable_set(:@installer, installer)
validator.used_swift_version.should.nil?
validator.uses_swift?.should.be.false
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