Skip to content

Commit

Permalink
Merge pull request #6 from aleksanderlorenc-lw/xcode16-legacy-fix
Browse files Browse the repository at this point in the history
Apply --legacy flag when using Xcode 16's xcresulttool
  • Loading branch information
giginet authored Aug 27, 2024
2 parents 5f4a6ff + fe2b769 commit e369a2c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 23 deletions.
43 changes: 28 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
PATH
remote: .
specs:
xcresult (0.2.1)
xcresult (0.2.2)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
ast (2.4.2)
diff-lcs (1.3)
jaro_winkler (1.5.3)
parallel (1.17.0)
parser (2.6.4.1)
ast (~> 2.4.0)
rainbow (3.0.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
parallel (1.25.1)
parser (3.3.4.0)
ast (~> 2.4.1)
racc
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.1)
regexp_parser (2.9.2)
rexml (3.3.4)
strscan
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
Expand All @@ -27,15 +33,22 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
rubocop (0.73.0)
jaro_winkler (~> 1.5.1)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 2.6)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
unicode-display_width (1.6.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
strscan (3.1.0)
unicode-display_width (2.5.0)

PLATFORMS
ruby
Expand All @@ -44,8 +57,8 @@ DEPENDENCIES
bundler (~> 2.0)
rake (~> 13.0)
rspec (~> 3.0)
rubocop
rubocop (~> 1.65)
xcresult!

BUNDLED WITH
2.0.2
2.5.10
21 changes: 17 additions & 4 deletions lib/xcresult/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def action_test_plan_summaries
# Maps ids into ActionTestPlanRunSummaries by executing xcresulttool to get JSON
# containing specific information for each test summary
@action_test_plan_summaries = ids.map do |id|
raw = execute_cmd("xcrun xcresulttool get --format json --path #{path} --id #{id}")
raw = execute_cmd(xcresulttool_command("get", "--format json --path #{path} --id #{id}"))
json = JSON.parse(raw)
XCResult::ActionTestPlanRunSummaries.new(json)
end
Expand All @@ -48,7 +48,7 @@ def export_xccovreports(destination: nil)
# Exports all xccovreport files from the report references
ids.each_with_index.map do |id, i|
output_path = File.join(destination, "action_#{i}.xccovreport")
cmd = "xcrun xcresulttool export --path #{path} --id '#{id}' --output-path #{output_path} --type file"
cmd = xcresulttool_command("export", "--path #{path} --id '#{id}' --output-path #{output_path} --type file")
execute_cmd(cmd)

output_path
Expand All @@ -67,7 +67,7 @@ def export_xccovarchives(destination: nil)
# Exports all xcovarchive directories from the archive references
ids.each_with_index.map do |id, i|
output_path = File.join(destination, "action_#{i}.xccovarchive")
cmd = "xcrun xcresulttool export --path #{path} --id '#{id}' --output-path #{output_path} --type directory"
cmd = xcresulttool_command("export", "--path #{path} --id '#{id}' --output-path #{output_path} --type directory")
execute_cmd(cmd)

output_path
Expand All @@ -77,11 +77,24 @@ def export_xccovarchives(destination: nil)
private

def get_result_bundle_json(id: nil)
cmd = "xcrun xcresulttool get --format json --path #{path}"
cmd = xcresulttool_command("get", "--format json --path #{path}")
cmd += " --id #{id}" if id
execute_cmd(cmd)
end

def xcresulttool_command(subcommand, args)
# Find the current xcresulttool version based on Fastlane's implementation
# xcresulttool version 23024, format version 3.53 (current)
match = `xcrun xcresulttool version`.match(/xcresulttool version (?<version>\d+),/)

version = match[:version]&.to_f

requires_legacy = version >= 23_021.0
legacy_flag = requires_legacy ? ' --legacy' : ''

cmd = "xcrun xcresulttool #{subcommand}#{legacy_flag} #{args}"
end

def execute_cmd(cmd)
output = `#{cmd}`
raise "Failed to execute - #{cmd}" unless $?.success?
Expand Down
2 changes: 1 addition & 1 deletion lib/xcresult/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module XCResult
VERSION = '0.2.1'
VERSION = '0.2.2'
end
36 changes: 34 additions & 2 deletions spec/xcresult_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
# frozen_string_literal: true

RSpec.describe XCResult do
RSpec.describe "XCResult Version" do
let(:path) { File.absolute_path("./spec/fixtures/Test.xcresult") }
let(:summary_id) { "0~2LVFAe2LWJ7FCnOsKan5UgGk7WChVJYuZlxPILKyxdpmfjsMrwjBJ2wUhaJQJ36Per_GRUfTI1cKeO2QiGvB8Q==" }
let!(:subject) { XCResult::Parser.new(path: path) }
let(:command) { subject.send(:xcresulttool_command, "get", "--format json --path #{path} --id #{summary_id}") }

before do
allow(subject).to receive(:`).with('xcrun xcresulttool version').and_return(xcresulttool_version)
end

context 'with below 23_021.0 ' do
let(:xcresulttool_version) { 'xcresulttool version 23020, format version 3.53 (current)' }
let(:expected) { "xcrun xcresulttool get --format json --path #{path} --id #{summary_id}" }

it 'should not have --legacy' do
expect(command).to eq(expected)
end
end

context 'with 23_021.0 and above' do
let(:xcresulttool_version) { 'xcresulttool version 23022, format version 3.53 (current)' }
let(:expected) { "xcrun xcresulttool get --legacy --format json --path #{path} --id #{summary_id}" }

it 'should have --legacy' do
expect(command).to eq(expected)
end
end
end

RSpec.describe "XCResult Test Summaries" do
let(:path) { File.absolute_path("./spec/fixtures/Test.xcresult") }
let(:summary_id) { "0~2LVFAe2LWJ7FCnOsKan5UgGk7WChVJYuZlxPILKyxdpmfjsMrwjBJ2wUhaJQJ36Per_GRUfTI1cKeO2QiGvB8Q==" }

Expand All @@ -21,7 +50,10 @@
it 'parse test plan summaries' do
parser = XCResult::Parser.new(path: path)

expect(parser).to receive(:execute_cmd).with("xcrun xcresulttool get --format json --path #{path} --id #{summary_id}").and_call_original
expect(parser).to receive(:execute_cmd).with(lambda { |command|
is_valid_xcresulttool_command_regex = /^xcrun xcresulttool get( --legacy)? --format json --path .+ --id [a-zA-Z0-9_\~\=]+$/
is_valid_xcresulttool_command_regex.match(command) != nil
}).and_call_original

summaries = parser.action_test_plan_summaries

Expand Down
2 changes: 1 addition & 1 deletion xcresult.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '~> 13.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'rubocop', '~> 1.65'
end

0 comments on commit e369a2c

Please sign in to comment.