-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.z-run
More file actions
163 lines (120 loc) · 4.24 KB
/
bundle.z-run
File metadata and controls
163 lines (120 loc) · 4.24 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
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
#!/dev/null
::// bundle / ...
:: bundle / run / editor :: exec -- "${ZRUN[@]}" ':: bundle / run / *' editor "${@}"
:: bundle / run / pager :: exec -- "${ZRUN[@]}" ':: bundle / run / *' pager "${@}"
:: bundle / build / editor :: exec -- "${ZRUN[@]}" ':: bundle / build / *' editor "${@}"
:: bundle / build / pager :: exec -- "${ZRUN[@]}" ':: bundle / build / *' pager "${@}"
--<< bundle / run / *
test "${#}" -ge 1 ; _main="${1}" ; shift -- 1
"${ZRUN[@]}" ':: bundle / build / *' "${_main}"
exec -- "./.outputs/${_main}--bundle.zip" "${@}"
!!
--<< bundle / build / *
test "${#}" -ge 1 ; _main="${1}" ; shift -- 1
_compress=true
_version=3.11
test "${#}" -eq 0
test -d ./.outputs
test -f "./sources/exec_${_main}.py"
"${ZRUN[@]}" ':: sources / embedded / hash'
_bundle_sources="$( readlink -m -- "./.outputs/${_main}--bundle.sources" )"
_bundle_zip="$( readlink -m -- "./.outputs/${_main}--bundle.zip" )"
if test -e "${_bundle_zip}" ; then
mv -T -- "${_bundle_zip}" "${_bundle_zip}.old"
fi
if test ! -e "${_bundle_sources}" ; then
mkdir -- "${_bundle_sources}"
fi
rsync \
-a \
--delete \
--exclude '/__main__.py' \
-- \
./sources/ \
"${_bundle_sources}/" \
#
if test ! -e "${_bundle_sources}/__main__.py" ; then
cp -T -- \
"${_bundle_sources}/exec_${_main}.py" \
"${_bundle_sources}/__main__.py" \
#
fi
_build_target=release
_build_number="$( exec -- cat -- ./sources/sce_embedded/build/number.txt )"
_build_version="$( exec -- cat -- ./sources/sce_embedded/build/version.txt )"
_build_timestamp="$( exec -- cat -- ./sources/sce_embedded/build/timestamp.txt )"
_build_sources_hash="$( exec -- cat -- ./sources/sce_embedded/build/sources.hash )"
_build_git_hash="$( exec -- cat -- ./.outputs/markers/build-git-hash.txt )"
sed -r \
-e 's#@\{SCE_BUILD_TARGET}#'"${_build_target}"'#' \
-e 's#@\{SCE_BUILD_NUMBER}#'"${_build_number}"'#' \
-e 's#@\{SCE_BUILD_VERSION}#'"${_build_version}"'#' \
-e 's#@\{SCE_BUILD_TIMESTAMP}#'"${_build_timestamp}"'#' \
-e 's#@\{SCE_BUILD_SOURCES_HASH}#'"${_build_sources_hash}"'#' \
-e 's#@\{SCE_BUILD_GIT_HASH}#'"${_build_git_hash}"'#' \
< "${_bundle_sources}/sce_embedded/embedded.py" \
> "${_bundle_sources}/sce_embedded/embedded.py.tmp" \
#
mv -T -- \
"${_bundle_sources}/sce_embedded/embedded.py.tmp" \
"${_bundle_sources}/sce_embedded/embedded.py" \
#
_touch_timestamp="${_build_timestamp//-/}"
_touch_timestamp="${_touch_timestamp:0:12}.${_touch_timestamp:12:14}"
find "${_bundle_sources}/" -exec touch -t "${_touch_timestamp}" -- {} +
"python${_version}" -u -O -O -B -E -S -s -R -m compileall -q -b -- "${_bundle_sources}"
if test "${_compress}" == true ; then
find "${_bundle_sources}/" -xtype f -name '*.py' -delete
fi
_touch_timestamp="${_build_timestamp//-/}"
_touch_timestamp="${_touch_timestamp:0:12}.${_touch_timestamp:12:14}"
find "${_bundle_sources}/" -exec touch -c -t "${_touch_timestamp}" -- {} +
if test -e "${_bundle_zip}.tmp.1" ; then
rm -- "${_bundle_zip}.tmp.1"
fi
if test -e "${_bundle_zip}.tmp.2" ; then
rm -- "${_bundle_zip}.tmp.2"
fi
_zip_level="-0"
if test "${_compress}" == true ; then
_zip_level="-9"
fi
execline-cd "${_bundle_sources}" \
find . -xtype f -print \
| LC_ALL=C sort \
| execline-cd "${_bundle_sources}" \
zip \
"${_zip_level}" \
-q \
-o \
-X \
"${_bundle_zip}.tmp.1" \
-@ \
#
_python_arguments=(
-u # unbuffered `stdin` and `stdout`
-O -O # optimizations enabled
-B # disable writing `*.py[oc]`
-E # ignore `PYTHON*` environment variables
-S # disable `sys.path` manipulation
-s # disable user-site
-R # hash randomization
)
cat -- \
<( printf '#!/usr/bin/env -S python%s %s\n' "${_version}" "${_python_arguments[*]}" ) \
"${_bundle_zip}.tmp.1" \
> "${_bundle_zip}.tmp.2" \
#
chmod +x -- "${_bundle_zip}.tmp.2"
rm -- "${_bundle_zip}.tmp.1"
mv -T -- "${_bundle_zip}.tmp.2" "${_bundle_zip}.new"
if test ! -e "${_bundle_zip}.old" ; then
mv -T -- "${_bundle_zip}.new" "${_bundle_zip}"
elif ! cmp -s -- "${_bundle_zip}.new" "${_bundle_zip}.old" ; then
mv -T -- "${_bundle_zip}.new" "${_bundle_zip}"
rm -- "${_bundle_zip}.old"
else
mv -T -- "${_bundle_zip}.old" "${_bundle_zip}"
rm -- "${_bundle_zip}.new"
fi
!!