Changeset View
Changeset View
Standalone View
Standalone View
contrib/teamcity/build-configurations.py
Show First 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | def load(self, build_name): | ||||
# 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": self.project_root.joinpath("cmake", "platforms"), | ||||
"THREADS": str(self.jobs), | "THREADS": str(self.jobs), | ||||
"TOPLEVEL": str(self.project_root), | "TOPLEVEL": str(self.project_root), | ||||
} | } | ||||
def create_script_file(self, dest, content): | |||||
# Write the content to a script file using a template | |||||
with open(self.script_root.joinpath("bash_script.sh.in"), encoding='utf-8') as f: | |||||
script_template_content = f.read() | |||||
template = Template(script_template_content) | |||||
with open(dest, 'w', encoding='utf-8') as f: | |||||
f.write( | |||||
template.safe_substitute( | |||||
**self.environment_variables, | |||||
SCRIPT_CONTENT=content, | |||||
) | |||||
) | |||||
dest.chmod(dest.stat().st_mode | stat.S_IEXEC) | |||||
def create_build_steps(self, artifact_dir): | def create_build_steps(self, artifact_dir): | ||||
# There are 2 possibilities to define the build steps: | # There are 2 possibilities to define the build steps: | ||||
# - By defining a script to run. If such a script is set and is | # - By manually defining a script to run. | ||||
# executable, it is the only thing to run. | |||||
# - By defining the configuration options and a list of target groups to | # - By defining the configuration options and a list of target groups to | ||||
# run. The configuration step should be run once then all the targets | # run. The configuration step should be run once then all the targets | ||||
# groups. Each target group can contain 1 or more targets which | # groups. Each target group can contain 1 or more targets which | ||||
# should be run parallel. | # should be run parallel. | ||||
script = self.config.get("script", None) | script = self.config.get("script", None) | ||||
if script: | if script: | ||||
script_path = Path(self.project_root.joinpath(script)) | script_file = self.build_directory.joinpath("script.sh") | ||||
if not script_path.is_file() or not os.access(script_path, os.X_OK): | self.create_script_file(script_file, script) | ||||
raise FileNotFoundError( | |||||
"The script file {} does not exist or does not have execution permission".format( | |||||
str(script_path) | |||||
) | |||||
) | |||||
self.build_steps = [ | self.build_steps = [ | ||||
{ | { | ||||
"bin": str(script_path), | "bin": str(script_file), | ||||
"args": [], | "args": [], | ||||
} | } | ||||
] | ] | ||||
return | return | ||||
# Get the cmake configuration definitions. | # Get the cmake configuration definitions. | ||||
self.cmake_flags = self.config.get("cmake_flags", []) | self.cmake_flags = self.config.get("cmake_flags", []) | ||||
self.cmake_flags.append("-DCMAKE_INSTALL_PREFIX={}".format( | self.cmake_flags.append("-DCMAKE_INSTALL_PREFIX={}".format( | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | def create_build_steps(self, artifact_dir): | ||||
"bin": generator_command, | "bin": generator_command, | ||||
"args": generator_flags + target_group, | "args": generator_flags + target_group, | ||||
} | } | ||||
) | ) | ||||
# If a post build script is defined, add it as a last step | # If a post build script is defined, add it as a last step | ||||
post_build = self.config.get("post_build", None) | post_build = self.config.get("post_build", None) | ||||
if post_build: | if post_build: | ||||
# Write the content to a script file using a template | |||||
script_file = self.build_directory.joinpath("post_build.sh") | script_file = self.build_directory.joinpath("post_build.sh") | ||||
self.create_script_file(script_file, post_build) | |||||
with open(self.script_root.joinpath("bash_script.sh.in"), encoding='utf-8') as f: | |||||
script_template_content = f.read() | |||||
template = Template(script_template_content) | |||||
with open(script_file, 'w', encoding='utf-8') as f: | |||||
f.write( | |||||
template.safe_substitute( | |||||
**self.environment_variables, | |||||
SCRIPT_CONTENT=post_build, | |||||
) | |||||
) | |||||
script_file.chmod(script_file.stat().st_mode | stat.S_IEXEC) | |||||
self.build_steps.append( | self.build_steps.append( | ||||
{ | { | ||||
"bin": str(script_file), | "bin": str(script_file), | ||||
"args": [], | "args": [], | ||||
} | } | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 297 Lines • Show Last 20 Lines |