Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout and retry calls to xcodebuild #876

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion build/config/ios/ios_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@
os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'flutter', 'prebuilts',
))


def run_command_with_retry(command, timeout=10, retries=3):
"""
Runs a command using subprocess.check_output with timeout and retry logic.

Args:
command: A list representing the command and its arguments.
timeout: The maximum time (in seconds) to wait for each command execution.
retries: The number of times to retry the command if it times out.

Returns:
The output of the command as a bytes object if successful, otherwise
raises a CalledProcessError.
"""
for attempt in range(1, retries + 1):
try:
result = subprocess.check_output(command, timeout=timeout)
return result.decode('utf-8').strip()
except subprocess.TimeoutExpired:
if attempt >= retries:
raise # Re-raise the TimeoutExpired error after all retries


def main(argv):
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -76,7 +99,7 @@ def main(argv):
sdk,
'Path'
]
sdk_output = subprocess.check_output(command).decode('utf-8').strip()
sdk_output = run_command_with_retry(command, timeout=300)
if symlink_path:
symlink_target = os.path.join(sdks_path, os.path.basename(sdk_output))
symlink(sdk_output, symlink_target)
Expand Down
24 changes: 23 additions & 1 deletion build/mac/find_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ def parse_version(version_str):
return [int(x) for x in re.findall(r'(\d+)', version_str)]


def run_command_with_retry(command, timeout=10, retries=3):
"""
Runs a command using subprocess.check_output with timeout and retry logic.

Args:
command: A list representing the command and its arguments.
timeout: The maximum time (in seconds) to wait for each command execution.
retries: The number of times to retry the command if it times out.

Returns:
The output of the command as a bytes object if successful, otherwise
raises a CalledProcessError.
"""
for attempt in range(1, retries + 1):
try:
result = subprocess.check_output(command, timeout=timeout)
return result.decode('utf-8').strip()
except subprocess.TimeoutExpired:
if attempt >= retries:
raise # Re-raise the TimeoutExpired error after all retries


def main():
parser = OptionParser()
parser.add_option("--print_sdk_path",
Expand Down Expand Up @@ -72,7 +94,7 @@ def main():
sdk_command = ['xcodebuild',
'-showsdks',
'-json']
sdk_json_output = subprocess.check_output(sdk_command)
sdk_json_output = run_command_with_retry(sdk_command, timeout=300)
sdk_json = json.loads(sdk_json_output)

best_sdk = None
Expand Down