From 79d0167bcd70796c4b16576e6f72f54b2786f74f Mon Sep 17 00:00:00 2001 From: Roger Oba Date: Fri, 15 Jan 2021 12:53:53 -0300 Subject: [PATCH] [gym][snapshot] fix gym `use_system_scm` option and add `use_system_scm` option to snapshot (#17832) * Fix gym -showBuildSettings command when providing use_system_scm option. - Also add use_system_scm option to snapshot to fix specs. * Fix duplicate use_system_scm option in #17832 (#17957) * Bump rspec version This will allow usage of `include("foo").once` * Add failing test 1) Scan Scan::TestCommandGenerator uses system scm options exactly once Failure/Error: expect(result).to include("-scmProvider system").once expected ["set -o pipefail &&", "env NSUnbufferedIO=YES xcodebuild", "-scheme app", "-project ./scan/examples/...it --output '/var/folders/qz/91qlx7gn30l6rfcwjfzsv_ph0000gn/T/junit_report20210113-97481-17c5v9n' "] to include "-scmProvider system" once but it is included twice * Deduplicate scmProvider option * Fix build command generator * Remove extra blank line Co-authored-by: Johannes Plunien --- fastlane.gemspec | 2 +- fastlane_core/lib/fastlane_core/project.rb | 1 + fastlane_core/spec/project_spec.rb | 28 +++++++++++++++++++ .../gym/generators/build_command_generator.rb | 4 ++- gym/spec/build_command_generator_spec.rb | 19 ++++++++++++- scan/lib/scan/test_command_generator.rb | 4 ++- scan/spec/test_command_generator_spec.rb | 19 ++++++++++++- snapshot/lib/snapshot/options.rb | 7 ++++- 8 files changed, 78 insertions(+), 6 deletions(-) diff --git a/fastlane.gemspec b/fastlane.gemspec index fe54f6b3951..7081cba34ac 100644 --- a/fastlane.gemspec +++ b/fastlane.gemspec @@ -102,7 +102,7 @@ Gem::Specification.new do |spec| # Development only spec.add_development_dependency('rake') - spec.add_development_dependency('rspec', '~> 3.9.0') + spec.add_development_dependency('rspec', '~> 3.10.0') spec.add_development_dependency('rspec_junit_formatter', '~> 0.4.1') spec.add_development_dependency('pry') spec.add_development_dependency('pry-byebug') diff --git a/fastlane_core/lib/fastlane_core/project.rb b/fastlane_core/lib/fastlane_core/project.rb index 0333bb7dc12..fffa270da58 100644 --- a/fastlane_core/lib/fastlane_core/project.rb +++ b/fastlane_core/lib/fastlane_core/project.rb @@ -322,6 +322,7 @@ def xcodebuild_parameters proj << "-configuration #{options[:configuration].shellescape}" if options[:configuration] proj << "-derivedDataPath #{options[:derived_data_path].shellescape}" if options[:derived_data_path] proj << "-xcconfig #{options[:xcconfig].shellescape}" if options[:xcconfig] + proj << "-scmProvider system" if options[:use_system_scm] if FastlaneCore::Helper.xcode_at_least?('11.0') && options[:cloned_source_packages_path] proj << "-clonedSourcePackagesDirPath #{options[:cloned_source_packages_path].shellescape}" diff --git a/fastlane_core/spec/project_spec.rb b/fastlane_core/spec/project_spec.rb index 8bfede326d4..20afa5a9a6a 100644 --- a/fastlane_core/spec/project_spec.rb +++ b/fastlane_core/spec/project_spec.rb @@ -510,6 +510,34 @@ def count_processes(text) end end + describe "xcodebuild use_system_scm" do + it 'generates an xcodebuild -showBuildSettings command that includes scmProvider if provided in options', requires_xcode: true do + project = FastlaneCore::Project.new({ + project: "./fastlane_core/spec/fixtures/projects/Example.xcodeproj", + use_system_scm: true + }) + command = "xcodebuild -showBuildSettings -project ./fastlane_core/spec/fixtures/projects/Example.xcodeproj -scmProvider system" + expect(project.build_xcodebuild_showbuildsettings_command).to eq(command) + end + + it 'generates an xcodebuild -showBuildSettings command that does not include scmProvider when not provided in options', requires_xcode: true do + project = FastlaneCore::Project.new({ + project: "./fastlane_core/spec/fixtures/projects/Example.xcodeproj" + }) + command = "xcodebuild -showBuildSettings -project ./fastlane_core/spec/fixtures/projects/Example.xcodeproj" + expect(project.build_xcodebuild_showbuildsettings_command).to eq(command) + end + + it 'generates an xcodebuild -showBuildSettings command that does not include scmProvider when the option provided is false', requires_xcode: true do + project = FastlaneCore::Project.new({ + project: "./fastlane_core/spec/fixtures/projects/Example.xcodeproj", + use_system_scm: false + }) + command = "xcodebuild -showBuildSettings -project ./fastlane_core/spec/fixtures/projects/Example.xcodeproj" + expect(project.build_xcodebuild_showbuildsettings_command).to eq(command) + end + end + describe 'xcodebuild command for SwiftPM', requires_xcode: true do it 'generates an xcodebuild -resolvePackageDependencies command with Xcode >= 11' do allow(FastlaneCore::Helper).to receive(:xcode_at_least?).and_return(true) diff --git a/gym/lib/gym/generators/build_command_generator.rb b/gym/lib/gym/generators/build_command_generator.rb index 6bb52eb3373..7640b8b3db0 100644 --- a/gym/lib/gym/generators/build_command_generator.rb +++ b/gym/lib/gym/generators/build_command_generator.rb @@ -39,7 +39,9 @@ def options options << "-destination '#{config[:destination]}'" if config[:destination] options << "-archivePath #{archive_path.shellescape}" unless config[:skip_archive] options << "-resultBundlePath '#{result_bundle_path}'" if config[:result_bundle] - options << "-scmProvider system" if config[:use_system_scm] + if config[:use_system_scm] && !options.include?("-scmProvider system") + options << "-scmProvider system" + end options << config[:xcargs] if config[:xcargs] options << "OTHER_SWIFT_FLAGS=\"-Xfrontend -debug-time-function-bodies\"" if config[:analyze_build_time] diff --git a/gym/spec/build_command_generator_spec.rb b/gym/spec/build_command_generator_spec.rb index ffea16abfc4..b572bd73651 100644 --- a/gym/spec/build_command_generator_spec.rb +++ b/gym/spec/build_command_generator_spec.rb @@ -6,6 +6,7 @@ end before(:each) do + @project.options.values.delete(:use_system_scm) allow(Gym).to receive(:project).and_return(@project) end @@ -92,7 +93,23 @@ options = { project: "./gym/examples/standard/Example.xcodeproj", use_system_scm: true } Gym.config = FastlaneCore::Configuration.create(Gym::Options.available_options, options) result = Gym::BuildCommandGenerator.generate - expect(result).to include("-scmProvider system") + expect(result).to include("-scmProvider system").once + end + + it "uses system scm via project options", requires_xcodebuild: true do + options = { project: "./gym/examples/standard/Example.xcodeproj" } + @project.options[:use_system_scm] = true + Gym.config = FastlaneCore::Configuration.create(Gym::Options.available_options, options) + result = Gym::BuildCommandGenerator.generate + expect(result).to include("-scmProvider system").once + end + + it "uses system scm options exactly once", requires_xcodebuild: true do + options = { project: "./gym/examples/standard/Example.xcodeproj", use_system_scm: true } + @project.options[:use_system_scm] = true + Gym.config = FastlaneCore::Configuration.create(Gym::Options.available_options, options) + result = Gym::BuildCommandGenerator.generate + expect(result).to include("-scmProvider system").once end it "defaults to Xcode scm when option is not provided", requires_xcodebuild: true do diff --git a/scan/lib/scan/test_command_generator.rb b/scan/lib/scan/test_command_generator.rb index eb1387ba887..5a24138fbfc 100644 --- a/scan/lib/scan/test_command_generator.rb +++ b/scan/lib/scan/test_command_generator.rb @@ -32,13 +32,15 @@ def options # rubocop:disable Metrics/PerceivedComplexity options = [] options += project_path_array unless config[:xctestrun] - options << "-scmProvider system" if config[:use_system_scm] options << "-sdk '#{config[:sdk]}'" if config[:sdk] options << destination # generated in `detect_values` options << "-toolchain '#{config[:toolchain]}'" if config[:toolchain] if config[:derived_data_path] && !options.include?("-derivedDataPath #{config[:derived_data_path].shellescape}") options << "-derivedDataPath #{config[:derived_data_path].shellescape}" end + if config[:use_system_scm] && !options.include?("-scmProvider system") + options << "-scmProvider system" + end options << "-resultBundlePath '#{result_bundle_path}'" if config[:result_bundle] if FastlaneCore::Helper.xcode_at_least?(10) options << "-parallel-testing-worker-count #{config[:concurrent_workers]}" if config[:concurrent_workers] diff --git a/scan/spec/test_command_generator_spec.rb b/scan/spec/test_command_generator_spec.rb index 1dab857aa68..1f6d0eb2f1e 100644 --- a/scan/spec/test_command_generator_spec.rb +++ b/scan/spec/test_command_generator_spec.rb @@ -76,6 +76,7 @@ describe Scan::TestCommandGenerator do before(:each) do @test_command_generator = Scan::TestCommandGenerator.new + @project.options.values.delete(:use_system_scm) end it "raises an exception when project path wasn't found" do @@ -163,7 +164,23 @@ options = { project: "./scan/examples/standard/app.xcodeproj", use_system_scm: true } Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options) result = @test_command_generator.generate - expect(result).to include("-scmProvider system") + expect(result).to include("-scmProvider system").once + end + + it "uses system scm via project options", requires_xcodebuild: true do + options = { project: "./scan/examples/standard/app.xcodeproj" } + @project.options[:use_system_scm] = true + Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options) + result = @test_command_generator.generate + expect(result).to include("-scmProvider system").once + end + + it "uses system scm options exactly once", requires_xcodebuild: true do + options = { project: "./scan/examples/standard/app.xcodeproj", use_system_scm: true } + @project.options[:use_system_scm] = true + Scan.config = FastlaneCore::Configuration.create(Scan::Options.available_options, options) + result = @test_command_generator.generate + expect(result).to include("-scmProvider system").once end it "defaults to Xcode scm when option is not provided", requires_xcodebuild: true do diff --git a/snapshot/lib/snapshot/options.rb b/snapshot/lib/snapshot/options.rb index 759e4c3b79e..8182c75ccca 100644 --- a/snapshot/lib/snapshot/options.rb +++ b/snapshot/lib/snapshot/options.rb @@ -283,7 +283,12 @@ def self.available_options env_name: "SNAPSHOT_SUPPRESS_XCODE_OUTPUT", description: "Suppress the output of xcodebuild to stdout. Output is still saved in buildlog_path", type: Boolean, - optional: true) + optional: true), + FastlaneCore::ConfigItem.new(key: :use_system_scm, + env_name: "SNAPSHOT_USE_SYSTEM_SCM", + description: "Lets xcodebuild use system's scm configuration", + type: Boolean, + default_value: false) ] end end