Skip to content

Commit 3279062

Browse files
authored
Timeout and retry calls to xcodebuild (#876)
The xcodebuild command occasionally times out. Subsequent runs behave as expected.
1 parent d28312a commit 3279062

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

build/config/ios/ios_sdk.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@
2121
os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'flutter', 'prebuilts',
2222
))
2323

24+
25+
def run_command_with_retry(command, timeout=10, retries=3):
26+
"""
27+
Runs a command using subprocess.check_output with timeout and retry logic.
28+
29+
Args:
30+
command: A list representing the command and its arguments.
31+
timeout: The maximum time (in seconds) to wait for each command execution.
32+
retries: The number of times to retry the command if it times out.
33+
34+
Returns:
35+
The output of the command as a bytes object if successful, otherwise
36+
raises a CalledProcessError.
37+
"""
38+
for attempt in range(1, retries + 1):
39+
try:
40+
result = subprocess.check_output(command, timeout=timeout)
41+
return result.decode('utf-8').strip()
42+
except subprocess.TimeoutExpired:
43+
if attempt >= retries:
44+
raise # Re-raise the TimeoutExpired error after all retries
45+
46+
2447
def main(argv):
2548
parser = argparse.ArgumentParser()
2649
parser.add_argument(
@@ -76,7 +99,7 @@ def main(argv):
7699
sdk,
77100
'Path'
78101
]
79-
sdk_output = subprocess.check_output(command).decode('utf-8').strip()
102+
sdk_output = run_command_with_retry(command, timeout=300)
80103
if symlink_path:
81104
symlink_target = os.path.join(sdks_path, os.path.basename(sdk_output))
82105
symlink(sdk_output, symlink_target)

build/mac/find_sdk.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ def parse_version(version_str):
3131
return [int(x) for x in re.findall(r'(\d+)', version_str)]
3232

3333

34+
def run_command_with_retry(command, timeout=10, retries=3):
35+
"""
36+
Runs a command using subprocess.check_output with timeout and retry logic.
37+
38+
Args:
39+
command: A list representing the command and its arguments.
40+
timeout: The maximum time (in seconds) to wait for each command execution.
41+
retries: The number of times to retry the command if it times out.
42+
43+
Returns:
44+
The output of the command as a bytes object if successful, otherwise
45+
raises a CalledProcessError.
46+
"""
47+
for attempt in range(1, retries + 1):
48+
try:
49+
result = subprocess.check_output(command, timeout=timeout)
50+
return result.decode('utf-8').strip()
51+
except subprocess.TimeoutExpired:
52+
if attempt >= retries:
53+
raise # Re-raise the TimeoutExpired error after all retries
54+
55+
3456
def main():
3557
parser = OptionParser()
3658
parser.add_option("--print_sdk_path",
@@ -72,7 +94,7 @@ def main():
7294
sdk_command = ['xcodebuild',
7395
'-showsdks',
7496
'-json']
75-
sdk_json_output = subprocess.check_output(sdk_command)
97+
sdk_json_output = run_command_with_retry(sdk_command, timeout=300)
7698
sdk_json = json.loads(sdk_json_output)
7799

78100
best_sdk = None

0 commit comments

Comments
 (0)