13
13
import pathlib
14
14
import shutil
15
15
import sys
16
+ import sysconfig
16
17
import zipfile
17
18
18
19
# source directory
19
20
SRCDIR = pathlib .Path (__file__ ).parent .parent .parent .absolute ()
20
21
SRCDIR_LIB = SRCDIR / "Lib"
21
22
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
- )
28
23
29
24
# Library directory relative to $(prefix).
30
25
WASM_LIB = pathlib .PurePath ("lib" )
121
116
"unittest/test/" ,
122
117
)
123
118
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
+
124
135
125
136
def create_stdlib_zip (
126
137
args : argparse .Namespace ,
@@ -150,7 +161,7 @@ def detect_extension_modules(args: argparse.Namespace):
150
161
modules = {}
151
162
152
163
# disabled by Modules/Setup.local ?
153
- with open (args .builddir / "Makefile" ) as f :
164
+ with open (args .buildroot / "Makefile" ) as f :
154
165
for line in f :
155
166
if line .startswith ("MODDISABLED_NAMES=" ):
156
167
disabled = line .split ("=" , 1 )[1 ].strip ().split ()
@@ -183,8 +194,8 @@ def path(val: str) -> pathlib.Path:
183
194
184
195
parser = argparse .ArgumentParser ()
185
196
parser .add_argument (
186
- "--builddir " ,
187
- help = "absolute build directory " ,
197
+ "--buildroot " ,
198
+ help = "absolute path to build root " ,
188
199
default = pathlib .Path ("." ).absolute (),
189
200
type = path ,
190
201
)
@@ -202,7 +213,7 @@ def main():
202
213
relative_prefix = args .prefix .relative_to (pathlib .Path ("/" ))
203
214
args .srcdir = SRCDIR
204
215
args .srcdir_lib = SRCDIR_LIB
205
- args .wasm_root = args .builddir / relative_prefix
216
+ args .wasm_root = args .buildroot / relative_prefix
206
217
args .wasm_stdlib_zip = args .wasm_root / WASM_STDLIB_ZIP
207
218
args .wasm_stdlib = args .wasm_root / WASM_STDLIB
208
219
args .wasm_dynload = args .wasm_root / WASM_DYNLOAD
@@ -212,9 +223,10 @@ def main():
212
223
args .compression = zipfile .ZIP_DEFLATED
213
224
args .compresslevel = 9
214
225
215
- args .sysconfig_data = args .builddir / SYSCONFIGDATA
226
+ args .builddir = get_builddir (args )
227
+ args .sysconfig_data = get_sysconfigdata (args )
216
228
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." )
218
230
219
231
extmods = detect_extension_modules (args )
220
232
omit_files = list (OMIT_FILES )
0 commit comments