Skip to content

Commit d946d09

Browse files
authored
chore: better simctl data gather (#32)
1 parent 2e6e0ef commit d946d09

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

lib/fastlane/plugin/create_simulator_devices/helpers/create_simulator_devices/models/simctl/device.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ module CreateSimulatorDevices
55
module SimCTL
66
# Represents a device.
77
class Device
8-
attr_accessor :udid, :name, :device_type_identifier, :available
8+
attr_accessor :udid, :name, :device_type_identifier, :available, :data_path, :log_path
99

10-
def initialize(name:, udid:, device_type_identifier:, available:)
10+
def initialize(name:, udid:, device_type_identifier:, available:, data_path:, log_path:) # rubocop:disable Metrics/ParameterLists
1111
self.name = name
1212
self.udid = udid
1313
self.device_type_identifier = device_type_identifier
1414
self.available = available
15+
self.data_path = data_path
16+
self.log_path = log_path
1517
end
1618

1719
def available?
@@ -27,7 +29,9 @@ def self.from_hash(hash)
2729
name: hash[:name],
2830
udid: hash[:udid],
2931
device_type_identifier: hash[:deviceTypeIdentifier],
30-
available: hash[:isAvailable]
32+
available: hash[:isAvailable],
33+
data_path: hash[:dataPath],
34+
log_path: hash[:logPath]
3135
)
3236
end
3337
end

lib/fastlane/plugin/create_simulator_devices/helpers/gather_simctl_diagnose/runner.rb

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ def run(devices) # rubocop:disable Metrics/AbcSize
5050
end
5151

5252
# Return distinct matched devices strings
53-
matched_devices = create_simulator_devices_runner.find_runtime_and_device_for_required_devices(required_devices)
53+
matched_simctl_devices = create_simulator_devices_runner.find_runtime_and_device_for_required_devices(required_devices)
5454
.reject { |required_device| required_device.simctl_device.nil? }
55+
.map(&:simctl_device)
5556

56-
matched_devices_udids = matched_devices.map { |matched_device| matched_device.simctl_device.udid }
57+
matched_devices_udids = matched_simctl_devices.map(&:udid)
5758
UI.message("Available simulator devices: #{matched_devices_udids.join(', ')}")
5859

59-
temp_output_dir = "#{File.expand_path(output_dir)}/simctl_diagnose_#{Time.now.strftime('%Y%m%d%H%M%S')}"
60+
full_output_dir_path = File.expand_path(output_dir)
61+
temp_output_dir = "#{full_output_dir_path}/simctl_diagnose"
62+
63+
FileUtils.mkdir_p(temp_output_dir)
6064

6165
diagnose_args = matched_devices_udids.map { |udid| "--udid=#{udid}" }
6266
diagnose_args << '-b' # Do NOT show the resulting archive in a Finder window upon completion.
@@ -68,17 +72,42 @@ def run(devices) # rubocop:disable Metrics/AbcSize
6872

6973
collect_diagnose_data_script_path = File.expand_path("#{__dir__}/scripts/collect_simctl_diagnose_data.sh")
7074

75+
UI.message("Collecting diagnose data to #{temp_output_dir}...")
7176
shell_helper.sh(
7277
command: "SIMCTL_DIAGNOSE_OUTPUT_FOLDER=#{temp_output_dir.shellescape} #{collect_diagnose_data_script_path.shellescape} #{cmd_args}",
73-
print_command: verbose,
78+
print_command: true,
7479
print_command_output: verbose
7580
)
7681

7782
archive_name = "#{temp_output_dir}.tar.gz"
7883
Actions.lane_context[Actions::SharedValues::GATHER_SIMCTL_DIAGNOSE_OUTPUT_FILE] = archive_name
7984

85+
copy_data_containers_and_logs(matched_simctl_devices, full_output_dir_path) if include_booted_device_data_directory || include_all_device_logs
86+
8087
archive_name
8188
end
89+
90+
def copy_data_containers_and_logs(matched_simctl_devices, output_dir)
91+
matched_simctl_devices.each do |simctl_device|
92+
copy_data_container_and_logs(simctl_device, output_dir)
93+
end
94+
end
95+
96+
def copy_data_container_and_logs(simctl_device, output_dir)
97+
if File.exist?(simctl_device.data_path)
98+
UI.message("Copying data from #{simctl_device.data_path} to #{output_dir}...")
99+
shell_helper.sh(
100+
command: "tar -czf #{output_dir}/#{simctl_device.name.shellescape}_#{simctl_device.udid.shellescape}_data.tar.gz --cd #{File.dirname(simctl_device.data_path).shellescape} #{File.basename(simctl_device.data_path).shellescape}"
101+
)
102+
end
103+
104+
return unless File.exist?(simctl_device.log_path)
105+
106+
UI.message("Copying logs from #{simctl_device.log_path} to #{output_dir}...")
107+
shell_helper.sh(
108+
command: "tar -czf #{output_dir}/#{simctl_device.name.shellescape}_#{simctl_device.udid.shellescape}_logs.tar.gz --cd #{File.dirname(simctl_device.log_path).shellescape} #{File.basename(simctl_device.log_path).shellescape}"
109+
)
110+
end
82111
end
83112
end
84113
end

lib/fastlane/plugin/create_simulator_devices/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Fastlane
44
module CreateSimulatorDevices
5-
VERSION = '0.0.15'
5+
VERSION = '0.0.16'
66
end
77
end

0 commit comments

Comments
 (0)