Skip to content
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

Respect --configuration option when analyzing via pod lib lint --analyze #10477

Merged
merged 1 commit into from
Mar 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`

##### Bug Fixes

* Respect `--configuration` option when analyzing via `pod lib lint --analyze`.
[Jenn Magder](https://github.com/jmagman)
[#10476](https://github.com/CocoaPods/CocoaPods/issues/10476)

* Do not add dependencies to 'Link Binary With Libraries' phase.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#10133](https://github.com/CocoaPods/CocoaPods/pull/10133)
Expand Down
5 changes: 3 additions & 2 deletions lib/cocoapods/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,9 @@ def build_pod
if scheme.nil?
UI.warn "Skipping compilation with `xcodebuild` because target contains no sources.\n".yellow
else
requested_configuration = configuration ? configuration : 'Release'
if analyze
output = xcodebuild('analyze', scheme, 'Release', :deployment_target => deployment_target)
output = xcodebuild('analyze', scheme, requested_configuration, :deployment_target => deployment_target)
find_output = Executable.execute_command('find', [validation_dir, '-name', '*.html'], false)
if find_output != ''
message = 'Static Analysis failed.'
Expand All @@ -722,7 +723,7 @@ def build_pod
error('build_pod', message)
end
else
output = xcodebuild('build', scheme, configuration ? configuration : 'Release', :deployment_target => deployment_target)
output = xcodebuild('build', scheme, requested_configuration, :deployment_target => deployment_target)
end
parsed_output = parse_xcodebuild_output(output)
translate_output_to_linter_messages(parsed_output)
Expand Down
9 changes: 9 additions & 0 deletions spec/functional/command/lib/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ module Pod
end
end

it 'analyzes the current working directory using Debug configuration' do
Dir.chdir(fixture('integration/Reachability')) do
cmd = command('lib', 'lint', '--only-errors', '--quick', '--configuration=Debug', '--analyze')
cmd.run

UI.output.should.include 'passed validation'
end
end

it 'lints a single spec in the current working directory' do
Dir.chdir(fixture('integration/Reachability')) do
cmd = command('lib', 'lint', 'Reachability.podspec', '--quick', '--only-errors')
Expand Down
8 changes: 8 additions & 0 deletions spec/functional/command/spec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ module Pod
end
end

it 'analyzes the current working directory using Debug configuration' do
Dir.chdir(fixture('spec-repos') + 'trunk/Specs/1/3/f/JSONKit/1.4/') do
cmd = command('spec', 'lint', '--quick', '--allow-warnings', '--configuration=Debug', '--analyze')
cmd.run
UI.output.should.include 'passed validation'
end
end

it 'fails with an informative error when downloading the podspec 404s' do
WebMock.stub_request(:get, 'https://no.such.domain/404').
to_return(:status => 404, :body => '', :headers => {})
Expand Down
61 changes: 61 additions & 0 deletions spec/unit/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,35 @@ def podspec_path(name = 'JSONKit', version = '1.4')
validator.validate.should == true
end

it 'runs xcodebuild with correct arguments when validating with --configuration' do
require 'fourflusher'
Fourflusher::SimControl.any_instance.stubs(:destination).returns(['-destination', 'id=XXX'])
Validator.any_instance.unstub(:xcodebuild)
PodTarget.any_instance.stubs(:should_build?).returns(true)
Installer::Xcode::PodsProjectGenerator::PodTargetInstaller.any_instance.stubs(:validate_targets_contain_sources) # since we skip downloading
validator = Validator.new(podspec_path, config.sources_manager.master.map(&:url))
validator.stubs(:check_file_patterns)
validator.stubs(:validate_url)
validator.configuration = 'Debug'
git = Executable.which(:git)
Executable.stubs(:which).with('git').returns(git)
Executable.stubs(:capture_command).with('git', ['config', '--get', 'remote.origin.url'], :capture => :out).returns(['https://github.com/CocoaPods/Specs.git'])
Executable.stubs(:which).with(:xcrun)
Executable.stubs(:execute_command).with('find', [validator.validation_dir, '-name', '*.html'], false).returns('')
Executable.expects(:execute_command).with { |executable, command, _| executable == 'git' && command.first == 'clone' }.once
# Command should '-configuration Debug' instead of '-configuration Release'.
command = ['clean', 'build', '-workspace', File.join(validator.validation_dir, 'App.xcworkspace'), '-scheme', 'App', '-configuration', 'Debug']
args = %w(CODE_SIGN_IDENTITY=)
Executable.expects(:execute_command).with('xcodebuild', command + args, true).once.returns('')
args = %w(CODE_SIGN_IDENTITY=- -sdk appletvsimulator) + Fourflusher::SimControl.new.destination('Apple TV 1080p')
Executable.expects(:execute_command).with('xcodebuild', command + args, true).once.returns('')
args = %w(CODE_SIGN_IDENTITY=- -sdk iphonesimulator) + Fourflusher::SimControl.new.destination('iPhone 4s')
Executable.expects(:execute_command).with('xcodebuild', command + args, true).once.returns('')
args = %w(CODE_SIGN_IDENTITY=- -sdk watchsimulator) + Fourflusher::SimControl.new.destination('Apple Watch - 38mm')
Executable.expects(:execute_command).with('xcodebuild', command + args, true).once.returns('')
validator.validate.should == true
end

it 'runs xcodebuild with correct arguments when validating with --analyze' do
require 'fourflusher'
Fourflusher::SimControl.any_instance.stubs(:destination).returns(['-destination', 'id=XXX'])
Expand Down Expand Up @@ -843,6 +872,38 @@ def podspec_path(name = 'JSONKit', version = '1.4')
validator.validate.should == true
end

it 'runs xcodebuild with correct arguments when validating with --analyze and --configuration' do
require 'fourflusher'
Fourflusher::SimControl.any_instance.stubs(:destination).returns(['-destination', 'id=XXX'])
Validator.any_instance.unstub(:xcodebuild)
PodTarget.any_instance.stubs(:should_build?).returns(true)
Installer::Xcode::PodsProjectGenerator::PodTargetInstaller.any_instance.stubs(:validate_targets_contain_sources) # since we skip downloading
validator = Validator.new(podspec_path, config.sources_manager.master.map(&:url))
validator.stubs(:check_file_patterns)
validator.stubs(:validate_url)
validator.analyze = true
validator.configuration = 'Debug'
git = Executable.which(:git)
Executable.stubs(:which).with('git').returns(git)
Executable.stubs(:capture_command).with('git', ['config', '--get', 'remote.origin.url'], :capture => :out).returns(['https://github.com/CocoaPods/Specs.git'])
Executable.stubs(:which).with(:xcrun)
Executable.stubs(:execute_command).with('find', [validator.validation_dir, '-name', '*.html'], false).returns('')
Executable.expects(:execute_command).with { |executable, command, _| executable == 'git' && command.first == 'clone' }.once
# Command should 'analyze' instead of 'build' and '-configuration Debug' instead of '-configuration Release'.
command = ['clean', 'analyze', '-workspace', File.join(validator.validation_dir, 'App.xcworkspace'), '-scheme', 'App', '-configuration', 'Debug']
args = %w(CODE_SIGN_IDENTITY=)
analyzer_args = %w(CLANG_ANALYZER_OUTPUT=html)
analyzer_args += %w(CLANG_ANALYZER_OUTPUT_DIR=analyzer)
Executable.expects(:execute_command).with('xcodebuild', command + args + analyzer_args, true).once.returns('')
args = %w(CODE_SIGN_IDENTITY=- -sdk appletvsimulator) + Fourflusher::SimControl.new.destination('Apple TV 1080p') + analyzer_args
Executable.expects(:execute_command).with('xcodebuild', command + args, true).once.returns('')
args = %w(CODE_SIGN_IDENTITY=- -sdk iphonesimulator) + Fourflusher::SimControl.new.destination('iPhone 4s') + analyzer_args
Executable.expects(:execute_command).with('xcodebuild', command + args, true).once.returns('')
args = %w(CODE_SIGN_IDENTITY=- -sdk watchsimulator) + Fourflusher::SimControl.new.destination('Apple Watch - 38mm') + analyzer_args
Executable.expects(:execute_command).with('xcodebuild', command + args, true).once.returns('')
validator.validate.should == true
end

it 'runs xcodebuild with correct arguments for code signing' do
require 'fourflusher'
Fourflusher::SimControl.any_instance.stubs(:destination).returns(['-destination', 'id=XXX'])
Expand Down