33
33
PREFIX_DIR = CROSS_BUILD_DIR / HOST_TRIPLE / "prefix"
34
34
35
35
LOCAL_SETUP = CHECKOUT / "Modules" / "Setup.local"
36
- LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/emscripten.py\n " .encode ("utf-8" )
36
+ LOCAL_SETUP_MARKER = "# Generated by Tools/wasm/emscripten.py\n " .encode (
37
+ "utf-8"
38
+ )
37
39
38
40
39
41
def updated_env (updates = {}):
@@ -45,7 +47,9 @@ def updated_env(updates={}):
45
47
# https://reproducible-builds.org/docs/source-date-epoch/
46
48
git_epoch_cmd = ["git" , "log" , "-1" , "--pretty=%ct" ]
47
49
try :
48
- epoch = subprocess .check_output (git_epoch_cmd , encoding = "utf-8" ).strip ()
50
+ epoch = subprocess .check_output (
51
+ git_epoch_cmd , encoding = "utf-8"
52
+ ).strip ()
49
53
env_defaults ["SOURCE_DATE_EPOCH" ] = epoch
50
54
except subprocess .CalledProcessError :
51
55
pass # Might be building from a tarball.
@@ -79,7 +83,11 @@ def wrapper(context):
79
83
terminal_width = 80
80
84
print ("⎯" * terminal_width )
81
85
print ("📁" , working_dir )
82
- if clean_ok and getattr (context , "clean" , False ) and working_dir .exists ():
86
+ if (
87
+ clean_ok
88
+ and getattr (context , "clean" , False )
89
+ and working_dir .exists ()
90
+ ):
83
91
print ("🚮 Deleting directory (--clean)..." )
84
92
shutil .rmtree (working_dir )
85
93
@@ -128,7 +136,9 @@ def build_python_path():
128
136
if not binary .is_file ():
129
137
binary = binary .with_suffix (".exe" )
130
138
if not binary .is_file ():
131
- raise FileNotFoundError ("Unable to find `python(.exe)` in " f"{ NATIVE_BUILD_DIR } " )
139
+ raise FileNotFoundError (
140
+ f"Unable to find `python(.exe)` in { NATIVE_BUILD_DIR } "
141
+ )
132
142
133
143
return binary
134
144
@@ -158,7 +168,8 @@ def make_build_python(context, working_dir):
158
168
cmd = [
159
169
binary ,
160
170
"-c" ,
161
- "import sys; " "print(f'{sys.version_info.major}.{sys.version_info.minor}')" ,
171
+ "import sys; "
172
+ "print(f'{sys.version_info.major}.{sys.version_info.minor}')" ,
162
173
]
163
174
version = subprocess .check_output (cmd , encoding = "utf-8" ).strip ()
164
175
@@ -173,7 +184,9 @@ def check_shasum(file: str, expected_shasum: str):
173
184
174
185
175
186
def download_and_unpack (working_dir : Path , url : str , expected_shasum : str ):
176
- with tempfile .NamedTemporaryFile (suffix = ".tar.gz" , delete_on_close = False ) as tmp_file :
187
+ with tempfile .NamedTemporaryFile (
188
+ suffix = ".tar.gz" , delete_on_close = False
189
+ ) as tmp_file :
177
190
with urlopen (url ) as response :
178
191
shutil .copyfileobj (response , tmp_file )
179
192
tmp_file .close ()
@@ -186,7 +199,11 @@ def make_emscripten_libffi(context, working_dir):
186
199
ver = "3.4.6"
187
200
libffi_dir = working_dir / f"libffi-{ ver } "
188
201
shutil .rmtree (libffi_dir , ignore_errors = True )
189
- download_and_unpack (working_dir , f"https://github.com/libffi/libffi/releases/download/v{ ver } /libffi-{ ver } .tar.gz" , "b0dea9df23c863a7a50e825440f3ebffabd65df1497108e5d437747843895a4e" )
202
+ download_and_unpack (
203
+ working_dir ,
204
+ f"https://github.com/libffi/libffi/releases/download/v{ ver } /libffi-{ ver } .tar.gz" ,
205
+ "b0dea9df23c863a7a50e825440f3ebffabd65df1497108e5d437747843895a4e" ,
206
+ )
190
207
call (
191
208
[EMSCRIPTEN_DIR / "make_libffi.sh" ],
192
209
env = updated_env ({"PREFIX" : PREFIX_DIR }),
@@ -200,7 +217,11 @@ def make_mpdec(context, working_dir):
200
217
ver = "4.0.1"
201
218
mpdec_dir = working_dir / f"mpdecimal-{ ver } "
202
219
shutil .rmtree (mpdec_dir , ignore_errors = True )
203
- download_and_unpack (working_dir , f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{ ver } .tar.gz" , "96d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8" )
220
+ download_and_unpack (
221
+ working_dir ,
222
+ f"https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-{ ver } .tar.gz" ,
223
+ "96d33abb4bb0070c7be0fed4246cd38416188325f820468214471938545b1ac8" ,
224
+ )
204
225
call (
205
226
[
206
227
"emconfigure" ,
@@ -214,10 +235,7 @@ def make_mpdec(context, working_dir):
214
235
quiet = context .quiet ,
215
236
)
216
237
call (
217
- [
218
- "make" ,
219
- "install"
220
- ],
238
+ ["make" , "install" ],
221
239
cwd = mpdec_dir ,
222
240
quiet = context .quiet ,
223
241
)
@@ -226,17 +244,15 @@ def make_mpdec(context, working_dir):
226
244
@subdir (HOST_DIR , clean_ok = True )
227
245
def configure_emscripten_python (context , working_dir ):
228
246
"""Configure the emscripten/host build."""
229
- config_site = os .fsdecode (
230
- EMSCRIPTEN_DIR / "config.site-wasm32-emscripten"
231
- )
247
+ config_site = os .fsdecode (EMSCRIPTEN_DIR / "config.site-wasm32-emscripten" )
232
248
233
249
emscripten_build_dir = working_dir .relative_to (CHECKOUT )
234
250
235
251
python_build_dir = NATIVE_BUILD_DIR / "build"
236
252
lib_dirs = list (python_build_dir .glob ("lib.*" ))
237
- assert (
238
- len ( lib_dirs ) == 1
239
- ), f"Expected a single lib.* directory in { python_build_dir } "
253
+ assert len ( lib_dirs ) == 1 , (
254
+ f"Expected a single lib.* directory in { python_build_dir } "
255
+ )
240
256
lib_dir = os .fsdecode (lib_dirs [0 ])
241
257
pydebug = lib_dir .endswith ("-pydebug" )
242
258
python_version = lib_dir .removesuffix ("-pydebug" ).rpartition ("-" )[- 1 ]
@@ -290,7 +306,9 @@ def configure_emscripten_python(context, working_dir):
290
306
quiet = context .quiet ,
291
307
)
292
308
293
- shutil .copy (EMSCRIPTEN_DIR / "node_entry.mjs" , working_dir / "node_entry.mjs" )
309
+ shutil .copy (
310
+ EMSCRIPTEN_DIR / "node_entry.mjs" , working_dir / "node_entry.mjs"
311
+ )
294
312
295
313
node_entry = working_dir / "node_entry.mjs"
296
314
exec_script = working_dir / "python.sh"
@@ -383,13 +401,15 @@ def main():
383
401
subcommands = parser .add_subparsers (dest = "subcommand" )
384
402
build = subcommands .add_parser ("build" , help = "Build everything" )
385
403
configure_build = subcommands .add_parser (
386
- "configure-build-python" , help = "Run `configure` for the " " build Python"
404
+ "configure-build-python" , help = "Run `configure` for the build Python"
387
405
)
388
406
make_mpdec_cmd = subcommands .add_parser (
389
- "make-mpdec" , help = "Clone mpdec repo, configure and build it for emscripten"
407
+ "make-mpdec" ,
408
+ help = "Clone mpdec repo, configure and build it for emscripten" ,
390
409
)
391
410
make_libffi_cmd = subcommands .add_parser (
392
- "make-libffi" , help = "Clone libffi repo, configure and build it for emscripten"
411
+ "make-libffi" ,
412
+ help = "Clone libffi repo, configure and build it for emscripten" ,
393
413
)
394
414
make_build = subcommands .add_parser (
395
415
"make-build-python" , help = "Run `make` for the build Python"
@@ -457,7 +477,11 @@ def main():
457
477
458
478
if not context .subcommand :
459
479
# No command provided, display help and exit
460
- print ("Expected one of" , ", " .join (sorted (dispatch .keys ())), file = sys .stderr )
480
+ print (
481
+ "Expected one of" ,
482
+ ", " .join (sorted (dispatch .keys ())),
483
+ file = sys .stderr ,
484
+ )
461
485
parser .print_help (sys .stderr )
462
486
sys .exit (1 )
463
487
dispatch [context .subcommand ](context )
0 commit comments