We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] Only send `-d` to core components, instead of everything.
As of now, build workflow will not send `-d` if user does not specify `--distribution`.
However, if user specify things such as `--distribution rpm` and try to build core+all plugins,
`-d` will be sent to plugins as well.

The plugin build script does not know how to interpret `-d` thus fail.
```
+ echo 'Invalid option: -?'
Invalid option: -?
+ exit 1
2022-02-17 23:58:36 ERROR    Error building common-utils, retry with: ./build.sh manifests/1.3.0/opensearch-1.3.0.yml --component common-utils
Traceback (most recent call last):
  File "./src/run_build.py", line 79, in <module>
    sys.exit(main())
  File "./src/run_build.py", line 67, in main
    builder.build(build_recorder)
  File "/local/home/zhujiaxi/opensearch-build-peterzhuamazon/src/build_workflow/builder_from_source.py", line 49, in build
    self.git_repo.execute(build_command)
  File "/local/home/zhujiaxi/opensearch-build-peterzhuamazon/src/git/git_repository.py", line 83, in execute
    subprocess.check_call(command, cwd=cwd, shell=True)
  File "/usr/lib64/python3.7/subprocess.py", line 363, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'bash /local/home/zhujiaxi/opensearch-build-peterzhuamazon/scripts/components/common-utils/build.sh -v 1.3.0 -p linux -a x64 -d rpm -s false -o builds' returned non-zero exit status 1.
```

Need to add a condition where if component != OpenSearch/OpenSearch-Dashboards, then `-d` will not be sent even if not None.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/build_workflow/builder_from_source.py`
Content:
```
1 # SPDX-License-Identifier: Apache-2.0
2 #
3 # The OpenSearch Contributors require contributions made to
4 # this file be licensed under the Apache-2.0 license or a
5 # compatible open source license.
6 
7 import os
8 
9 from build_workflow.build_recorder import BuildRecorder
10 from build_workflow.builder import Builder
11 from git.git_repository import GitRepository
12 from paths.script_finder import ScriptFinder
13 
14 """
15 This class is responsible for executing the build for a component and passing the results to a build recorder.
16 It will notify the build recorder of build information such as repository and git ref, and any artifacts generated by the build.
17 Artifacts found in "<build root>/artifacts/<maven|plugins|libs|dist|core-plugins>" will be recognized and recorded.
18 """
19 
20 
21 class BuilderFromSource(Builder):
22     def checkout(self, work_dir: str) -> None:
23         self.git_repo = GitRepository(
24             self.component.repository,
25             self.component.ref,
26             os.path.join(work_dir, self.component.name),
27             self.component.working_directory,
28         )
29 
30     def build(self, build_recorder: BuildRecorder) -> None:
31         build_script = ScriptFinder.find_build_script(self.target.name, self.component.name, self.git_repo.working_directory)
32 
33         build_command = " ".join(
34             filter(
35                 None,
36                 [
37                     "bash",
38                     build_script,
39                     f"-v {self.target.version}",
40                     f"-p {self.target.platform}",
41                     f"-a {self.target.architecture}",
42                     f"-d {self.target.distribution}" if self.target.distribution else None,
43                     f"-s {str(self.target.snapshot).lower()}",
44                     f"-o {self.output_path}",
45                 ]
46             )
47         )
48 
49         self.git_repo.execute(build_command)
50         build_recorder.record_component(self.component.name, self.git_repo)
51 
52     def export_artifacts(self, build_recorder: BuildRecorder) -> None:
53         artifacts_path = os.path.join(self.git_repo.working_directory, self.output_path)
54         for artifact_type in ["maven", "dist", "plugins", "libs", "core-plugins"]:
55             for dir, _, files in os.walk(os.path.join(artifacts_path, artifact_type)):
56                 for file_name in files:
57                     absolute_path = os.path.join(dir, file_name)
58                     relative_path = os.path.relpath(absolute_path, artifacts_path)
59                     build_recorder.record_artifact(self.component.name, artifact_type, relative_path, absolute_path)
60
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/build_workflow/builder_from_source.py b/src/build_workflow/builder_from_source.py
--- a/src/build_workflow/builder_from_source.py
+++ b/src/build_workflow/builder_from_source.py
@@ -28,6 +28,11 @@
         )
 
     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(
@@ -39,7 +44,7 @@
                     f"-v {self.target.version}",
                     f"-p {self.target.platform}",
                     f"-a {self.target.architecture}",
-                    f"-d {self.target.distribution}" if self.target.distribution else None,
+                    f"-d {self.target.distribution}" if self.target.distribution and (self.component.name in DISTRIBUTION_SUPPORTED_COMPONENTS) else None,
                     f"-s {str(self.target.snapshot).lower()}",
                     f"-o {self.output_path}",
                 ]

