Skip to content

Commit 7a2cc35

Browse files
authored
gh-84461: Fix pydebug Emscripten browser builds (GH-93982)
wasm_assets script did not take the ABIFLAG flag of sysconfigdata into account.
1 parent f9433ff commit 7a2cc35

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

Makefile.pre.in

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ SRCDIRS= @SRCDIRS@
247247
SUBDIRSTOO= Include Lib Misc
248248

249249
# assets for Emscripten browser builds
250-
WASM_ASSETS_DIR=".$(prefix)"
251-
WASM_STDLIB="$(WASM_ASSETS_DIR)/local/lib/python$(VERSION)/os.py"
250+
WASM_ASSETS_DIR=.$(prefix)
251+
WASM_STDLIB=$(WASM_ASSETS_DIR)/lib/python$(VERSION)/os.py
252252

253253
# Files and directories to be distributed
254254
CONFIGFILES= configure configure.ac acconfig.h pyconfig.h.in Makefile.pre.in
@@ -821,7 +821,7 @@ $(WASM_STDLIB): $(srcdir)/Lib/*.py $(srcdir)/Lib/*/*.py \
821821
Makefile pybuilddir.txt Modules/Setup.local \
822822
python.html python.worker.js
823823
$(PYTHON_FOR_BUILD) $(srcdir)/Tools/wasm/wasm_assets.py \
824-
--builddir . --prefix $(prefix)
824+
--buildroot . --prefix $(prefix)
825825

826826
python.html: $(srcdir)/Tools/wasm/python.html python.worker.js
827827
@cp $(srcdir)/Tools/wasm/python.html $@
@@ -2391,7 +2391,7 @@ clean-retain-profile: pycremoval
23912391
-rm -f Lib/lib2to3/*Grammar*.pickle
23922392
-rm -f _bootstrap_python
23932393
-rm -f python.html python*.js python.data python*.symbols python*.map
2394-
-rm -rf $(WASM_STDLIB)
2394+
-rm -f $(WASM_STDLIB)
23952395
-rm -f Programs/_testembed Programs/_freeze_module
23962396
-rm -f Python/deepfreeze/*.[co]
23972397
-rm -f Python/frozen_modules/*.h

Tools/wasm/wasm_assets.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@
1313
import pathlib
1414
import shutil
1515
import sys
16+
import sysconfig
1617
import zipfile
1718

1819
# source directory
1920
SRCDIR = pathlib.Path(__file__).parent.parent.parent.absolute()
2021
SRCDIR_LIB = SRCDIR / "Lib"
2122

22-
# sysconfig data relative to build dir.
23-
SYSCONFIGDATA = pathlib.PurePath(
24-
"build",
25-
f"lib.emscripten-wasm32-{sys.version_info.major}.{sys.version_info.minor}",
26-
"_sysconfigdata__emscripten_wasm32-emscripten.py",
27-
)
2823

2924
# Library directory relative to $(prefix).
3025
WASM_LIB = pathlib.PurePath("lib")
@@ -121,6 +116,22 @@
121116
"unittest/test/",
122117
)
123118

119+
def get_builddir(args: argparse.Namespace) -> pathlib.Path:
120+
"""Get builddir path from pybuilddir.txt
121+
"""
122+
with open("pybuilddir.txt", encoding="utf-8") as f:
123+
builddir = f.read()
124+
return pathlib.Path(builddir)
125+
126+
127+
def get_sysconfigdata(args: argparse.Namespace) -> pathlib.Path:
128+
"""Get path to sysconfigdata relative to build root
129+
"""
130+
data_name = sysconfig._get_sysconfigdata_name()
131+
assert "emscripten_wasm32" in data_name
132+
filename = data_name + ".py"
133+
return args.builddir / filename
134+
124135

125136
def create_stdlib_zip(
126137
args: argparse.Namespace,
@@ -150,7 +161,7 @@ def detect_extension_modules(args: argparse.Namespace):
150161
modules = {}
151162

152163
# disabled by Modules/Setup.local ?
153-
with open(args.builddir / "Makefile") as f:
164+
with open(args.buildroot / "Makefile") as f:
154165
for line in f:
155166
if line.startswith("MODDISABLED_NAMES="):
156167
disabled = line.split("=", 1)[1].strip().split()
@@ -183,8 +194,8 @@ def path(val: str) -> pathlib.Path:
183194

184195
parser = argparse.ArgumentParser()
185196
parser.add_argument(
186-
"--builddir",
187-
help="absolute build directory",
197+
"--buildroot",
198+
help="absolute path to build root",
188199
default=pathlib.Path(".").absolute(),
189200
type=path,
190201
)
@@ -202,7 +213,7 @@ def main():
202213
relative_prefix = args.prefix.relative_to(pathlib.Path("/"))
203214
args.srcdir = SRCDIR
204215
args.srcdir_lib = SRCDIR_LIB
205-
args.wasm_root = args.builddir / relative_prefix
216+
args.wasm_root = args.buildroot / relative_prefix
206217
args.wasm_stdlib_zip = args.wasm_root / WASM_STDLIB_ZIP
207218
args.wasm_stdlib = args.wasm_root / WASM_STDLIB
208219
args.wasm_dynload = args.wasm_root / WASM_DYNLOAD
@@ -212,9 +223,10 @@ def main():
212223
args.compression = zipfile.ZIP_DEFLATED
213224
args.compresslevel = 9
214225

215-
args.sysconfig_data = args.builddir / SYSCONFIGDATA
226+
args.builddir = get_builddir(args)
227+
args.sysconfig_data = get_sysconfigdata(args)
216228
if not args.sysconfig_data.is_file():
217-
raise ValueError(f"sysconfigdata file {SYSCONFIGDATA} missing.")
229+
raise ValueError(f"sysconfigdata file {args.sysconfig_data} missing.")
218230

219231
extmods = detect_extension_modules(args)
220232
omit_files = list(OMIT_FILES)

0 commit comments

Comments
 (0)