Skip to content

Commit 94498a5

Browse files
authored
pythonGH-137248: Add a --logdir option to Tools/wasm/wasi (pythonGH-137249)
1 parent 2f1a9f2 commit 94498a5

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a ``--logdir`` option to ``Tools/wasm/wasi`` for specifying where to
2+
write log files.

Tools/wasm/wasi/__main__.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,25 @@ def wrapper(context):
9393
return decorator
9494

9595

96-
def call(command, *, quiet, **kwargs):
96+
def call(command, *, context=None, quiet=False, logdir=None, **kwargs):
9797
"""Execute a command.
9898
9999
If 'quiet' is true, then redirect stdout and stderr to a temporary file.
100100
"""
101+
if context is not None:
102+
quiet = context.quiet
103+
logdir = context.logdir
104+
elif quiet and logdir is None:
105+
raise ValueError("When quiet is True, logdir must be specified")
106+
101107
print("❯", " ".join(map(str, command)))
102108
if not quiet:
103109
stdout = None
104110
stderr = None
105111
else:
106112
stdout = tempfile.NamedTemporaryFile("w", encoding="utf-8",
107113
delete=False,
114+
dir=logdir,
108115
prefix="cpython-wasi-",
109116
suffix=".log")
110117
stderr = subprocess.STDOUT
@@ -156,14 +163,14 @@ def configure_build_python(context, working_dir):
156163
if context.args:
157164
configure.extend(context.args)
158165

159-
call(configure, quiet=context.quiet)
166+
call(configure, context=context)
160167

161168

162169
@subdir(BUILD_DIR)
163170
def make_build_python(context, working_dir):
164171
"""Make/build the build Python."""
165172
call(["make", "--jobs", str(cpu_count()), "all"],
166-
quiet=context.quiet)
173+
context=context)
167174

168175
binary = build_python_path()
169176
cmd = [binary, "-c",
@@ -275,7 +282,7 @@ def configure_wasi_python(context, working_dir):
275282
configure.extend(context.args)
276283
call(configure,
277284
env=updated_env(env_additions | wasi_sdk_env(context)),
278-
quiet=context.quiet)
285+
context=context)
279286

280287
python_wasm = working_dir / "python.wasm"
281288
exec_script = working_dir / "python.sh"
@@ -291,7 +298,7 @@ def make_wasi_python(context, working_dir):
291298
"""Run `make` for the WASI/host build."""
292299
call(["make", "--jobs", str(cpu_count()), "all"],
293300
env=updated_env(),
294-
quiet=context.quiet)
301+
context=context)
295302

296303
exec_script = working_dir / "python.sh"
297304
call([exec_script, "--version"], quiet=False)
@@ -333,6 +340,7 @@ def main():
333340
"--dir {HOST_DIR}::{GUEST_DIR} "
334341
# Set PYTHONPATH to the sysconfig data.
335342
"--env {ENV_VAR_NAME}={ENV_VAR_VALUE}")
343+
default_logdir = pathlib.Path(tempfile.gettempdir())
336344

337345
parser = argparse.ArgumentParser()
338346
subcommands = parser.add_subparsers(dest="subcommand")
@@ -355,6 +363,9 @@ def main():
355363
subcommand.add_argument("--quiet", action="store_true", default=False,
356364
dest="quiet",
357365
help="Redirect output from subprocesses to a log file")
366+
subcommand.add_argument("--logdir", type=pathlib.Path, default=default_logdir,
367+
help="Directory to store log files; "
368+
f"defaults to {default_logdir}")
358369
for subcommand in configure_build, configure_host:
359370
subcommand.add_argument("--clean", action="store_true", default=False,
360371
dest="clean",

0 commit comments

Comments
 (0)