@@ -91,18 +91,25 @@ def wrapper(context):
9191 return decorator
9292
9393
94- def call (command , * , quiet , ** kwargs ):
94+ def call (command , * , context = None , quiet = False , logdir = None , ** kwargs ):
9595 """Execute a command.
9696
9797 If 'quiet' is true, then redirect stdout and stderr to a temporary file.
9898 """
99+ if context is not None :
100+ quiet = context .quiet
101+ logdir = context .logdir
102+ elif quiet and logdir is None :
103+ raise ValueError ("When quiet is True, logdir must be specified" )
104+
99105 print ("❯" , " " .join (map (str , command )))
100106 if not quiet :
101107 stdout = None
102108 stderr = None
103109 else :
104110 stdout = tempfile .NamedTemporaryFile ("w" , encoding = "utf-8" ,
105111 delete = False ,
112+ dir = logdir ,
106113 prefix = "cpython-wasi-" ,
107114 suffix = ".log" )
108115 stderr = subprocess .STDOUT
@@ -154,14 +161,14 @@ def configure_build_python(context, working_dir):
154161 if context .args :
155162 configure .extend (context .args )
156163
157- call (configure , quiet = context . quiet )
164+ call (configure , context = context )
158165
159166
160167@subdir (BUILD_DIR )
161168def make_build_python (context , working_dir ):
162169 """Make/build the build Python."""
163170 call (["make" , "--jobs" , str (cpu_count ()), "all" ],
164- quiet = context . quiet )
171+ context = context )
165172
166173 binary = build_python_path ()
167174 cmd = [binary , "-c" ,
@@ -261,7 +268,7 @@ def configure_wasi_python(context, working_dir):
261268 configure .extend (context .args )
262269 call (configure ,
263270 env = updated_env (env_additions | wasi_sdk_env (context )),
264- quiet = context . quiet )
271+ context = context )
265272
266273 python_wasm = working_dir / "python.wasm"
267274 exec_script = working_dir / "python.sh"
@@ -277,7 +284,7 @@ def make_wasi_python(context, working_dir):
277284 """Run `make` for the WASI/host build."""
278285 call (["make" , "--jobs" , str (cpu_count ()), "all" ],
279286 env = updated_env (),
280- quiet = context . quiet )
287+ context = context )
281288
282289 exec_script = working_dir / "python.sh"
283290 call ([exec_script , "--version" ], quiet = False )
@@ -317,6 +324,7 @@ def main():
317324 "--dir {HOST_DIR}::{GUEST_DIR} "
318325 # Set PYTHONPATH to the sysconfig data.
319326 "--env {ENV_VAR_NAME}={ENV_VAR_VALUE}" )
327+ default_logdir = pathlib .Path (tempfile .gettempdir ())
320328
321329 parser = argparse .ArgumentParser ()
322330 subcommands = parser .add_subparsers (dest = "subcommand" )
@@ -339,6 +347,9 @@ def main():
339347 subcommand .add_argument ("--quiet" , action = "store_true" , default = False ,
340348 dest = "quiet" ,
341349 help = "Redirect output from subprocesses to a log file" )
350+ subcommand .add_argument ("--logdir" , type = pathlib .Path , default = default_logdir ,
351+ help = "Directory to store log files; "
352+ f"defaults to { default_logdir } " )
342353 for subcommand in configure_build , configure_host :
343354 subcommand .add_argument ("--clean" , action = "store_true" , default = False ,
344355 dest = "clean" ,
0 commit comments