44 "encoding/json"
55 "fmt"
66 "os/exec"
7+ "regexp"
8+ "strconv"
79
810 "github.com/bitrise-io/go-utils/command"
911 "github.com/bitrise-io/go-utils/errorutil"
@@ -16,13 +18,47 @@ func isXcresulttoolAvailable() bool {
1618 return command .New ("xcrun" , "--find" , "xcresulttool" ).Run () == nil
1719}
1820
21+ func isLegacyFlagNeededForXcresulttoolVersion () (bool , error ) {
22+ args := []string {"xcresulttool" , "version" }
23+ cmd := command .New ("xcrun" , args ... )
24+ out , err := cmd .RunAndReturnTrimmedCombinedOutput ()
25+ if err != nil {
26+ if errorutil .IsExitStatusError (err ) {
27+ return true , fmt .Errorf ("%s failed: %s" , cmd .PrintableCommandArgs (), out )
28+ }
29+ return true , fmt .Errorf ("%s failed: %s" , cmd .PrintableCommandArgs (), err )
30+ }
31+ // xcresulttool version 23025, format version 3.53 (current)
32+ versionRegexp := regexp .MustCompile ("xcresulttool version ([0-9]+)" )
33+
34+ matches := versionRegexp .FindStringSubmatch (out )
35+ if len (matches ) < 2 {
36+ return true , fmt .Errorf ("no version matches found in output: %s" , out )
37+ }
38+
39+ version , err := strconv .Atoi (matches [1 ])
40+ if err != nil {
41+ return true , fmt .Errorf ("failed to convert version: %s" , matches [1 ])
42+ }
43+
44+ return version >= 23_021 , nil // Xcode 16 beta3 has version 23021
45+ }
46+
1947// xcresulttoolGet performs xcrun xcresulttool get with --id flag defined if id provided and marshals the output into v.
2048func xcresulttoolGet (xcresultPth , id string , v interface {}) error {
2149 args := []string {"xcresulttool" , "get" , "--format" , "json" , "--path" , xcresultPth }
2250 if id != "" {
2351 args = append (args , "--id" , id )
2452 }
2553
54+ isLegacyFlag , err := isLegacyFlagNeededForXcresulttoolVersion ()
55+ if err != nil {
56+ return err
57+ }
58+ if isLegacyFlag {
59+ args = append (args , "--legacy" )
60+ }
61+
2662 cmd := command .New ("xcrun" , args ... )
2763 out , err := cmd .RunAndReturnTrimmedCombinedOutput ()
2864 if err != nil {
@@ -40,6 +76,14 @@ func xcresulttoolGet(xcresultPth, id string, v interface{}) error {
4076// xcresulttoolExport exports a file with the given id at the given output path.
4177func xcresulttoolExport (xcresultPth , id , outputPth string ) error {
4278 args := []string {"xcresulttool" , "export" , "--path" , xcresultPth , "--id" , id , "--output-path" , outputPth , "--type" , "file" }
79+ isLegacyFlag , err := isLegacyFlagNeededForXcresulttoolVersion ()
80+ if err != nil {
81+ return err
82+ }
83+ if isLegacyFlag {
84+ args = append (args , "--legacy" )
85+ }
86+
4387 cmd := command .New ("xcrun" , args ... )
4488 out , err := cmd .RunAndReturnTrimmedCombinedOutput ()
4589 if err != nil {
0 commit comments