Repository navigation
Expand file tree
/
Copy pathpackage-pythonhome.sh
More file actions
executable file
·51 lines (41 loc) · 2.06 KB
/
Copy pathpackage-pythonhome.sh
File metadata and controls
executable file
·51 lines (41 loc) · 2.06 KB
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
#!/bin/bash -e
# Creates a minimal Python file hierarchy at $PACKAGEDIR
# Copyright (C) 2018, 2019, 2020 Sylvain Beucler
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
FILE_PACKAGER="python3 $(dirname $(which emcc))/tools/file_packager.py"
PREFIX=${PREFIX:-$(dirname $(readlink -f $0))/destdir}
PACKAGEDIR=${PACKAGEDIR:-$(dirname $(readlink -f $0))/package}
OUTDIR=${OUTDIR:-.}
CROSSPYTHON=$(dirname $(readlink -f $0))/crosspython-static/bin/python3
# Python home
# optional lz4 compression, requires '-s LZ4=1'
LZ4=
if [ "$1" == "--lz4" ]; then LZ4="--lz4"; shift; fi
rm -rf $PACKAGEDIR/
mkdir -p $PACKAGEDIR
# Hard-coded modules: for 'print("hello, world.")'
# $@: additional, app-specific modules
(cd $PREFIX/lib/python3.8/ && $CROSSPYTHON -OO -m compileall .) >/dev/null || true
for i in site.py os.py stat.py posixpath.py genericpath.py abc.py encodings/__init__.py codecs.py encodings/aliases.py encodings/utf_8.py io.py _collections_abc.py _sitebuiltins.py encodings/ascii.py encodings/latin_1.py \
"$@"; do
mkdir -p $PACKAGEDIR/lib/python3.8/$(dirname $i)/__pycache__
# Install to legacy .pyc location for size-efficient source-less distribution
cp -au $PREFIX/lib/python3.8/$(dirname $i)/__pycache__/$(basename ${i%.py}.cpython-38.opt-2.pyc) \
$PACKAGEDIR/lib/python3.8/${i%.py}.pyc
done
# Large and leaks build paths, clean it:
#echo 'build_time_vars = {}' > $PACKAGEDIR/lib/python3.8/lib-dynload/_sysconfigdata__linux_x86_64-linux-gnu.py
#(cd $PACKAGEDIR && $CROSSPYTHON -OO -m py_compile lib/python3.8/_sysconfigdata.py)
#rm -f $PACKAGEDIR/lib/python3.8/_sysconfigdata.py
# --no-heap-copy: suited for ALLOW_MEMORY_GROWTH=1
PACKAGEDIR_FULLPATH=$(readlink -f $PACKAGEDIR)
(
cd $OUTDIR; # use relative path in xxx-data.js
$FILE_PACKAGER \
pythonhome.data --js-output=pythonhome-data.js \
--preload $PACKAGEDIR_FULLPATH@/ \
--use-preload-cache --no-heap-copy $LZ4
)