-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathdev.sh
executable file
·249 lines (241 loc) · 9.53 KB
/
dev.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
245
246
247
248
#!/usr/bin/env bash
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
codeserver_remove_unuseful_node_module() {
# remove $2 from $1/package.json
if [[ -f $1/package.json ]]; then
jq "del(.dependencies[\"$2\"]) | del(.devDependencies[\"$2\"])" $1/package.json > $1/package.json.tmp
chown $(stat -c "%u:%g" $1/package.json) $1/package.json.tmp
mv $1/package.json.tmp $1/package.json
fi
# remove $2 from $1/yarn.lock
if [[ -f $1/yarn.lock ]]; then
# remove $2 and its versions from yarn.lock
sed -i.bk "/^$2@.*:/,/^$/d" $1/yarn.lock
# chown $1/yarn.lock back to the original user
chown $(stat -c "%u:%g" $1/yarn.lock.bk) $1/yarn.lock
rm $1/yarn.lock.bk
fi
}
codeserver_remove_unuseful_node_modules() {
codeserver_remove_unuseful_node_module $1 kerberos
}
main() {
cd "$(dirname "$0")/"
case "$1" in
diff)
cd code-server/lib
diff -x node_modules -x build -x .build -x 'out-*' -x out -ru vscode.orig vscode
;;
save-diff)
cd code-server/lib
diff -x node_modules -x build -x .build -x 'out-*' -x out -ru vscode.orig vscode > ../../vscode.vh.patch
;;
apply-patch)
if [[ -f ./vscode.vh.patch ]]; then
cd code-server/lib/vscode && git apply ../../../vscode.vh.patch
fi
rm -rf .pc;QUILT_PATCHES=patches/code-server quilt push -a
rm -rf .pc;QUILT_PATCHES=patches/node-src quilt push -a
;;
build-android-env)
docker build ./container/android -t vsandroidenv:latest
;;
release)
if [ "$EUID" -ne 0 ]; then
USERRUN=
else
BUILDING_USER=$(ls -n /vscode/dev.sh | awk '{print $3}')
BUILDING_GROUP=$(ls -n /vscode/dev.sh | awk '{print $4}')
if ! grep -q code-builder /etc/passwd; then
groupadd -g $BUILDING_GROUP builder-gr
useradd -m -g $BUILDING_GROUP -u $BUILDING_USER -N code-builder
fi
USERRUN="sudo -E -H -u #$BUILDING_USER"
fi
set -x
echo $ANDROID_ARCH > current_building
gcc -shared -fPIC /vscode-build/lib/node-preload.c -o /vscode-build/lib/node-preload.so -ldl
chmod 0744 /vscode-build/lib/node-preload.so
case $ANDROID_ARCH in
arm|armeabi-v7a)
ARCH_NAME="armeabi-v7a"
NODE_CONFIGURE_NAME="arm"
TERMUX_ARCH="arm"
;;
x86)
ARCH_NAME="x86"
NODE_CONFIGURE_NAME="x86"
TERMUX_ARCH="i686"
;;
x86_64)
ARCH_NAME="x86_64"
NODE_CONFIGURE_NAME="x86_64"
TERMUX_ARCH="x86_64"
;;
arm64|aarch64)
ARCH_NAME="arm64-v8a"
NODE_CONFIGURE_NAME="arm64"
TERMUX_ARCH="aarch64"
;;
*)
echo "Unsupported arch $ANDROID_ARCH"
exit 1
;;
esac
set -e
if [ ! -z "$BUILD_NODE" ]; then
pushd node-src
make clean
git clean -dfx
git checkout -f HEAD
(cd ..; rm -rf .pc; QUILT_PATCHES=patches/node-src quilt push -a -f)
sed -i "s|<(android_ndk_path)|$NDK|g" common.gypi
$USERRUN PATH=/vscode-build/hostbin:$PATH CC_host=gcc CXX_host=g++ LINK_host=g++ ./android-configure /opt/android-ndk/ $ANDROID_BUILD_API_VERSION $NODE_CONFIGURE_NAME
NODE_MAKE_CUSTOM_LDFLAGS=
if [[ "$ANDROID_ARCH" == "x86" ]]; then
NODE_MAKE_CUSTOM_LDFLAGS="$NODE_MAKE_CUSTOM_LDFLAGS -latomic"
fi
LDFLAGS="$LDFLAGS $NODE_MAKE_CUSTOM_LDFLAGS" PATH=/vscode-build/hostbin:$PATH JOBS=$(nproc) make -j $(nproc)
$USERRUN mkdir -p include/node
$USERRUN cp config.gypi include/node/config.gypi
popd
fi
for f in /usr/lib/node_modules/npm/bin/node-gyp-bin/node-gyp; do
if [ ! -f "$f.orig" ]; then
mv $f "$f.orig"
fi
echo -e '#!/bin/bash\n/vscode-build/bin/node-gyp-hook $0 $@\n'$f'.orig --nodedir /vscode/node-src/ "$@"' > $f
chmod 0747 $f
chmod 0747 "$f.orig"
done
for f in /usr/bin/node; do
if [ ! -f "$f.orig" ]; then
mv $f "$f.orig"
fi
echo -e '#!/bin/bash\n/vscode-build/bin/node-hook '$f'.orig "$@"' > $f
chmod 0747 $f
chmod 0747 "$f.orig"
done
export VERSION=$(cd code-server && git describe --tags)
YARN="$USERRUN CC_target=cc AR_target=ar CXX_target=cxx LINK_target=ld PATH=/vscode-build/bin:$PATH yarn"
if [ ! -z "$BUILD_RELEASE" ]; then
pushd code-server
$USERRUN git checkout -f HEAD
git clean -dfx
$USERRUN git submodule foreach --recursive 'git checkout -f HEAD'
git submodule foreach --recursive 'git clean -dfx'
quilt push -a # changes made by code-server
(cd ..;rm -rf .pc;QUILT_PATCHES=patches/code-server quilt push -a) || true # changes made by me
codeserver_remove_unuseful_node_modules lib/vscode
codeserver_remove_unuseful_node_modules lib/vscode/remote
yarn cache clean
$USERRUN yarn cache clean
sub_builder() {
find $1 -iname yarn.lock | grep -v node_modules | while IPS= read dir
do
[[ "$dir" == "./test/unit/node/test-plugin/yarn.lock" ]] && continue
echo "$dir"
pushd "$(dirname "$dir")"
set -x
echo "* Work on $(pwd)"
$YARN --frozen-lockfile --production=false
[[ "$(jq ".scripts.build" package.json )" != "null" ]] && $YARN build
[[ "$(jq ".scripts.release" package.json )" != "null" ]] && $YARN release
[[ "$(jq ".scripts[\"release:standalone\"]" package.json )" != "null" ]] && $YARN release:standalone
$YARN --frozen-lockfile --production
set +x
popd
done
}
rm -rf release release-standalone node_modules
export NODE_PATH=/usr/lib/node_modules
npm install -g @mapbox/node-pre-gyp node-addon-api
$USERRUN mv -f yarn.lock.origbk yarn.lock || true
$YARN --production=false --frozen-lockfile
$USERRUN mv -f yarn.lock yarn.lock.origbk || true
sub_builder .
$USERRUN mv -f yarn.lock.origbk yarn.lock || true
sub_builder lib
pushd lib/vscode
$YARN --frozen-lockfile --production=false
popd
$YARN build
DISABLE_V8_COMPILE_CACHE=1 $YARN build:vscode
$YARN release
#nonexisten proxy to disable downloading
$YARN release:standalone
cd release-standalone
$YARN --production --frozen-lockfile --force
popd
fi
rm -rf cs-$ANDROID_ARCH.tgz libc++_shared.so node
cp node-src/out/Release/node ./
case $ANDROID_ARCH in
arm|armeabi-v7a)
LIBCPP_ARCH_NAME="arm-linux-androideabi"
;;
x86)
LIBCPP_ARCH_NAME="i686-linux-android"
;;
x86_64)
LIBCPP_ARCH_NAME="x86_64-linux-android"
;;
arm64|aarch64)
LIBCPP_ARCH_NAME="aarch64-linux-android"
;;
*)
echo "Unsupported arch $ANDROID_ARCH"
exit 1
;;
esac
cp /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/$LIBCPP_ARCH_NAME/libc++_shared.so ./libc++_shared.so
VERSION_SUFFIX=
if [[ -f patch_version ]]; then
VERSION_SUFFIX="-p$(cat patch_version)"
fi
echo "$VERSION$VERSION_SUFFIX" | tr -d '\n' | $USERRUN tee code-server/VERSION
$USERRUN ANDROID_ARCH=$ANDROID_ARCH TERMUX_ARCH=$TERMUX_ARCH bash ./scripts/download-rg.sh
find code-server/release-standalone -iname rg | while IPS= read p
do
echo "Replace rg in $p"
$USERRUN cp rg/$ANDROID_ARCH/rg $p
echo md5 $p
done
if [[ "$(find code-server/release-standalone -iname '*.orig')" != "" ]]; then
find code-server/release-standalone -iname '*.orig'
exit -1
fi
$USERRUN tar -czvf cs-$ANDROID_ARCH.tgz code-server/release-standalone code-server/VERSION node "libc++_shared.so"
{
find code-server/release-standalone/ -iname '*.node' | grep -vE 'watcher/prebuilds'
find code-server -type f -executable -print
} | sort | uniq | xargs file | grep -vE '(ASCII|UTF-8|OpenType|TrueType|JSON)'
;;
docker-run)
shift
set -x
docker run --rm \
-w /vscode \
--memory=13g \
--memory-swap=-1 \
-e ANDROID_BUILD_API_VERSION=24 \
-v $(pwd):/vscode \
-v $(pwd)/container/android:/vscode-build \
-v $(pwd)/node:/vscode-node \
-v $(pwd)/.git/modules/code-server:/.git/modules/code-server \
--entrypoint env \
vsandroidenv:latest OKOKOKRUN=1 "$@"; exit $?
;;
*)
docker run --rm -it \
-w /vscode \
-e ANDROID_BUILD_API_VERSION=24 \
-v $(pwd):/vscode \
-v $(pwd)/container/android:/vscode-build \
-v $(pwd)/node:/vscode-node \
-v $(pwd)/.git/modules/code-server:/.git/modules/code-server \
vsandroidenv:latest bash; exit $?
;;
esac
}
main "$@"