Skip to content

Commit fd11f0d

Browse files
committed
Update build-using-self to pass global arguments to all SwiftPM commands
1 parent 046dd7e commit fd11f0d

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

Utilities/build-using-self

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ from datetime import datetime
2525
import typing as t
2626

2727
from helpers import (
28-
Configuration,
2928
change_directory,
3029
call,
3130
call_output,
@@ -71,10 +70,8 @@ def get_arguments() -> argparse.Namespace:
7170
parser.add_argument(
7271
"-c",
7372
"--configuration",
74-
type=Configuration,
73+
type=str,
7574
dest="config",
76-
default=Configuration.DEBUG,
77-
choices=[e for e in Configuration],
7875
help="The configuration to use.",
7976
)
8077
parser.add_argument(
@@ -89,6 +86,12 @@ def get_arguments() -> argparse.Namespace:
8986
type=str,
9087
dest="build_system",
9188
)
89+
parser.add_argument(
90+
"--skip-clean",
91+
action="store_false",
92+
dest="should_clean",
93+
help="When set, do not clean the build output"
94+
)
9295
parser.add_argument(
9396
"--additional-build-args",
9497
type=str,
@@ -123,10 +126,12 @@ def log_environment() -> None:
123126
logging.info(" --> %s=%r", key, value)
124127

125128

126-
def get_swiftpm_bin_dir(config: Configuration) -> pathlib.Path:
129+
def get_swiftpm_bin_dir(
130+
global_args: t.List[str],
131+
) -> pathlib.Path:
127132
logging.info("Retrieving Swift PM binary directory.")
128133
swiftpm_bin_dir = pathlib.Path(
129-
call_output(["swift", "build", "--configuration", config, "--show-bin-path"])
134+
call_output(["swift", "build", *global_args, "--show-bin-path"])
130135
)
131136
logging.info("SwiftPM BIN DIR: %s", swiftpm_bin_dir)
132137
return swiftpm_bin_dir
@@ -136,10 +141,7 @@ def is_on_darwin() -> bool:
136141
return platform.system() == "Darwin"
137142

138143

139-
def set_environment(
140-
*,
141-
swiftpm_bin_dir: pathlib.Path,
142-
) -> None:
144+
def set_environment() -> None:
143145
os.environ["SWIFTCI_IS_SELF_HOSTED"] = "1"
144146

145147
# Ensure SDKROOT is configure
@@ -198,6 +200,7 @@ def main() -> None:
198200
globalArgsData = [
199201
GlobalArgs(global_argument="--triple", value=args.triple),
200202
GlobalArgs(global_argument="--build-system", value=args.build_system),
203+
GlobalArgs(global_argument="--configuration", value=args.config),
201204
]
202205
global_args: t.Iterator[GlobalArgsValueType] = list(
203206
itertools.chain.from_iterable(
@@ -207,8 +210,8 @@ def main() -> None:
207210
logging.debug("Global Args: %r", global_args)
208211
start_time = datetime.now()
209212
with change_directory(REPO_ROOT_PATH):
210-
swiftpm_bin_dir = get_swiftpm_bin_dir(config=args.config)
211-
set_environment(swiftpm_bin_dir=swiftpm_bin_dir)
213+
swiftpm_bin_dir = get_swiftpm_bin_dir(global_args=global_args)
214+
set_environment()
212215

213216
call(
214217
filterIsTruthy(
@@ -219,43 +222,70 @@ def main() -> None:
219222
)
220223
)
221224

225+
if args.should_clean:
226+
call(
227+
filterIsTruthy(
228+
[
229+
"swift",
230+
"package",
231+
*global_args,
232+
"clean",
233+
]
234+
)
235+
)
236+
222237
call(
223238
filterIsTruthy(
224239
[
225240
"swift",
226241
"package",
242+
*global_args,
227243
"update",
228244
]
229245
)
230246
)
247+
231248
call(
232249
filterIsTruthy(
233250
[
234251
"swift",
235252
"build",
236253
*global_args,
237-
"--configuration",
238-
args.config,
239254
*ignore_args,
240255
*args.additional_build_args.split(" ")
241256
]
242257
)
243258
)
259+
260+
call(
261+
filterIsTruthy(
262+
[
263+
swiftpm_bin_dir / "swift-build",
264+
*global_args,
265+
*ignore_args,
266+
"--very-verbose",
267+
"--force-resolved-versions",
268+
"--scratch-path",
269+
".build-swb",
270+
*args.additional_build_args.split(" ")
271+
]
272+
)
273+
)
274+
244275
call(
245276
filterIsTruthy(
246277
[
247278
"swift",
248279
"run",
280+
*global_args,
249281
*ignore_args,
250-
*args.additional_run_args.split(" "),
251282
"swift-test",
252283
*global_args,
253-
"--configuration",
254-
args.config,
284+
*ignore_args,
285+
"--force-resolved-versions",
255286
"--parallel",
256287
"--scratch-path",
257288
".test",
258-
*ignore_args,
259289
*args.additional_test_args.split(" ")
260290
]
261291
)

0 commit comments

Comments
 (0)