@@ -90,18 +90,25 @@ def wrapper(context):
9090 return decorator
9191
9292
93- def call (command , * , quiet , ** kwargs ):
93+ def call (command , * , context = None , quiet = False , logdir = None , ** kwargs ):
9494 """Execute a command.
9595
9696 If 'quiet' is true, then redirect stdout and stderr to a temporary file.
9797 """
98+ if context is not None :
99+ quiet = context .quiet
100+ logdir = context .logdir
101+ elif quiet and logdir is None :
102+ raise ValueError ("When quiet is True, logdir must be specified" )
103+
98104 print ("❯" , " " .join (map (str , command )))
99105 if not quiet :
100106 stdout = None
101107 stderr = None
102108 else :
103109 stdout = tempfile .NamedTemporaryFile ("w" , encoding = "utf-8" ,
104110 delete = False ,
111+ dir = logdir ,
105112 prefix = "cpython-wasi-" ,
106113 suffix = ".log" )
107114 stderr = subprocess .STDOUT
@@ -150,14 +157,14 @@ def configure_build_python(context, working_dir):
150157 if context .args :
151158 configure .extend (context .args )
152159
153- call (configure , quiet = context . quiet )
160+ call (configure , context = context )
154161
155162
156163@subdir (BUILD_DIR )
157164def make_build_python (context , working_dir ):
158165 """Make/build the build Python."""
159166 call (["make" , "--jobs" , str (cpu_count ()), "all" ],
160- quiet = context . quiet )
167+ context = context )
161168
162169 binary = build_python_path ()
163170 cmd = [binary , "-c" ,
@@ -257,7 +264,7 @@ def configure_wasi_python(context, working_dir):
257264 configure .extend (context .args )
258265 call (configure ,
259266 env = updated_env (env_additions | wasi_sdk_env (context )),
260- quiet = context . quiet )
267+ context = context )
261268
262269 python_wasm = working_dir / "python.wasm"
263270 exec_script = working_dir / "python.sh"
@@ -273,7 +280,7 @@ def make_wasi_python(context, working_dir):
273280 """Run `make` for the WASI/host build."""
274281 call (["make" , "--jobs" , str (cpu_count ()), "all" ],
275282 env = updated_env (),
276- quiet = context . quiet )
283+ context = context )
277284
278285 exec_script = working_dir / "python.sh"
279286 call ([exec_script , "--version" ], quiet = False )
@@ -314,6 +321,7 @@ def main():
314321 "--dir {HOST_DIR}::{GUEST_DIR} "
315322 # Set PYTHONPATH to the sysconfig data.
316323 "--env {ENV_VAR_NAME}={ENV_VAR_VALUE}" )
324+ default_logdir = pathlib .Path (tempfile .gettempdir ())
317325
318326 parser = argparse .ArgumentParser ()
319327 subcommands = parser .add_subparsers (dest = "subcommand" )
@@ -336,6 +344,9 @@ def main():
336344 subcommand .add_argument ("--quiet" , action = "store_true" , default = False ,
337345 dest = "quiet" ,
338346 help = "Redirect output from subprocesses to a log file" )
347+ subcommand .add_argument ("--logdir" , type = pathlib .Path , default = default_logdir ,
348+ help = "Directory to store log files; "
349+ f"defaults to { default_logdir } " )
339350 for subcommand in configure_build , configure_host :
340351 subcommand .add_argument ("--clean" , action = "store_true" , default = False ,
341352 dest = "clean" ,
0 commit comments