@@ -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
84113end
0 commit comments