Changeset View
Changeset View
Standalone View
Standalone View
contrib/teamcity/build-configurations.py
Show All 25 Lines | |||||
class BuildConfiguration: | class BuildConfiguration: | ||||
def __init__(self, script_root, config_file, build_name=None): | def __init__(self, script_root, config_file, build_name=None): | ||||
self.script_root = script_root | self.script_root = script_root | ||||
self.config_file = config_file | self.config_file = config_file | ||||
self.name = None | self.name = None | ||||
self.config = {} | self.config = {} | ||||
self.script_path = Path() | self.script_path = Path() | ||||
self.project_root = PurePath( | |||||
subprocess.run( | |||||
['git', 'rev-parse', '--show-toplevel'], | |||||
capture_output=True, | |||||
check=True, | |||||
encoding='utf-8', | |||||
text=True, | |||||
).stdout.strip() | |||||
) | |||||
if not config_file.is_file(): | if not config_file.is_file(): | ||||
raise FileNotFoundError( | raise FileNotFoundError( | ||||
"The configuration file does not exist {}".format( | "The configuration file does not exist {}".format( | ||||
str(config_file) | str(config_file) | ||||
) | ) | ||||
) | ) | ||||
if build_name is not None: | if build_name is not None: | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | def load(self, build_name): | ||||
) | ) | ||||
) | ) | ||||
def get(self, key, default): | def get(self, key, default): | ||||
return self.config.get(key, default) | return self.config.get(key, default) | ||||
class UserBuild(): | class UserBuild(): | ||||
def __init__(self, configuration, project_root): | def __init__(self, configuration): | ||||
self.configuration = configuration | self.configuration = configuration | ||||
self.project_root = project_root | |||||
project_root = self.configuration.project_root | |||||
# Create the build directory as needed | # Create the build directory as needed | ||||
self.build_directory = Path( | self.build_directory = Path( | ||||
self.project_root.joinpath( | project_root.joinpath( | ||||
'abc-ci-builds', | 'abc-ci-builds', | ||||
self.configuration.name)) | self.configuration.name)) | ||||
self.build_directory.mkdir(exist_ok=True, parents=True) | self.build_directory.mkdir(exist_ok=True, parents=True) | ||||
self.artifact_dir = self.build_directory.joinpath("artifacts") | self.artifact_dir = self.build_directory.joinpath("artifacts") | ||||
self.junit_reports_dir = self.build_directory.joinpath("test/junit") | self.junit_reports_dir = self.build_directory.joinpath("test/junit") | ||||
self.test_logs_dir = self.build_directory.joinpath("test/log") | self.test_logs_dir = self.build_directory.joinpath("test/log") | ||||
# We will provide the required environment variables | # We will provide the required environment variables | ||||
self.environment_variables = { | self.environment_variables = { | ||||
"BUILD_DIR": str(self.build_directory), | "BUILD_DIR": str(self.build_directory), | ||||
"CMAKE_PLATFORMS_DIR": self.project_root.joinpath("cmake", "platforms"), | "CMAKE_PLATFORMS_DIR": project_root.joinpath("cmake", "platforms"), | ||||
"THREADS": str(os.cpu_count() or 1), | "THREADS": str(os.cpu_count() or 1), | ||||
"TOPLEVEL": str(self.project_root), | "TOPLEVEL": str(project_root), | ||||
} | } | ||||
# Build 2 log files: | # Build 2 log files: | ||||
# - the full log will contain all unfiltered content | # - the full log will contain all unfiltered content | ||||
# - the clean log will contain the same filtered content as what is | # - the clean log will contain the same filtered content as what is | ||||
# printed to stdout. This filter is done in print_line_to_logs(). | # printed to stdout. This filter is done in print_line_to_logs(). | ||||
self.logs = {} | self.logs = {} | ||||
self.logs["clean_log"] = self.build_directory.joinpath( | self.logs["clean_log"] = self.build_directory.joinpath( | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | def run(self, args=[]): | ||||
self.configuration.get( | self.configuration.get( | ||||
"timeout", DEFAULT_TIMEOUT)) | "timeout", DEFAULT_TIMEOUT)) | ||||
) | ) | ||||
return (return_code, message) | return (return_code, message) | ||||
class TeamcityBuild(UserBuild): | class TeamcityBuild(UserBuild): | ||||
def __init__(self, configuration, project_root): | def __init__(self, configuration): | ||||
super().__init__(configuration, project_root) | super().__init__(configuration) | ||||
# This accounts for the volume mapping from the container. | # This accounts for the volume mapping from the container. | ||||
# Our local /results is mapped to some relative ./results on the host, | # Our local /results is mapped to some relative ./results on the host, | ||||
# so we use /results/artifacts to copy our files but results/artifacts as | # so we use /results/artifacts to copy our files but results/artifacts as | ||||
# an artifact path for teamcity. | # an artifact path for teamcity. | ||||
# TODO abstract out the volume mapping | # TODO abstract out the volume mapping | ||||
self.artifact_dir = Path("/results/artifacts") | self.artifact_dir = Path("/results/artifacts") | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | def main(): | ||||
args, unknown_args = parser.parse_known_args() | args, unknown_args = parser.parse_known_args() | ||||
# Check the configuration file exists | # Check the configuration file exists | ||||
config_path = Path(args.config) if args.config else default_config_path | config_path = Path(args.config) if args.config else default_config_path | ||||
build_configuration = BuildConfiguration( | build_configuration = BuildConfiguration( | ||||
script_dir, config_path, args.build) | script_dir, config_path, args.build) | ||||
git_root = PurePath( | |||||
subprocess.run( | |||||
['git', 'rev-parse', '--show-toplevel'], | |||||
capture_output=True, | |||||
check=True, | |||||
encoding='utf-8', | |||||
text=True, | |||||
).stdout.strip() | |||||
) | |||||
if is_running_under_teamcity(): | if is_running_under_teamcity(): | ||||
build = TeamcityBuild(build_configuration, git_root) | build = TeamcityBuild(build_configuration) | ||||
else: | else: | ||||
build = UserBuild(build_configuration, git_root) | build = UserBuild(build_configuration) | ||||
sys.exit(build.run(unknown_args)[0]) | sys.exit(build.run(unknown_args)[0]) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |