1313import pathlib
1414import shutil
1515import sys
16+ import sysconfig
1617import zipfile
1718
1819# source directory
1920SRCDIR = pathlib .Path (__file__ ).parent .parent .parent .absolute ()
2021SRCDIR_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).
3025WASM_LIB = pathlib .PurePath ("lib" )
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
125136def 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
184195parser = argparse .ArgumentParser ()
185196parser .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