Skip to content

Commit 947bc5d

Browse files
Add distribution supported components list so only specific scripts can take -d parameter (#1652)
* Add distribution supported components list so only specific scripts can take parameter Signed-off-by: Peter Zhu <[email protected]> * Remove extra spaces Signed-off-by: Peter Zhu <[email protected]>
1 parent 504427b commit 947bc5d

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/build_workflow/builder_from_source.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ def checkout(self, work_dir: str) -> None:
2828
)
2929

3030
def build(self, build_recorder: BuildRecorder) -> None:
31+
32+
# List of components whose build scripts support `-d` parameter
33+
# Bundled plugins do not need `-d` as they are java based zips
34+
DISTRIBUTION_SUPPORTED_COMPONENTS = ["OpenSearch", "OpenSearch-Dashboards"]
35+
3136
build_script = ScriptFinder.find_build_script(self.target.name, self.component.name, self.git_repo.working_directory)
3237

3338
build_command = " ".join(
@@ -39,7 +44,7 @@ def build(self, build_recorder: BuildRecorder) -> None:
3944
f"-v {self.target.version}",
4045
f"-p {self.target.platform}",
4146
f"-a {self.target.architecture}",
42-
f"-d {self.target.distribution}" if self.target.distribution else None,
47+
f"-d {self.target.distribution}" if self.target.distribution and (self.component.name in DISTRIBUTION_SUPPORTED_COMPONENTS) else None,
4348
f"-s {str(self.target.snapshot).lower()}",
4449
f"-o {self.output_path}",
4550
]

tests/tests_build_workflow/test_builder_from_source.py

+33
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ def setUp(self) -> None:
4040
),
4141
)
4242

43+
self.builder_distribution_support = BuilderFromSource(
44+
InputComponentFromSource({"name": "common-utils", "repository": "url", "ref": "ref"}),
45+
BuildTarget(
46+
name="OpenSearch",
47+
version="1.3.0",
48+
platform="linux",
49+
architecture="x64",
50+
distribution="rpm",
51+
snapshot=False,
52+
),
53+
)
54+
4355
def test_builder(self) -> None:
4456
self.assertEqual(self.builder.component.name, "common-utils")
4557

@@ -86,6 +98,27 @@ def test_build_distribution(self, mock_git_repo: Mock) -> None:
8698
)
8799
build_recorder.record_component.assert_called_with("OpenSearch", mock_git_repo.return_value)
88100

101+
@patch("build_workflow.builder_from_source.GitRepository")
102+
def test_build_distribution_support(self, mock_git_repo: Mock) -> None:
103+
mock_git_repo.return_value = MagicMock(working_directory="dir")
104+
build_recorder = MagicMock()
105+
self.builder_distribution_support.checkout("dir")
106+
self.builder_distribution_support.build(build_recorder)
107+
mock_git_repo.return_value.execute.assert_called_with(
108+
" ".join(
109+
[
110+
"bash",
111+
os.path.realpath(os.path.join(ScriptFinder.component_scripts_path, "common-utils", "build.sh")),
112+
"-v 1.3.0",
113+
"-p linux",
114+
"-a x64",
115+
"-s false",
116+
"-o builds",
117+
]
118+
)
119+
)
120+
build_recorder.record_component.assert_called_with("common-utils", mock_git_repo.return_value)
121+
89122
@patch("build_workflow.builder_from_source.GitRepository")
90123
def test_build_snapshot(self, mock_git_repo: Mock) -> None:
91124
self.builder.target.snapshot = True

0 commit comments

Comments
 (0)