@@ -25,7 +25,6 @@ from datetime import datetime
2525import typing as t
2626
2727from 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,86 @@ 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+ out_dir = call_output (
261+ filterIsTruthy (
262+ [
263+ "swift" ,
264+ "build" ,
265+ * global_args ,
266+ * ignore_args ,
267+ "--show-bin-path"
268+ ]
269+ )
270+ )
271+ logging .debug ("Build path directory : %s" , out_dir )
272+ logging .debug ("Listing files in directory: %s" , out_dir )
273+ for item in sorted (os .listdir (path = out_dir )):
274+ logging .debug (" -> %s" , item )
275+
276+ call (
277+ filterIsTruthy (
278+ [
279+ swiftpm_bin_dir / "swift-build" ,
280+ * global_args ,
281+ * ignore_args ,
282+ "--very-verbose" ,
283+ "--force-resolved-versions" ,
284+ "--scratch-path" ,
285+ ".build-swb" ,
286+ * args .additional_build_args .split (" " )
287+ ]
288+ )
289+ )
290+
244291 call (
245292 filterIsTruthy (
246293 [
247294 "swift" ,
248295 "run" ,
296+ * global_args ,
249297 * ignore_args ,
250- * args .additional_run_args .split (" " ),
251298 "swift-test" ,
252299 * global_args ,
253- "--configuration" ,
254- args . config ,
300+ * ignore_args ,
301+ "--force-resolved-versions" ,
255302 "--parallel" ,
256303 "--scratch-path" ,
257304 ".test" ,
258- * ignore_args ,
259305 * args .additional_test_args .split (" " )
260306 ]
261307 )
0 commit comments