forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder_from_source.py
65 lines (54 loc) · 2.84 KB
/
builder_from_source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
import os
from build_workflow.build_recorder import BuildRecorder
from build_workflow.builder import Builder
from git.git_repository import GitRepository
from paths.script_finder import ScriptFinder
"""
This class is responsible for executing the build for a component and passing the results to a build recorder.
It will notify the build recorder of build information such as repository and git ref, and any artifacts generated by the build.
Artifacts found in "<build root>/artifacts/<maven|plugins|libs|dist|core-plugins>" will be recognized and recorded.
"""
class BuilderFromSource(Builder):
def checkout(self, work_dir: str) -> None:
self.git_repo = GitRepository(
self.component.repository,
self.component.ref,
os.path.join(work_dir, self.component.name),
self.component.working_directory,
)
def build(self, build_recorder: BuildRecorder) -> None:
# List of components whose build scripts support `-d` parameter
# Bundled plugins do not need `-d` as they are java based zips
DISTRIBUTION_SUPPORTED_COMPONENTS = ["OpenSearch", "OpenSearch-Dashboards"]
build_script = ScriptFinder.find_build_script(self.target.name, self.component.name, self.git_repo.working_directory)
build_command = " ".join(
filter(
None,
[
"bash",
build_script,
f"-v {self.target.version}",
f"-q {self.target.qualifier}" if self.target.qualifier else None,
f"-p {self.target.platform}",
f"-a {self.target.architecture}",
f"-d {self.target.distribution}" if self.component.name in DISTRIBUTION_SUPPORTED_COMPONENTS else None,
f"-s {str(self.target.snapshot).lower()}",
f"-o {self.output_path}",
]
)
)
self.git_repo.execute(build_command)
build_recorder.record_component(self.component.name, self.git_repo)
def export_artifacts(self, build_recorder: BuildRecorder) -> None:
artifacts_path = os.path.join(self.git_repo.working_directory, self.output_path)
for artifact_type in ["maven", "dist", "plugins", "libs", "core-plugins"]:
for dir, _, files in os.walk(os.path.join(artifacts_path, artifact_type)):
for file_name in files:
absolute_path = os.path.join(dir, file_name)
relative_path = os.path.relpath(absolute_path, artifacts_path)
build_recorder.record_artifact(self.component.name, artifact_type, relative_path, absolute_path)