mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
Add a clean subcommand to Tools/wasm/wasi.py (GH-114274)
This commit is contained in:
parent
229ee5bea1
commit
681e9e85a2
1 changed files with 24 additions and 7 deletions
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue