Skip to content

Commit

Permalink
Merge pull request #10477 from jmagman/analyze-config
Browse files Browse the repository at this point in the history
Respect `--configuration` option when analyzing via `pod lib lint --analyze`
  • Loading branch information
segiddins committed Mar 16, 2021
2 parents b16c090 + b3bb536 commit 123f2d0
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
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
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
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
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
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

0 comments on commit 123f2d0

Please sign in to comment.