Changeset View
Changeset View
Standalone View
Standalone View
contrib/teamcity/build-configurations.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2020 The Bitcoin developers | # Copyright (c) 2020 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
import argparse | import argparse | ||||
import json | import json | ||||
import os | import os | ||||
from pathlib import Path, PurePath | from pathlib import Path, PurePath | ||||
import signal | |||||
import subprocess | import subprocess | ||||
import sys | import sys | ||||
# Default timeout value in seconds. Should be overridden by the | |||||
# configuration file. | |||||
DEFAULT_TIMEOUT = 1 * 60 * 60 | |||||
if sys.version_info < (3, 6): | if sys.version_info < (3, 6): | ||||
raise SystemError("This script requires python >= 3.6") | raise SystemError("This script requires python >= 3.6") | ||||
def main(): | def main(): | ||||
script_dir = PurePath(os.path.realpath(__file__)).parent | script_dir = PurePath(os.path.realpath(__file__)).parent | ||||
# By default search for a configuration file in the same directory as this | # By default search for a configuration file in the same directory as this | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | def main(): | ||||
} | } | ||||
try: | try: | ||||
subprocess.run( | subprocess.run( | ||||
[str(script_path)] + unknown_args, | [str(script_path)] + unknown_args, | ||||
check=True, | check=True, | ||||
cwd=build_directory, | cwd=build_directory, | ||||
env={**os.environ, **environment_variables}, | env={**os.environ, **environment_variables}, | ||||
timeout=build.get("timeout", DEFAULT_TIMEOUT), | |||||
) | |||||
except subprocess.TimeoutExpired as e: | |||||
print( | |||||
"Build {} timed out after {:.1f}s".format( | |||||
args.build, round(e.timeout, 1) | |||||
) | |||||
) | ) | ||||
# Make sure to kill all the child processes, as subprocess only kills | |||||
# the one we started. It will also kill this python script ! | |||||
# The return code is 128 + 9 (SIGKILL) = 137. | |||||
os.killpg(os.getpgid(os.getpid()), signal.SIGKILL) | |||||
except subprocess.CalledProcessError as e: | except subprocess.CalledProcessError as e: | ||||
print("Build failed with exit code {}".format(e.returncode)) | print( | ||||
"Build {} failed with exit code {}".format( | |||||
args.build, | |||||
e.returncode)) | |||||
sys.exit(e.returncode) | sys.exit(e.returncode) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |