https://github.com/python/cpython/commit/681e9e85a2c1f72576ddfbd766506e2d6db34862
commit: 681e9e85a2c1f72576ddfbd766506e2d6db34862
branch: main
author: Brett Cannon <[email protected]>
committer: brettcannon <[email protected]>
date: 2024-01-19T11:38:52-08:00
summary:

Add a `clean` subcommand to `Tools/wasm/wasi.py` (GH-114274)

files:
M Tools/wasm/wasi.py

diff --git a/Tools/wasm/wasi.py b/Tools/wasm/wasi.py
index 36bc70ffd9db7b..e71b0b302a5561 100644
--- a/Tools/wasm/wasi.py
+++ b/Tools/wasm/wasi.py
@@ -17,11 +17,15 @@
 
 
 CHECKOUT = pathlib.Path(__file__).parent.parent.parent
+
 CROSS_BUILD_DIR = CHECKOUT / "cross-build"
 BUILD_DIR = CROSS_BUILD_DIR / "build"
 HOST_TRIPLE = "wasm32-wasi"
 HOST_DIR = CROSS_BUILD_DIR / HOST_TRIPLE
 
+LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
+LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/wasi.py\n".encode("utf-8")
+
 
 def updated_env(updates={}):
     """Create a new dict representing the environment to use.
@@ -119,12 +123,11 @@ def build_python_path():
 @subdir(BUILD_DIR, clean_ok=True)
 def configure_build_python(context, working_dir):
     """Configure the build/host Python."""
-    local_setup = CHECKOUT / "Modules" / "Setup.local"
-    if local_setup.exists():
-        print(f"๐Ÿ‘ {local_setup} exists ...")
+    if LOCAL_SETUP.exists():
+        print(f"๐Ÿ‘ {LOCAL_SETUP} exists ...")
     else:
-        print(f"๐Ÿ“ Touching {local_setup} ...")
-        local_setup.touch()
+        print(f"๐Ÿ“ Touching {LOCAL_SETUP} ...")
+        LOCAL_SETUP.write_bytes(LOCAL_SETUP_MARKER)
 
     configure = [os.path.relpath(CHECKOUT / 'configure', working_dir)]
     if context.args:
@@ -260,6 +263,17 @@ def build_all(context):
     for step in steps:
         step(context)
 
+def clean_contents(context):
+    """Delete all files created by this script."""
+    if CROSS_BUILD_DIR.exists():
+        print(f"๐Ÿงน Deleting {CROSS_BUILD_DIR} ...")
+        shutil.rmtree(CROSS_BUILD_DIR)
+
+    if LOCAL_SETUP.exists():
+        with LOCAL_SETUP.open("rb") as file:
+            if file.read(len(LOCAL_SETUP_MARKER)) == LOCAL_SETUP_MARKER:
+                print(f"๐Ÿงน Deleting generated {LOCAL_SETUP} ...")
+
 
 def main():
     default_host_runner = (f"{shutil.which('wasmtime')} run "
@@ -290,11 +304,13 @@ def main():
                                                  "Python)")
     make_host = subcommands.add_parser("make-host",
                                        help="Run `make` for the host/WASI")
+    clean = subcommands.add_parser("clean", help="Delete files and directories 
"
+                                                 "created by this script")
     for subcommand in build, configure_build, make_build, configure_host, 
make_host:
         subcommand.add_argument("--quiet", action="store_true", default=False,
                         dest="quiet",
                         help="Redirect output from subprocesses to a log file")
-    for subcommand in build, configure_build, configure_host:
+    for subcommand in configure_build, configure_host:
         subcommand.add_argument("--clean", action="store_true", default=False,
                         dest="clean",
                         help="Delete any relevant directories before building")
@@ -319,7 +335,8 @@ def main():
                 "make-build-python": make_build_python,
                 "configure-host": configure_wasi_python,
                 "make-host": make_wasi_python,
-                "build": build_all}
+                "build": build_all,
+                "clean": clean_contents}
     dispatch[context.subcommand](context)
 
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to