Skip to content

Commit 5a639ca

Browse files
miss-islingtonbrettcannonemmatyping
authored
[3.14] Introduce build-python and build-host subcommands for Tools/wasm/wasi (GH-142266) (#142322)
Introduce `build-python` and `build-host` subcommands for `Tools/wasm/wasi` (GH-142266) It should make it easier when you need to rebuild just the e.g. host Python, but it requires ./configure to run. (cherry picked from commit 58e1c7a) Co-authored-by: Brett Cannon <brett@python.org> Co-authored-by: Emma Smith <emma@emmatyping.dev>
1 parent 66d1d7e commit 5a639ca

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

Tools/wasm/wasi/__main__.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,6 @@ def make_wasi_python(context, working_dir):
389389
)
390390

391391

392-
def build_all(context):
393-
"""Build everything."""
394-
steps = [
395-
configure_build_python,
396-
make_build_python,
397-
configure_wasi_python,
398-
make_wasi_python,
399-
]
400-
for step in steps:
401-
step(context)
402-
403-
404392
def clean_contents(context):
405393
"""Delete all files created by this script."""
406394
if CROSS_BUILD_DIR.exists():
@@ -412,6 +400,16 @@ def clean_contents(context):
412400
log("🧹", f"Deleting generated {LOCAL_SETUP} ...")
413401

414402

403+
def build_steps(*steps):
404+
"""Construct a command from other steps."""
405+
406+
def builder(context):
407+
for step in steps:
408+
step(context)
409+
410+
return builder
411+
412+
415413
def main():
416414
default_host_triple = "wasm32-wasip1"
417415
default_wasi_sdk = find_wasi_sdk()
@@ -439,6 +437,9 @@ def main():
439437
make_build = subcommands.add_parser(
440438
"make-build-python", help="Run `make` for the build Python"
441439
)
440+
build_python = subcommands.add_parser(
441+
"build-python", help="Build the build Python"
442+
)
442443
configure_host = subcommands.add_parser(
443444
"configure-host",
444445
help="Run `configure` for the "
@@ -449,15 +450,20 @@ def main():
449450
make_host = subcommands.add_parser(
450451
"make-host", help="Run `make` for the host/WASI"
451452
)
453+
build_host = subcommands.add_parser(
454+
"build-host", help="Build the host/WASI Python"
455+
)
452456
subcommands.add_parser(
453457
"clean", help="Delete files and directories created by this script"
454458
)
455459
for subcommand in (
456460
build,
457461
configure_build,
458462
make_build,
463+
build_python,
459464
configure_host,
460465
make_host,
466+
build_host,
461467
):
462468
subcommand.add_argument(
463469
"--quiet",
@@ -472,19 +478,30 @@ def main():
472478
default=default_logdir,
473479
help=f"Directory to store log files; defaults to {default_logdir}",
474480
)
475-
for subcommand in configure_build, configure_host:
481+
for subcommand in (
482+
configure_build,
483+
configure_host,
484+
build_python,
485+
build_host,
486+
):
476487
subcommand.add_argument(
477488
"--clean",
478489
action="store_true",
479490
default=False,
480491
dest="clean",
481492
help="Delete any relevant directories before building",
482493
)
483-
for subcommand in build, configure_build, configure_host:
494+
for subcommand in (
495+
build,
496+
configure_build,
497+
configure_host,
498+
build_python,
499+
build_host,
500+
):
484501
subcommand.add_argument(
485502
"args", nargs="*", help="Extra arguments to pass to `configure`"
486503
)
487-
for subcommand in build, configure_host:
504+
for subcommand in build, configure_host, build_host:
488505
subcommand.add_argument(
489506
"--wasi-sdk",
490507
type=pathlib.Path,
@@ -500,7 +517,7 @@ def main():
500517
help="Command template for running the WASI host; defaults to "
501518
f"`{default_host_runner}`",
502519
)
503-
for subcommand in build, configure_host, make_host:
520+
for subcommand in build, configure_host, make_host, build_host:
504521
subcommand.add_argument(
505522
"--host-triple",
506523
action="store",
@@ -512,12 +529,17 @@ def main():
512529
context = parser.parse_args()
513530
context.init_dir = pathlib.Path().absolute()
514531

532+
build_build_python = build_steps(configure_build_python, make_build_python)
533+
build_wasi_python = build_steps(configure_wasi_python, make_wasi_python)
534+
515535
dispatch = {
516536
"configure-build-python": configure_build_python,
517537
"make-build-python": make_build_python,
538+
"build-python": build_build_python,
518539
"configure-host": configure_wasi_python,
519540
"make-host": make_wasi_python,
520-
"build": build_all,
541+
"build-host": build_wasi_python,
542+
"build": build_steps(build_build_python, build_wasi_python),
521543
"clean": clean_contents,
522544
}
523545
dispatch[context.subcommand](context)

0 commit comments

Comments
 (0)