Skip to content

Commit d57bd36

Browse files
authored
pipeline: support additional args in build-using-self (#8559)
Update the build-using-self to support accepting a triple and a build system, which some self hosted CI environments might want to set.
1 parent 174cdc2 commit d57bd36

File tree

2 files changed

+112
-17
lines changed

2 files changed

+112
-17
lines changed

Utilities/build-using-self

Lines changed: 108 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# ===----------------------------------------------------------------------===##
1313

1414
import argparse
15+
import dataclasses
16+
import itertools
1517
import logging
1618
import os
1719
import pathlib
@@ -64,10 +66,22 @@ def get_arguments() -> argparse.Namespace:
6466
"--configuration",
6567
type=Configuration,
6668
dest="config",
67-
default="debug",
68-
choices=[e.value for e in Configuration],
69+
default=Configuration.DEBUG,
70+
choices=[e for e in Configuration],
6971
help="The configuraiton to use.",
7072
)
73+
parser.add_argument(
74+
"-t",
75+
"--triple",
76+
type=str,
77+
dest="triple",
78+
)
79+
parser.add_argument(
80+
"-b",
81+
"--build-system",
82+
type=str,
83+
dest="build_system",
84+
)
7185
parser.add_argument(
7286
"--enable-swift-testing",
7387
action="store_true",
@@ -99,7 +113,10 @@ def is_on_darwin() -> bool:
99113
return platform.uname().system == "Darwin"
100114

101115

102-
def set_environment(*, swiftpm_bin_dir: pathlib.Path,) -> None:
116+
def set_environment(
117+
*,
118+
swiftpm_bin_dir: pathlib.Path,
119+
) -> None:
103120
os.environ["SWIFTCI_IS_SELF_HOSTED"] = "1"
104121

105122
# Set the SWIFTPM_CUSTOM_BIN_DIR path
@@ -131,39 +148,117 @@ def run_bootstrap(swiftpm_bin_dir: pathlib.Path) -> None:
131148
)
132149

133150

151+
GlobalArgsValueType = str
152+
153+
154+
@dataclasses.dataclass
155+
class GlobalArgs:
156+
global_argument: str
157+
value: t.Optional[GlobalArgsValueType]
158+
159+
160+
def filterNone(items: t.Iterable) -> t.Iterable:
161+
return list(filter(lambda x: x is not None, items))
162+
163+
134164
def main() -> None:
135165
args = get_arguments()
136-
ignore = "-Xlinker /ignore:4217" if os.name == "nt" else ""
137166
logging.getLogger().setLevel(logging.DEBUG if args.is_verbose else logging.INFO)
138167
logging.debug("Args: %r", args)
139-
168+
ignore_args = ["-Xlinker", "/ignore:4217"] if os.name == "nt" else []
169+
globalArgsData = [
170+
GlobalArgs(global_argument="--triple", value=args.triple),
171+
GlobalArgs(global_argument="--build-system", value=args.build_system),
172+
]
173+
global_args: t.Iterator[GlobalArgsValueType] = list(
174+
itertools.chain.from_iterable(
175+
[[arg.global_argument, arg.value] for arg in globalArgsData if arg.value]
176+
)
177+
)
178+
logging.debug("Global Args: %r", global_args)
140179
with change_directory(REPO_ROOT_PATH):
141180
swiftpm_bin_dir = get_swiftpm_bin_dir(config=args.config)
142181
set_environment(swiftpm_bin_dir=swiftpm_bin_dir)
143182

144183
call(
145-
shlex.split("swift --version"),
184+
filterNone(
185+
[
186+
"swift",
187+
"--version",
188+
]
189+
)
146190
)
147191

148192
call(
149-
shlex.split("swift package update"),
193+
filterNone(
194+
[
195+
"swift",
196+
"package",
197+
"update",
198+
]
199+
)
150200
)
151201
call(
152-
shlex.split(f"swift build --configuration {args.config} {ignore}"),
202+
filterNone(
203+
[
204+
"swift",
205+
"build",
206+
*global_args,
207+
"--configuration",
208+
args.config,
209+
*ignore_args,
210+
]
211+
)
153212
)
154213

