forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_args.py
121 lines (114 loc) · 3.38 KB
/
build_args.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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 argparse
import logging
import sys
from typing import IO, List
class BuildArgs:
SUPPORTED_PLATFORMS = ["linux", "darwin", "windows"]
SUPPORTED_ARCHITECTURES = [
"x64",
"arm64",
]
SUPPORTED_DISTRIBUTIONS = ["tar", "zip", "rpm"]
manifest: IO
snapshot: bool
components: List[str]
keep: bool
platform: str
architecture: str
distribution: str
def __init__(self) -> None:
parser = argparse.ArgumentParser(description="Build an OpenSearch Distribution")
parser.add_argument(
"manifest",
type=argparse.FileType("r"),
help="Manifest file."
)
parser.add_argument(
"-l",
"--lock",
dest="lock",
action="store_true",
default=False,
help="Generate a stable reference manifest."
)
parser.add_argument(
"-s",
"--snapshot",
action="store_true",
default=False,
help="Build snapshot.",
)
parser.add_argument(
"-c",
"--component",
dest="components",
nargs='*',
type=str,
help="Rebuild one or more components."
)
parser.add_argument(
"--keep",
dest="keep",
action="store_true",
help="Do not delete the working temporary directory.",
)
parser.add_argument(
"-p",
"--platform",
type=str,
choices=self.SUPPORTED_PLATFORMS,
help="Platform to build."
)
parser.add_argument(
"-a",
"--architecture",
type=str,
choices=self.SUPPORTED_ARCHITECTURES,
help="Architecture to build."
)
parser.add_argument(
"-v",
"--verbose",
help="Show more verbose output.",
action="store_const",
default=logging.INFO,
const=logging.DEBUG,
dest="logging_level",
)
parser.add_argument(
"-d",
"--distribution",
type=str,
choices=self.SUPPORTED_DISTRIBUTIONS,
help="Distribution to build.",
default="tar",
dest="distribution"
)
args = parser.parse_args()
self.logging_level = args.logging_level
self.manifest = args.manifest
self.ref_manifest = args.manifest.name + ".lock" if args.lock else None
self.snapshot = args.snapshot
self.components = args.components
self.keep = args.keep
self.platform = args.platform
self.architecture = args.architecture
self.distribution = args.distribution
self.script_path = sys.argv[0].replace("/src/run_build.py", "/build.sh")
def component_command(self, name: str) -> str:
return " ".join(
filter(
None,
[
self.script_path,
self.manifest.name,
f"--component {name}",
"--snapshot" if self.snapshot else None,
],
)
)