17
17
18
18
19
19
CHECKOUT = pathlib .Path (__file__ ).parent .parent .parent
20
+
20
21
CROSS_BUILD_DIR = CHECKOUT / "cross-build"
21
22
BUILD_DIR = CROSS_BUILD_DIR / "build"
22
23
HOST_TRIPLE = "wasm32-wasi"
23
24
HOST_DIR = CROSS_BUILD_DIR / HOST_TRIPLE
24
25
26
+ LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
27
+ LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n " .encode ("utf-8" )
28
+
25
29
26
30
def updated_env (updates = {}):
27
31
"""Create a new dict representing the environment to use.
@@ -119,12 +123,11 @@ def build_python_path():
119
123
@subdir (BUILD_DIR , clean_ok = True )
120
124
def configure_build_python (context , working_dir ):
121
125
"""Configure the build/host Python."""
122
- local_setup = CHECKOUT / "Modules" / "Setup.local"
123
- if local_setup .exists ():
124
- print (f"👍 { local_setup } exists ..." )
126
+ if LOCAL_SETUP .exists ():
127
+ print (f"👍 { LOCAL_SETUP } exists ..." )
125
128
else :
126
- print (f"📝 Touching { local_setup } ..." )
127
- local_setup . touch ( )
129
+ print (f"📝 Touching { LOCAL_SETUP } ..." )
130
+ LOCAL_SETUP . write_bytes ( LOCAL_SETUP_MARKER )
128
131
129
132
configure = [os .path .relpath (CHECKOUT / 'configure' , working_dir )]
130
133
if context .args :
@@ -260,6 +263,17 @@ def build_all(context):
260
263
for step in steps :
261
264
step (context )
262
265
266
+ def clean_contents (context ):
267
+ """Delete all files created by this script."""
268
+ if CROSS_BUILD_DIR .exists ():
269
+ print (f"🧹 Deleting { CROSS_BUILD_DIR } ..." )
270
+ shutil .rmtree (CROSS_BUILD_DIR )
271
+
272
+ if LOCAL_SETUP .exists ():
273
+ with LOCAL_SETUP .open ("rb" ) as file :
274
+ if file .read (len (LOCAL_SETUP_MARKER )) == LOCAL_SETUP_MARKER :
275
+ print (f"🧹 Deleting generated { LOCAL_SETUP } ..." )
276
+
263
277
264
278
def main ():
265
279
default_host_runner = (f"{ shutil .which ('wasmtime' )} run "
@@ -290,11 +304,13 @@ def main():
290
304
"Python)" )
291
305
make_host = subcommands .add_parser ("make-host" ,
292
306
help = "Run `make` for the host/WASI" )
307
+ clean = subcommands .add_parser ("clean" , help = "Delete files and directories "
308
+ "created by this script" )
293
309
for subcommand in build , configure_build , make_build , configure_host , make_host :
294
310
subcommand .add_argument ("--quiet" , action = "store_true" , default = False ,
295
311
dest = "quiet" ,
296
312
help = "Redirect output from subprocesses to a log file" )
297
- for subcommand in build , configure_build , configure_host :
313
+ for subcommand in configure_build , configure_host :
298
314
subcommand .add_argument ("--clean" , action = "store_true" , default = False ,
299
315
dest = "clean" ,
300
316
help = "Delete any relevant directories before building" )
@@ -319,7 +335,8 @@ def main():
319
335
"make-build-python" : make_build_python ,
320
336
"configure-host" : configure_wasi_python ,
321
337
"make-host" : make_wasi_python ,
322
- "build" : build_all }
338
+ "build" : build_all ,
339
+ "clean" : clean_contents }
323
340
dispatch [context .subcommand ](context )
324
341
325
342
0 commit comments