155-
swift_testing_arg= "--enable-swift-testing" if args.enable_swift_testing else ""
156-
xctest_arg= "--enable-xctest" if args.enable_swift_testing else ""
214+
swift_testing_arg = (
215+
"--enable-swift-testing" if args.enable_swift_testing else None
216+
)
217+
xctest_arg = "--enable-xctest" if args.enable_swift_testing else None
157218
call(
158-
shlex.split(f"swift run swift-test --configuration {args.config} --parallel {swift_testing_arg} {xctest_arg} --scratch-path .test {ignore}"),
219+
filterNone(
220+
[
221+
"swift",
222+
"run",
223+
"swift-test",
224+
*global_args,
225+
"--configuration",
226+
args.config,
227+
"--parallel",
228+
swift_testing_arg,
229+
xctest_arg,
230+
"--scratch-path",
231+
".test",
232+
*ignore_args,
233+
]
234+
)
159235
)
160236

161237
integration_test_dir = (REPO_ROOT_PATH / "IntegrationTests").as_posix()
162238
call(
163-
shlex.split(f"swift package --package-path {integration_test_dir} update"),
239+
filterNone(
240+
[
241+
"swift",
242+
"package",
243+
"--package-path",
244+
integration_test_dir,
245+
"update",
246+
]
247+
)
164248
)
165249
call(
166-
shlex.split(f"swift run swift-test --package-path {integration_test_dir} --parallel {ignore}"),
250+
filterNone(
251+
[
252+
"swift",
253+
"run",
254+
"swift-test",
255+
*global_args,
256+
"--package-path",
257+
integration_test_dir,
258+
"--parallel",
259+
*ignore_args,
260+
]
261+
)
167262
)
168263

169264
if is_on_darwin():

Utilities/helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ def mkdir_p(path):
6565
def call(cmd, cwd=None, verbose=False):
6666
"""Calls a subprocess."""
6767
cwd = cwd or pathlib.Path.cwd()
68-
logging.info("executing command >>> %r with cwd %s", " ".join([str(c) for c in cmd]), cwd)
6968
try:
69+
logging.info("executing command >>> %r with cwd %s", cmd, cwd)
7070
subprocess.check_call(cmd, cwd=cwd)
7171
except subprocess.CalledProcessError as cpe:
72-
logging.debug("executing command >>> %r with cwd %s", " ".join([str(c) for c in cmd]), cwd)
72+
logging.debug("executing command >>> %r with cwd %s", cmd, cwd)
7373
logging.error(
7474
"\n".join([
7575
"Process failure with return code %d: %s",
@@ -96,7 +96,7 @@ def call_output(cmd, cwd=None, stderr=False, verbose=False):
9696
"""Calls a subprocess for its return data."""
9797
stderr = subprocess.STDOUT if stderr else False
9898
cwd = cwd or pathlib.Path.cwd()
99-
logging.info("executing command >>> %r with cwd %s", " ".join([str(c) for c in cmd]), cwd)
99+
logging.info("executing command >>> %r with cwd %s", cmd, cwd)
100100
try:
101101
return subprocess.check_output(
102102
cmd,
@@ -105,7 +105,7 @@ def call_output(cmd, cwd=None, stderr=False, verbose=False):
105105
universal_newlines=True,
106106
).strip()
107107
except subprocess.CalledProcessError as cpe:
108-
logging.debug("executing command >>> %r with cwd %s", " ".join([str(c) for c in cmd]), cwd)
108+
logging.debug("executing command >>> %r with cwd %s", cmd, cwd)
109109
logging.error(
110110
"\n".join([
111111
"Process failure with return code %d: %s",

0 commit comments

Comments
 (0)