From c5071a5706ac391724c9a0b003bff5101c0148b3 Mon Sep 17 00:00:00 2001 From: boztopuz Date: Thu, 5 Dec 2024 11:39:08 +0300 Subject: [PATCH 1/6] [BE-4993]: Added -legacy flag for xcode cli xcresulttool command --- xcode_parser.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/xcode_parser.rb b/xcode_parser.rb index 3f884db..12eb87c 100644 --- a/xcode_parser.rb +++ b/xcode_parser.rb @@ -19,8 +19,19 @@ def execute_cmd(cmd) output end + def get_xcode_version + output = execute_cmd("xcodebuild -version") + xcode_version = output.match(/Xcode (\d+(\.\d+)?)/)[1] + return xcode_version.to_f + end + def get_object(id = nil) - cmd = "xcrun xcresulttool get --format json --path #{@test_path}" + selected_xcode_version = get_xcode_version + if selected_xcode_version >= 16.0 + cmd = "xcrun xcresulttool get object --legacy --format json --path #{@test_path}" + else + cmd = "xcrun xcresulttool get --format json --path #{@test_path}" + end cmd += " --id #{id}" if id raw_result = execute_cmd(cmd) JSON.parse raw_result @@ -31,7 +42,12 @@ def extract_attachment(filename, id) FileUtils.mkdir_p(attachments_path) unless Dir.exist?(attachments_path) output_path = File.join(attachments_path, filename) puts "Exporting attachment #{filename}" - cmd = "xcrun xcresulttool export --path #{@test_path} --id '#{id}' --output-path '#{output_path}' --type file" + selected_xcode_version = get_xcode_version + if selected_xcode_version >= 16.0 + cmd = "xcrun xcresulttool export object --legacy --path #{@test_path} --id '#{id}' --output-path '#{output_path}' --type file" + else + cmd = "xcrun xcresulttool export --path #{@test_path} --id '#{id}' --output-path '#{output_path}' --type file" + end execute_cmd(cmd) end From c47aed40126222f75ee533b3e387a98d5d1337a1 Mon Sep 17 00:00:00 2001 From: boztopuz Date: Fri, 6 Dec 2024 15:35:21 +0300 Subject: [PATCH 2/6] [BE-4993]: Refactor some function, and handled multiple execute of xcode version --- xcode_parser.rb | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/xcode_parser.rb b/xcode_parser.rb index 12eb87c..636b73a 100644 --- a/xcode_parser.rb +++ b/xcode_parser.rb @@ -19,22 +19,27 @@ def execute_cmd(cmd) output end + @@xcode_version = nil def get_xcode_version - output = execute_cmd("xcodebuild -version") - xcode_version = output.match(/Xcode (\d+(\.\d+)?)/)[1] - return xcode_version.to_f + @@xcode_version ||= begin + output = execute_cmd("xcodebuild -version") + output.match(/Xcode (\d+(\.\d+)?)/)[1].to_f + 1 + end end - def get_object(id = nil) - selected_xcode_version = get_xcode_version - if selected_xcode_version >= 16.0 - cmd = "xcrun xcresulttool get object --legacy --format json --path #{@test_path}" - else - cmd = "xcrun xcresulttool get --format json --path #{@test_path}" - end + def get_xcrun_command(cmd_func, id: nil, filename: nil, output_path: nil) + cmd = "xcrun xcresulttool #{cmd_func} object --path #{@test_path}" + cmd += " object --legacy" if get_xcode_version >= 16.0 cmd += " --id #{id}" if id + cmd += " --format json" if cmd_func == "get" + cmd += " --output-path '#{output_path}' --type file" if output_path + cmd + end + + def get_object(id = nil) + cmd = get_xcrun_command("get", id: id) raw_result = execute_cmd(cmd) - JSON.parse raw_result + JSON.parse(raw_result) end def extract_attachment(filename, id) @@ -42,12 +47,7 @@ def extract_attachment(filename, id) FileUtils.mkdir_p(attachments_path) unless Dir.exist?(attachments_path) output_path = File.join(attachments_path, filename) puts "Exporting attachment #{filename}" - selected_xcode_version = get_xcode_version - if selected_xcode_version >= 16.0 - cmd = "xcrun xcresulttool export object --legacy --path #{@test_path} --id '#{id}' --output-path '#{output_path}' --type file" - else - cmd = "xcrun xcresulttool export --path #{@test_path} --id '#{id}' --output-path '#{output_path}' --type file" - end + cmd = get_xcrun_command("export", id: id, output_path: output_path) execute_cmd(cmd) end From 966437ecb828ad35594f1a0de41114951ba3ba35 Mon Sep 17 00:00:00 2001 From: boztopuz Date: Fri, 6 Dec 2024 17:04:17 +0300 Subject: [PATCH 3/6] [BE-4993]: deleted unexpeted argument --- xcode_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode_parser.rb b/xcode_parser.rb index 636b73a..e51d144 100644 --- a/xcode_parser.rb +++ b/xcode_parser.rb @@ -28,7 +28,7 @@ def get_xcode_version end def get_xcrun_command(cmd_func, id: nil, filename: nil, output_path: nil) - cmd = "xcrun xcresulttool #{cmd_func} object --path #{@test_path}" + cmd = "xcrun xcresulttool #{cmd_func} --path #{@test_path}" cmd += " object --legacy" if get_xcode_version >= 16.0 cmd += " --id #{id}" if id cmd += " --format json" if cmd_func == "get" From 676ad3bfe2ba076a6c02dde3bdaba3bec386711e Mon Sep 17 00:00:00 2001 From: boztopuz Date: Sun, 8 Dec 2024 21:47:46 +0300 Subject: [PATCH 4/6] [BE-4993]: fixed wrong logic of cmd function --- xcode_parser.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xcode_parser.rb b/xcode_parser.rb index e51d144..d4a1d47 100644 --- a/xcode_parser.rb +++ b/xcode_parser.rb @@ -28,11 +28,11 @@ def get_xcode_version end def get_xcrun_command(cmd_func, id: nil, filename: nil, output_path: nil) - cmd = "xcrun xcresulttool #{cmd_func} --path #{@test_path}" + cmd = "xcrun xcresulttool #{cmd_func}" cmd += " object --legacy" if get_xcode_version >= 16.0 - cmd += " --id #{id}" if id - cmd += " --format json" if cmd_func == "get" - cmd += " --output-path '#{output_path}' --type file" if output_path + cmd += " --format json --path #{@test_path}" if cmd_func == "get" + cmd += " --id #{id}" if cmd_func == "get" && id + cmd += " --path #{@test_path} --id #{id} --output-path '#{output_path}' --type file" if output_path cmd end From 9b51bdd65b9a1efcce78c79bd683101999c1f5d1 Mon Sep 17 00:00:00 2001 From: boztopuz Date: Sun, 8 Dec 2024 22:11:40 +0300 Subject: [PATCH 5/6] [BE-4993]: Fixed wrong version increament --- xcode_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcode_parser.rb b/xcode_parser.rb index d4a1d47..f72dda4 100644 --- a/xcode_parser.rb +++ b/xcode_parser.rb @@ -23,7 +23,7 @@ def execute_cmd(cmd) def get_xcode_version @@xcode_version ||= begin output = execute_cmd("xcodebuild -version") - output.match(/Xcode (\d+(\.\d+)?)/)[1].to_f + 1 + output.match(/Xcode (\d+(\.\d+)?)/)[1].to_f end end From 02cbb2abf5ee89ad06cc53ec56d91e71daefbe4d Mon Sep 17 00:00:00 2001 From: boztopuz Date: Mon, 9 Dec 2024 13:42:22 +0300 Subject: [PATCH 6/6] [BE-4993]: Fixed duplicated logics --- xcode_parser.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xcode_parser.rb b/xcode_parser.rb index f72dda4..0de2319 100644 --- a/xcode_parser.rb +++ b/xcode_parser.rb @@ -30,9 +30,10 @@ def get_xcode_version def get_xcrun_command(cmd_func, id: nil, filename: nil, output_path: nil) cmd = "xcrun xcresulttool #{cmd_func}" cmd += " object --legacy" if get_xcode_version >= 16.0 - cmd += " --format json --path #{@test_path}" if cmd_func == "get" - cmd += " --id #{id}" if cmd_func == "get" && id - cmd += " --path #{@test_path} --id #{id} --output-path '#{output_path}' --type file" if output_path + cmd += " --format json" if cmd_func == "get" + cmd += " --path #{@test_path}" + cmd += " --id #{id}" if id + cmd += " --output-path '#{output_path}' --type file" if output_path cmd end