@@ -77,9 +77,11 @@ def get_build_paths(cross_build_dir=None, emsdk_cache=None):
7777LOCAL_SETUP_MARKER = b"# Generated by Platforms/wasm/emscripten.py\n "
7878
7979
80+ @functools .cache
8081def validate_emsdk_version (emsdk_cache ):
8182 """Validate that the emsdk cache contains the required emscripten version."""
8283 if emsdk_cache is None :
84+ print ("Build will use EMSDK from current environment." )
8385 return
8486 required_version = required_emscripten_version ()
8587 emsdk_env = emsdk_activate_path (emsdk_cache )
@@ -530,7 +532,6 @@ def configure_emscripten_python(context, working_dir):
530532@subdir ("host_dir" )
531533def make_emscripten_python (context , working_dir ):
532534 """Run `make` for the emscripten/host build."""
533- validate_emsdk_version (context .emsdk_cache )
534535 call (
535536 ["make" , "--jobs" , str (cpu_count ()), "all" ],
536537 env = updated_env ({}, context .emsdk_cache ),
@@ -541,6 +542,22 @@ def make_emscripten_python(context, working_dir):
541542 subprocess .check_call ([exec_script , "--version" ])
542543
543544
545+ def run_emscripten_python (context ):
546+ """Run the built emscripten Python."""
547+ host_dir = context .build_paths ["host_dir" ]
548+ exec_script = host_dir / "python.sh"
549+ if not exec_script .is_file ():
550+ print ("Emscripten not built" , file = sys .stderr )
551+ sys .exit (1 )
552+
553+ args = context .args
554+ # Strip the "--" separator if present
555+ if args and args [0 ] == "--" :
556+ args = args [1 :]
557+
558+ os .execv (str (exec_script ), [str (exec_script )] + args )
559+
560+
544561def build_target (context ):
545562 """Build one or more targets."""
546563 steps = []
@@ -581,6 +598,18 @@ def clean_contents(context):
581598 print (f"🧹 Deleting generated { LOCAL_SETUP } ..." )
582599
583600
601+ def add_cross_build_dir_option (subcommand ):
602+ subcommand .add_argument (
603+ "--cross-build-dir" ,
604+ action = "store" ,
605+ default = os .environ .get ("CROSS_BUILD_DIR" ),
606+ dest = "cross_build_dir" ,
607+ help = "Path to the cross-build directory "
608+ f"(default: { DEFAULT_CROSS_BUILD_DIR } ). "
609+ "Can also be set with the CROSS_BUILD_DIR environment variable." ,
610+ )
611+
612+
584613def main ():
585614 default_host_runner = "node"
586615
@@ -623,6 +652,17 @@ def main():
623652 make_host = subcommands .add_parser (
624653 "make-host" , help = "Run `make` for the host/emscripten"
625654 )
655+ run = subcommands .add_parser (
656+ "run" ,
657+ help = "Run the built emscripten Python" ,
658+ )
659+ run .add_argument (
660+ "args" ,
661+ nargs = argparse .REMAINDER ,
662+ help = "Arguments to pass to the emscripten Python "
663+ "(use '--' to separate from run options)" ,
664+ )
665+ add_cross_build_dir_option (run )
626666 clean = subcommands .add_parser (
627667 "clean" , help = "Delete files and directories created by this script"
628668 )
@@ -651,25 +691,20 @@ def main():
651691 subcommand .add_argument (
652692 "--quiet" ,
653693 action = "store_true" ,
654- default = False ,
694+ default = "QUIET" in os . environ ,
655695 dest = "quiet" ,
656- help = "Redirect output from subprocesses to a log file" ,
657- )
658- subcommand .add_argument (
659- "--cross-build-dir" ,
660- action = "store" ,
661- default = None ,
662- dest = "cross_build_dir" ,
663- help = "Path to the cross-build directory "
664- f"(default: { DEFAULT_CROSS_BUILD_DIR } )" ,
696+ help = "Redirect output from subprocesses to a log file. "
697+ "Can also be set with the QUIET environment variable." ,
665698 )
699+ add_cross_build_dir_option (subcommand )
666700 subcommand .add_argument (
667701 "--emsdk-cache" ,
668702 action = "store" ,
669- default = None ,
703+ default = os . environ . get ( "EMSDK_CACHE" ) ,
670704 dest = "emsdk_cache" ,
671705 help = "Path to emsdk cache directory. If provided, validates that "
672- "the required emscripten version is installed." ,
706+ "the required emscripten version is installed. "
707+ "Can also be set with the EMSDK_CACHE environment variable." ,
673708 )
674709 for subcommand in configure_build , configure_host :
675710 subcommand .add_argument (
@@ -699,8 +734,6 @@ def main():
699734
700735 if context .emsdk_cache :
701736 context .emsdk_cache = Path (context .emsdk_cache ).absolute ()
702- else :
703- print ("Build will use EMSDK from current environment." )
704737
705738 context .build_paths = get_build_paths (
706739 context .cross_build_dir , context .emsdk_cache
@@ -715,6 +748,7 @@ def main():
715748 "configure-host" : configure_emscripten_python ,
716749 "make-host" : make_emscripten_python ,
717750 "build" : build_target ,
751+ "run" : run_emscripten_python ,
718752 "clean" : clean_contents ,
719753 }
720754
0 commit comments