Skip to content

Commit 8162f61

Browse files
[3.14] gh-151929: Add pythoninfo-build command to Platforms/emscripten (GH-152210) (#152218)
gh-151929: Add pythoninfo-build command to Platforms/emscripten (GH-152210) * Add also "pythoninfo-host" command. * Add pythoninfo to the "build" command. (cherry picked from commit 7676427) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent f38c16a commit 8162f61

2 files changed

Lines changed: 41 additions & 13 deletions

File tree

.github/workflows/reusable-emscripten.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ jobs:
6363
run: python3 Platforms/emscripten configure-build-python -- --config-cache --with-pydebug
6464
- name: "Make build Python"
6565
run: python3 Platforms/emscripten make-build-python
66+
- name: "Display build info of the build Python"
67+
run: python3 Platforms/emscripten pythoninfo-build
6668
- name: "Make dependencies"
6769
run: >-
6870
python3 Platforms/emscripten make-dependencies
6971
${{ steps.emsdk-cache.outputs.cache-hit == 'true' && '--check-up-to-date' || '' }}
70-
- name: "Configure host Python"
72+
- name: "Configure host/Emscripten Python"
7173
run: python3 Platforms/emscripten configure-host --host-runner node -- --config-cache
72-
- name: "Make host Python"
74+
- name: "Make host/Emscripten Python"
7375
run: python3 Platforms/emscripten make-host
74-
- name: "Display build info"
75-
run: python3 Platforms/emscripten run --pythoninfo
76+
- name: "Display build info of the host/Emscripten Python"
77+
run: python3 Platforms/emscripten pythoninfo-host
7678
- name: "Test"
7779
run: python3 Platforms/emscripten run --test

Platforms/emscripten/__main__.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ def make_build_python(context, working_dir):
290290
print(f"🎉 {binary} {version}")
291291

292292

293+
@subdir("native_build_dir")
294+
def pythoninfo_build_python(context, working_dir):
295+
"""Display build info of the build Python."""
296+
call(["make", "pythoninfo"], quiet=context.quiet)
297+
298+
293299
def check_shasum(file: str, expected_shasum: str):
294300
with open(file, "rb") as f:
295301
digest = hashlib.file_digest(f, "sha256")
@@ -580,41 +586,49 @@ def make_emscripten_python(context, working_dir):
580586
subprocess.check_call([exec_script, "--version"])
581587

582588

583-
def run_emscripten_python(context):
589+
def run_emscripten_python(context, args=None):
584590
"""Run the built emscripten Python."""
585591
host_dir = context.build_paths["host_dir"]
586592
exec_script = host_dir / "python.sh"
587593
if not exec_script.is_file():
588594
print("Emscripten not built", file=sys.stderr)
589595
sys.exit(1)
590596

591-
args = context.args
592-
# Strip the "--" separator if present
593-
if args and args[0] == "--":
594-
args = args[1:]
597+
if args is None:
598+
args = context.args
599+
# Strip the "--" separator if present
600+
if args and args[0] == "--":
601+
args = args[1:]
595602

596-
if context.test:
597-
args = load_config_toml()["test-args"] + args
598-
elif context.pythoninfo:
599-
args = load_config_toml()["pythoninfo-args"] + args
603+
if context.test:
604+
args = load_config_toml()["test-args"] + args
605+
elif context.pythoninfo:
606+
args = load_config_toml()["pythoninfo-args"] + args
600607

601608
os.execv(str(exec_script), [str(exec_script), *args])
602609

603610

611+
def pythoninfo_emscripten_python(context):
612+
"""Display build info of the host/Emscripten Python."""
613+
run_emscripten_python(context, ["-m", "test.pythoninfo"])
614+
615+
604616
def build_target(context):
605617
"""Build one or more targets."""
606618
steps = []
607619
if context.target in {"build", "all"}:
608620
steps.extend([
609621
configure_build_python,
610622
make_build_python,
623+
pythoninfo_build_python,
611624
])
612625
if context.target in {"host", "all"}:
613626
steps.extend([
614627
make_emscripten_libffi,
615628
make_mpdec,
616629
configure_emscripten_python,
617630
make_emscripten_python,
631+
pythoninfo_emscripten_python,
618632
])
619633

620634
for step in steps:
@@ -707,6 +721,10 @@ def main():
707721
"make-build-python", help="Run `make` for the build Python"
708722
)
709723

724+
pythoninfo_build = subcommands.add_parser(
725+
"pythoninfo-build", help="Display build info of the build Python"
726+
)
727+
710728
configure_host = subcommands.add_parser(
711729
"configure-host",
712730
help=(
@@ -719,6 +737,10 @@ def main():
719737
"make-host", help="Run `make` for the host/emscripten"
720738
)
721739

740+
pythoninfo_host = subcommands.add_parser(
741+
"pythoninfo-host", help="Display build info of the host/Emscripten Python"
742+
)
743+
722744
run = subcommands.add_parser(
723745
"run",
724746
help="Run the built emscripten Python",
@@ -770,8 +792,10 @@ def main():
770792
make_mpdec_cmd,
771793
make_dependencies_cmd,
772794
make_build,
795+
pythoninfo_build,
773796
configure_host,
774797
make_host,
798+
pythoninfo_host,
775799
clean,
776800
):
777801
subcommand.add_argument(
@@ -840,8 +864,10 @@ def main():
840864
"make-dependencies": make_dependencies,
841865
"configure-build-python": configure_build_python,
842866
"make-build-python": make_build_python,
867+
"pythoninfo-build": pythoninfo_build_python,
843868
"configure-host": configure_emscripten_python,
844869
"make-host": make_emscripten_python,
870+
"pythoninfo-host": pythoninfo_emscripten_python,
845871
"build": build_target,
846872
"run": run_emscripten_python,
847873
"clean": clean_contents,

0 commit comments

Comments
 (0)