Skip to content

Commit

Permalink
[gym][snapshot] fix gym use_system_scm option and add `use_system_s…
Browse files Browse the repository at this point in the history
…cm` 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 <johannes@plunien.de>
  • Loading branch information
rogerluan and plu committed Jan 15, 2021
1 parent e2ff499 commit 79d0167
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 6 deletions.
2 changes: 1 addition & 1 deletion fastlane.gemspec
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions fastlane_core/lib/fastlane_core/project.rb
Expand Up @@ -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}"
Expand Down
28 changes: 28 additions & 0 deletions fastlane_core/spec/project_spec.rb
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion gym/lib/gym/generators/build_command_generator.rb
Expand Up @@ -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]

Expand Down
19 changes: 18 additions & 1 deletion gym/spec/build_command_generator_spec.rb
Expand Up @@ -6,6 +6,7 @@
end

before(:each) do
@project.options.values.delete(:use_system_scm)
allow(Gym).to receive(:project).and_return(@project)
end

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion scan/lib/scan/test_command_generator.rb
Expand Up @@ -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]
Expand Down
19 changes: 18 additions & 1 deletion scan/spec/test_command_generator_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion snapshot/lib/snapshot/options.rb
Expand Up @@ -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
Expand Down

0 comments on commit 79d0167

Please sign in to comment.