]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] GH-137248: Add a `--logdir` option to `Tools/wasm/wasi` (GH-137249) (GH-137252)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 7 Oct 2025 23:51:19 +0000 (01:51 +0200)
committerGitHub <noreply@github.com>
Tue, 7 Oct 2025 23:51:19 +0000 (23:51 +0000)
GH-137248: Add a `--logdir` option to `Tools/wasm/wasi` (GH-137249)
(cherry picked from commit 94498a53f308a079be9860e0f0d470eeaeb082ff)

Co-authored-by: Brett Cannon <brett@python.org>
Misc/NEWS.d/next/Tools-Demos/2025-07-30-11-15-47.gh-issue-137248.8IxwY3.rst [new file with mode: 0644]
Tools/wasm/wasi/__main__.py

diff --git a/Misc/NEWS.d/next/Tools-Demos/2025-07-30-11-15-47.gh-issue-137248.8IxwY3.rst b/Misc/NEWS.d/next/Tools-Demos/2025-07-30-11-15-47.gh-issue-137248.8IxwY3.rst
new file mode 100644 (file)
index 0000000..311ade0
--- /dev/null
@@ -0,0 +1,2 @@
+Add a ``--logdir`` option to ``Tools/wasm/wasi`` for specifying where to
+write log files.
index d2461c387fab544aaa417592f46c4b3f58331ec3..fdd93d5c0aa4af31038e7b61ed699045cc19d2e8 100644 (file)
@@ -93,11 +93,17 @@ def subdir(working_dir, *, clean_ok=False):
     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
@@ -105,6 +111,7 @@ def call(command, *, quiet, **kwargs):
     else:
         stdout = tempfile.NamedTemporaryFile("w", encoding="utf-8",
                                              delete=False,
+                                             dir=logdir,
                                              prefix="cpython-wasi-",
                                              suffix=".log")
         stderr = subprocess.STDOUT
@@ -156,14 +163,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",
@@ -275,7 +282,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"
@@ -291,7 +298,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)
@@ -333,6 +340,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")
@@ -355,6 +363,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",