|
12 | 12 | # ===----------------------------------------------------------------------===##
|
13 | 13 |
|
14 | 14 | import argparse
|
| 15 | +import dataclasses |
| 16 | +import itertools |
15 | 17 | import logging
|
16 | 18 | import os
|
17 | 19 | import pathlib
|
@@ -64,10 +66,22 @@ def get_arguments() -> argparse.Namespace:
|
64 | 66 | "--configuration",
|
65 | 67 | type=Configuration,
|
66 | 68 | dest="config",
|
67 |
| - default="debug", |
68 |
| - choices=[e.value for e in Configuration], |
| 69 | + default=Configuration.DEBUG, |
| 70 | + choices=[e for e in Configuration], |
69 | 71 | help="The configuraiton to use.",
|
70 | 72 | )
|
| 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 | + ) |
71 | 85 | parser.add_argument(
|
72 | 86 | "--enable-swift-testing",
|
73 | 87 | action="store_true",
|
@@ -99,7 +113,10 @@ def is_on_darwin() -> bool:
|
99 | 113 | return platform.uname().system == "Darwin"
|
100 | 114 |
|
101 | 115 |
|
102 |
| -def set_environment(*, swiftpm_bin_dir: pathlib.Path,) -> None: |
| 116 | +def set_environment( |
| 117 | + *, |
| 118 | + swiftpm_bin_dir: pathlib.Path, |
| 119 | +) -> None: |
103 | 120 | os.environ["SWIFTCI_IS_SELF_HOSTED"] = "1"
|
104 | 121 |
|
105 | 122 | # Set the SWIFTPM_CUSTOM_BIN_DIR path
|
@@ -131,39 +148,117 @@ def run_bootstrap(swiftpm_bin_dir: pathlib.Path) -> None:
|
131 | 148 | )
|
132 | 149 |
|
133 | 150 |
|
| 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 | + |
134 | 164 | def main() -> None:
|
135 | 165 | args = get_arguments()
|
136 |
| - ignore = "-Xlinker /ignore:4217" if os.name == "nt" else "" |
137 | 166 | logging.getLogger().setLevel(logging.DEBUG if args.is_verbose else logging.INFO)
|
138 | 167 | 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) |
140 | 179 | with change_directory(REPO_ROOT_PATH):
|
141 | 180 | swiftpm_bin_dir = get_swiftpm_bin_dir(config=args.config)
|
142 | 181 | set_environment(swiftpm_bin_dir=swiftpm_bin_dir)
|
143 | 182 |
|
144 | 183 | call(
|
145 |
| - shlex.split("swift --version"), |
| 184 | + filterNone( |
| 185 | + [ |
| 186 | + "swift", |
| 187 | + "--version", |
| 188 | + ] |
| 189 | + ) |
146 | 190 | )
|
147 | 191 |
|
148 | 192 | call(
|
149 |
| - shlex.split("swift package update"), |
| 193 | + filterNone( |
| 194 | + [ |
| 195 | + "swift", |
| 196 | + "package", |
| 197 | + "update", |
| 198 | + ] |
| 199 | + ) |
150 | 200 | )
|
151 | 201 | 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 | + ) |
153 | 212 | )
|
154 | 213 |
|
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 |
157 | 218 | 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 | + ) |
159 | 235 | )
|
160 | 236 |
|
161 | 237 | integration_test_dir = (REPO_ROOT_PATH / "IntegrationTests").as_posix()
|
162 | 238 | 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 | + ) |
164 | 248 | )
|
165 | 249 | 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 | + ) |
167 | 262 | )
|
168 | 263 |
|
169 | 264 | if is_on_darwin():
|
|
0 commit comments