forked from pygame-web/pygbag
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-rootfs.sh
executable file
·246 lines (186 loc) · 4.61 KB
/
build-rootfs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/bash
. scripts/vendoring.sh
. ${CONFIG:-$SDKROOT/config}
mkdir -p build
FS=build/fs
echo "
* packing minimal stdlib for
PYTHON=$HPY
FS=$FS
PYTHONPYCACHEPREFIX=$PYTHONPYCACHEPREFIX
"
if echo $PYTHONPYCACHEPREFIX |grep -q $SDKROOT
then
echo "
* cleaning up compiled pyc if any in $PYTHONPYCACHEPREFIX/./$SDKROOT/
"
rm -rf $PYTHONPYCACHEPREFIX/./$SDKROOT/
fi
$HPY -B -v <<END 2>&1 | tee log |grep py$ > $FS
from __future__ import annotations
import sys
M1='os, json, builtins, shutil, zipimport, time, trace, traceback, '
M2='asyncio, inspect, _thread, importlib, ctypes, tomllib, pathlib'
for mod in (M1+M2).split(', '):
try:
__import__(mod)
except:
pass
try:
# installer
sys.stdout.reconfigure(encoding='cp437')
# bokeh
sys.stdout.reconfigure(encoding='unicode-escape')
sys.stdout.reconfigure(encoding='utf-16')
sys.stdout.reconfigure(encoding='utf-8')
except:
pass
import sysconfig
sysconfig.get_paths()
import multiprocessing.connection
# sockets ????
import asyncio.selector_events
import multiprocessing
# mypy
import typing
# ? _extensions
# for dom event subscriptions and js interface
import webbrowser
import platform
# for pyodide runPython emulation
from textwrap import dedent
# FIXME: because _sqlite3 is builtins anyway ?
import sqlite3
# for pygame-script FS
import tempfile
# for console
import code
# for wget to overload urlretrieve
import urllib.request
# installer "cp437"
import compileall, csv, configparser
from email.policy import compat32
#telemetrix
import concurrent.futures.thread
# micropip
import importlib.metadata
# pygame_gui
import html.parser
import importlib.readers
#pymunk+tests
import unittest, locale
import platform
import numbers, random
#pgzero
import hashlib, queue, pkgutil
#pytmx
import gzip
import zlib
from xml.etree import ElementTree
import distutils.spawn
#matplotlib
import uuid
#arcade
import ctypes.util
#pygame_gui
import importlib.resources
#curses
try:
import curses
except:
print('_curses not built')
#rich
import getpass
import fractions
#nurses_2
import tty
# cffi
import copy
# datetime
import datetime
import _strptime
# numpy
import secrets
# HPy
import plistlib
from pkg_resources import resource_filename
# netpbm
from mimetypes import guess_type
from pprint import pprint
# pgex
import typing
try:
from typing import tuple
except:
pass
# nodezator
from logging.handlers import RotatingFileHandler
from colorsys import rgb_to_hls, hls_to_rgb
import xml.dom.minidom
from xml.dom import expatbuilder
import pydoc
# Box2D
import optparse
# bokeh
import hmac
#ursina
import imghdr
# pep722
import pyparsing
import packaging.requirements
#import installer
try:
import imp
except:
# python 3.12 !
pass
if 0:
import cffi
from cffi import FFI
ffi = FFI()
END
echo "-----------------------------------------------------------"
$HPY -u -I -B <<END
import sys, os
stdlp=""
with open("build/stdlib.list","w") as tarlist:
sysconf = "_sysconfigdata__linux_$(arch)-linux-gnu.py"
with open("$FS") as fs:
for l in fs.readlines():
#print( l.strip() )
if l.find('/')<0:
continue
_,trail = l.strip().split('/',1)
try:
stdlp, name = trail.rsplit('usr/lib/',1)
except Exception as x:
print(f"ERROR {l=}", x, file=sys.stderr)
print(sys.path, file=sys.stderr)
continue
#print (stdlp, name)
#if name.find('asyncio/unix_events.py')>0:
# continue
if name.find('/site-packages/setuptools/')>0:
continue
if name.find('/site-packages/pkg_resources/_vendor/')>0:
continue
if name.endswith(sysconf):
name = name.replace(sysconf,"_sysconfigdata__emscripten_wasm32-emscripten.py")
if name.find('asyncio/selector_')>=0:
#print(name, file=tarlist )
name = name.replace('asyncio/selector_','asyncio/wasm_')
print(name, file=tarlist )
else:
stdlp = stdlp.replace('$(arch)','emsdk')
print(stdlp)
tarcmd=f"tar --directory=/{stdlp}usr/lib --files-from=build/stdlib.list -cf build/stdl.tar"
print(tarcmd)
os.system(tarcmd)
END
echo "*******************************************"
grep -v ^import log |grep -v ^#
echo "*******************************************"
mkdir -p build/stdlib-rootfs
tar xvf build/stdl.tar -C build/stdlib-rootfs | wc -l
rm build/stdl.tar
du -hs build/stdlib-rootfs/python${PYBUILD}