{"golden_diff": "diff --git a/src/build_workflow/builder_from_source.py b/src/build_workflow/builder_from_source.py\n--- a/src/build_workflow/builder_from_source.py\n+++ b/src/build_workflow/builder_from_source.py\n@@ -28,6 +28,11 @@\n         )\n \n     def build(self, build_recorder: BuildRecorder) -> None:\n+\n+        # List of components whose build scripts support `-d` parameter\n+        # Bundled plugins do not need `-d` as they are java based zips\n+        DISTRIBUTION_SUPPORTED_COMPONENTS = [\"OpenSearch\", \"OpenSearch-Dashboards\"]\n+\n         build_script = ScriptFinder.find_build_script(self.target.name, self.component.name, self.git_repo.working_directory)\n \n         build_command = \" \".join(\n@@ -39,7 +44,7 @@\n                     f\"-v {self.target.version}\",\n                     f\"-p {self.target.platform}\",\n                     f\"-a {self.target.architecture}\",\n-                    f\"-d {self.target.distribution}\" if self.target.distribution else None,\n+                    f\"-d {self.target.distribution}\" if self.target.distribution and (self.component.name in DISTRIBUTION_SUPPORTED_COMPONENTS) else None,\n                     f\"-s {str(self.target.snapshot).lower()}\",\n                     f\"-o {self.output_path}\",\n                 ]\n", "issue": "[BUG] Only send `-d` to core components, instead of everything.\nAs of now, build workflow will not send `-d` if user does not specify `--distribution`.\r\nHowever, if user specify things such as `--distribution rpm` and try to build core+all plugins,\r\n`-d` will be sent to plugins as well.\r\n\r\nThe plugin build script does not know how to interpret `-d` thus fail.\r\n```\r\n+ echo 'Invalid option: -?'\r\nInvalid option: -?\r\n+ exit 1\r\n2022-02-17 23:58:36 ERROR    Error building common-utils, retry with: ./build.sh manifests/1.3.0/opensearch-1.3.0.yml --component common-utils\r\nTraceback (most recent call last):\r\n  File \"./src/run_build.py\", line 79, in <module>\r\n    sys.exit(main())\r\n  File \"./src/run_build.py\", line 67, in main\r\n    builder.build(build_recorder)\r\n  File \"/local/home/zhujiaxi/opensearch-build-peterzhuamazon/src/build_workflow/builder_from_source.py\", line 49, in build\r\n    self.git_repo.execute(build_command)\r\n  File \"/local/home/zhujiaxi/opensearch-build-peterzhuamazon/src/git/git_repository.py\", line 83, in execute\r\n    subprocess.check_call(command, cwd=cwd, shell=True)\r\n  File \"/usr/lib64/python3.7/subprocess.py\", line 363, in check_call\r\n    raise CalledProcessError(retcode, cmd)\r\nsubprocess.CalledProcessError: Command 'bash /local/home/zhujiaxi/opensearch-build-peterzhuamazon/scripts/components/common-utils/build.sh -v 1.3.0 -p linux -a x64 -d rpm -s false -o builds' returned non-zero exit status 1.\r\n```\r\n\r\nNeed to add a condition where if component != OpenSearch/OpenSearch-Dashboards, then `-d` will not be sent even if not None.\n", "before_files": [{"content": "# SPDX-License-Identifier: Apache-2.0\n#\n# The OpenSearch Contributors require contributions made to\n# this file be licensed under the Apache-2.0 license or a\n# compatible open source license.\n\nimport os\n\nfrom build_workflow.build_recorder import BuildRecorder\nfrom build_workflow.builder import Builder\nfrom git.git_repository import GitRepository\nfrom paths.script_finder import ScriptFinder\n\n\"\"\"\nThis class is responsible for executing the build for a component and passing the results to a build recorder.\nIt will notify the build recorder of build information such as repository and git ref, and any artifacts generated by the build.\nArtifacts found in \"<build root>/artifacts/<maven|plugins|libs|dist|core-plugins>\" will be recognized and recorded.\n\"\"\"\n\n\nclass BuilderFromSource(Builder):\n    def checkout(self, work_dir: str) -> None:\n        self.git_repo = GitRepository(\n            self.component.repository,\n            self.component.ref,\n            os.path.join(work_dir, self.component.name),\n            self.component.working_directory,\n        )\n\n    def build(self, build_recorder: BuildRecorder) -> None:\n        build_script = ScriptFinder.find_build_script(self.target.name, self.component.name, self.git_repo.working_directory)\n\n        build_command = \" \".join(\n            filter(\n                None,\n                [\n                    \"bash\",\n                    build_script,\n                    f\"-v {self.target.version}\",\n                    f\"-p {self.target.platform}\",\n                    f\"-a {self.target.architecture}\",\n                    f\"-d {self.target.distribution}\" if self.target.distribution else None,\n                    f\"-s {str(self.target.snapshot).lower()}\",\n                    f\"-o {self.output_path}\",\n                ]\n            )\n        )\n\n        self.git_repo.execute(build_command)\n        build_recorder.record_component(self.component.name, self.git_repo)\n\n    def export_artifacts(self, build_recorder: BuildRecorder) -> None:\n        artifacts_path = os.path.join(self.git_repo.working_directory, self.output_path)\n        for artifact_type in [\"maven\", \"dist\", \"plugins\", \"libs\", \"core-plugins\"]:\n            for dir, _, files in os.walk(os.path.join(artifacts_path, artifact_type)):\n                for file_name in files:\n                    absolute_path = os.path.join(dir, file_name)\n                    relative_path = os.path.relpath(absolute_path, artifacts_path)\n                    build_recorder.record_artifact(self.component.name, artifact_type, relative_path, absolute_path)\n", "path": "src/build_workflow/builder_from_source.py"}], "after_files": [{"content": "# SPDX-License-Identifier: Apache-2.0\n#\n# The OpenSearch Contributors require contributions made to\n# this file be licensed under the Apache-2.0 license or a\n# compatible open source license.\n\nimport os\n\nfrom build_workflow.build_recorder import BuildRecorder\nfrom build_workflow.builder import Builder\nfrom git.git_repository import GitRepository\nfrom paths.script_finder import ScriptFinder\n\n\"\"\"\nThis class is responsible for executing the build for a component and passing the results to a build recorder.\nIt will notify the build recorder of build information such as repository and git ref, and any artifacts generated by the build.\nArtifacts found in \"<build root>/artifacts/<maven|plugins|libs|dist|core-plugins>\" will be recognized and recorded.\n\"\"\"\n\n\nclass BuilderFromSource(Builder):\n    def checkout(self, work_dir: str) -> None:\n        self.git_repo = GitRepository(\n            self.component.repository,\n            self.component.ref,\n            os.path.join(work_dir, self.component.name),\n            self.component.working_directory,\n        )\n\n    def build(self, build_recorder: BuildRecorder) -> None:\n\n        # List of components whose build scripts support `-d` parameter\n        # Bundled plugins do not need `-d` as they are java based zips\n        DISTRIBUTION_SUPPORTED_COMPONENTS = [\"OpenSearch\", \"OpenSearch-Dashboards\"]\n\n        build_script = ScriptFinder.find_build_script(self.target.name, self.component.name, self.git_repo.working_directory)\n\n        build_command = \" \".join(\n            filter(\n                None,\n                [\n                    \"bash\",\n                    build_script,\n                    f\"-v {self.target.version}\",\n                    f\"-p {self.target.platform}\",\n                    f\"-a {self.target.architecture}\",\n                    f\"-d {self.target.distribution}\" if self.target.distribution and (self.component.name in DISTRIBUTION_SUPPORTED_COMPONENTS) else None,\n                    f\"-s {str(self.target.snapshot).lower()}\",\n                    f\"-o {self.output_path}\",\n                ]\n            )\n        )\n\n        self.git_repo.execute(build_command)\n        build_recorder.record_component(self.component.name, self.git_repo)\n\n    def export_artifacts(self, build_recorder: BuildRecorder) -> None:\n        artifacts_path = os.path.join(self.git_repo.working_directory, self.output_path)\n        for artifact_type in [\"maven\", \"dist\", \"plugins\", \"libs\", \"core-plugins\"]:\n            for dir, _, files in os.walk(os.path.join(artifacts_path, artifact_type)):\n                for file_name in files:\n                    absolute_path = os.path.join(dir, file_name)\n                    relative_path = os.path.relpath(absolute_path, artifacts_path)\n                    build_recorder.record_artifact(self.component.name, artifact_type, relative_path, absolute_path)\n", "path": "src/build_workflow/builder_from_source.py"}]}