Skip to content

Commit 19e9b9d

Browse files
committed
GH-137248: Add a --logdir option to Tools/wasm/wasi
1 parent 9d3b53c commit 19e9b9d

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
@@ -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)
161168
def 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

Comments
 (0)