8000 Better warning message for which Swift version was used during validation by dnkoutso · Pull Request #7131 · CocoaPods/CocoaPods · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Better warning message for which Swift version was used during validation #7131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed link


* Fix xcconfig boolean merging when substrings include yes or no
[Paul Beusterien](https://github.com/paulb777)
Expand Down
1 change: 1 addition & 0 deletions lib/cocoapods/generator/app_target_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def self.add_xctest_search_paths(target)
# @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
Expand Down
32 changes: 19 additions & 13 deletions lib/cocoapods/validator.rb
< 8000 tr data-hunk="e520a08fb1d2462898a56c5566a7ffcf9166a84388e8ba86ca2e4c41cc70127a" class="show-top-border">
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def validation_dir
# @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?
Copy link
Contributor Author
@dnkoutso dnkoutso Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the regression fix. @swift_version is always defined but it is nil.

if version = dot_swift_version
@swift_version = version
else
Expand All @@ -277,11 +277,10 @@ def dot_swift_version
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

#-------------------------------------------------------------------------#
Expand Down Expand Up @@ -318,7 +317,7 @@ def perform_extensive_analysis(spec)
download_pod
check_file_patterns
install_pod
validate_dot_swift_version
validate_swift_version
add_app_project_import
validate_vendored_dynamic_frameworks
build_pod
Expand Down Expand Up @@ -394,14 +393,21 @@ def validate_documentation_url(spec)
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

Expand Down
32 changes: 25 additions & 7 deletions spec/unit/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,29 @@ def test_swiftpod_with_dot_swift_version(version = '3.1.0')

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

Expand Down Expand Up @@ -950,7 +968,7 @@ def test_swiftpod_with_dot_swift_version(version = '3.1.0')
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
Expand All @@ -959,7 +977,7 @@ def test_swiftpod_with_dot_swift_version(version = '3.1.0')
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
Expand Down
0