diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f28956185..4dd28ab491 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/cocoapods/validator.rb b/lib/cocoapods/validator.rb index 1ea578ee3a..11aafa8891 100644 --- a/lib/cocoapods/validator.rb +++ b/lib/cocoapods/validator.rb @@ -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.' @@ -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) diff --git a/spec/functional/command/lib/list_spec.rb b/spec/functional/command/lib/list_spec.rb index be66007598..45b3902378 100644 --- a/spec/functional/command/lib/list_spec.rb +++ b/spec/functional/command/lib/list_spec.rb @@ -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') diff --git a/spec/functional/command/spec_spec.rb b/spec/functional/command/spec_spec.rb index 54a0edf6c4..e55669650e 100644 --- a/spec/functional/command/spec_spec.rb +++ b/spec/functional/command/spec_spec.rb @@ -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 => {}) diff --git a/spec/unit/validator_spec.rb b/spec/unit/validator_spec.rb index 242bf15aa3..8811fe1710 100644 --- a/spec/unit/validator_spec.rb +++ b/spec/unit/validator_spec.rb @@ -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']) @@ -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'])