Skip to content

Commit

Permalink
Use legacy flag for xcresulttool, needed for Xcode 16 support. (#209)
Browse files Browse the repository at this point in the history
* Use legacy flag for xcresulttool, needed for Xcode 16 support.

* Remove artifacts
  • Loading branch information
lpusok authored Aug 26, 2024
1 parent f14128c commit 1335841
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/converters/xcresult3/xcresulttool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"os/exec"
"regexp"
"strconv"

"github.com/bitrise-io/go-utils/command"
"github.com/bitrise-io/go-utils/errorutil"
Expand All @@ -16,13 +18,47 @@ func isXcresulttoolAvailable() bool {
return command.New("xcrun", "--find", "xcresulttool").Run() == nil
}

func isLegacyFlagNeededForXcresulttoolVersion() (bool, error) {
args := []string{"xcresulttool", "version"}
cmd := command.New("xcrun", args...)
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
if err != nil {
if errorutil.IsExitStatusError(err) {
return true, fmt.Errorf("%s failed: %s", cmd.PrintableCommandArgs(), out)
}
return true, fmt.Errorf("%s failed: %s", cmd.PrintableCommandArgs(), err)
}
// xcresulttool version 23025, format version 3.53 (current)
versionRegexp := regexp.MustCompile("xcresulttool version ([0-9]+)")

matches := versionRegexp.FindStringSubmatch(out)
if len(matches) < 2 {
return true, fmt.Errorf("no version matches found in output: %s", out)
}

version, err := strconv.Atoi(matches[1])
if err != nil {
return true, fmt.Errorf("failed to convert version: %s", matches[1])
}

return version >= 23_021, nil // Xcode 16 beta3 has version 23021
}

// xcresulttoolGet performs xcrun xcresulttool get with --id flag defined if id provided and marshals the output into v.
func xcresulttoolGet(xcresultPth, id string, v interface{}) error {
args := []string{"xcresulttool", "get", "--format", "json", "--path", xcresultPth}
if id != "" {
args = append(args, "--id", id)
}

isLegacyFlag, err := isLegacyFlagNeededForXcresulttoolVersion()
if err != nil {
return err
}
if isLegacyFlag {
args = append(args, "--legacy")
}

cmd := command.New("xcrun", args...)
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
if err != nil {
Expand All @@ -40,6 +76,14 @@ func xcresulttoolGet(xcresultPth, id string, v interface{}) error {
// xcresulttoolExport exports a file with the given id at the given output path.
func xcresulttoolExport(xcresultPth, id, outputPth string) error {
args := []string{"xcresulttool", "export", "--path", xcresultPth, "--id", id, "--output-path", outputPth, "--type", "file"}
isLegacyFlag, err := isLegacyFlagNeededForXcresulttoolVersion()
if err != nil {
return err
}
if isLegacyFlag {
args = append(args, "--legacy")
}

cmd := command.New("xcrun", args...)
out, err := cmd.RunAndReturnTrimmedCombinedOutput()
if err != nil {
Expand Down

0 comments on commit 1335841

Please sign in to comment.