Skip to content

[3.14] GH-137248: Add a --logdir option to Tools/wasm/wasi (GH-137249) #137252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 3.14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
GH-137248: Add a --logdir option to Tools/wasm/wasi (GH-137249)
(cherry picked from commit 94498a5)

Co-authored-by: Brett Cannon <brett@python.org>
  • Loading branch information
brettcannon authored and miss-islington committed Jul 30, 2025
commit 6fbfca65ea8abe2e1668a3e86731a4c69b73f0c4
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add a ``--logdir`` option to ``Tools/wasm/wasi`` for specifying where to
write log files.
21 changes: 16 additions & 5 deletions Tools/wasm/wasi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,25 @@ def wrapper(context):
return decorator


def call(command, *, quiet, **kwargs):
def call(command, *, context=None, quiet=False, logdir=None, **kwargs):
"""Execute a command.

If 'quiet' is true, then redirect stdout and stderr to a temporary file.
"""
if context is not None:
quiet = context.quiet
logdir = context.logdir
elif quiet and logdir is None:
raise ValueError("When quiet is True, logdir must be specified")

print("❯", " ".join(map(str, command)))
if not quiet:
stdout = None
stderr = None
else:
stdout = tempfile.NamedTemporaryFile("w", encoding="utf-8",
delete=False,
dir=logdir,
prefix="cpython-wasi-",
suffix=".log")
stderr = subprocess.STDOUT
Expand Down Expand Up @@ -150,14 +157,14 @@ def configure_build_python(context, working_dir):
if context.args:
configure.extend(context.args)

call(configure, quiet=context.quiet)
call(configure, context=context)


@subdir(BUILD_DIR)
def make_build_python(context, working_dir):
"""Make/build the build Python."""
call(["make", "--jobs", str(cpu_count()), "all"],
quiet=context.quiet)
context=context)

binary = build_python_path()
cmd = [binary, "-c",
Expand Down Expand Up @@ -257,7 +264,7 @@ def configure_wasi_python(context, working_dir):
configure.extend(context.args)
call(configure,
env=updated_env(env_additions | wasi_sdk_env(context)),
quiet=context.quiet)
context=context)

python_wasm = working_dir / "python.wasm"
exec_script = working_dir / "python.sh"
Expand All @@ -273,7 +280,7 @@ def make_wasi_python(context, working_dir):
"""Run `make` for the WASI/host build."""
call(["make", "--jobs", str(cpu_count()), "all"],
env=updated_env(),
quiet=context.quiet)
context=context)

exec_script = working_dir / "python.sh"
call([exec_script, "--version"], quiet=False)
Expand Down Expand Up @@ -314,6 +321,7 @@ def main():
"--dir {HOST_DIR}::{GUEST_DIR} "
# Set PYTHONPATH to the sysconfig data.
"--env {ENV_VAR_NAME}={ENV_VAR_VALUE}")
default_logdir = pathlib.Path(tempfile.gettempdir())

parser = argparse.ArgumentParser()
subcommands = parser.add_subparsers(dest="subcommand")
Expand All @@ -336,6 +344,9 @@ def main():
subcommand.add_argument("--quiet", action="store_true", default=False,
dest="quiet",
help="Redirect output from subprocesses to a log file")
subcommand.add_argument("--logdir", type=pathlib.Path, default=default_logdir,
help="Directory to store log files; "
f"defaults to {default_logdir}")
for subcommand in configure_build, configure_host:
subcommand.add_argument("--clean", action="store_true", default=False,
dest="clean",
Expand Down
Loading