-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·254 lines (215 loc) · 6.58 KB
/
build.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
249
250
251
252
253
254
#!/bin/bash
# setup:
#
# 1. install icecc + cccahe, and enable scheduler:
#
# sudo aptitude install icecc ccache
# sudo systemctl enable icecc-scheduler.service
# sudo systemctl start icecc-scheduler.service
#
# 2. manually add custom_hooks to /media/src/chromium/.gclient:
#
# "custom_hooks": [ {"pattern": ".", "action": ["icecc-create-env.py"] } ]
#
# for full instructions, see: https://github.com/lilles/icecc-chromium
SRC=$(realpath $(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd))
ATTEMPTS=10
BASE=$HOME/src
JOBS=$((`nproc` + 2))
TTL=86400
UPDATE=0
VERSION=
OPTIND=1
while getopts "a:b:j:t:uv:" opt; do
case "$opt" in
a) ATTEMPTS=$OPTARG ;;
b) BASE=$OPTARG ;;
j) JOBS=$OPTARG ;;
t) TTL=$OPTARG ;;
u) UPDATE=1 ;;
v) VERSION=$OPTARG ;;
esac
done
set -e
# determine last update state
LAST=0
if [ -e $SRC/.last ]; then
LAST=$(cat $SRC/.last)
fi
if [ "$((`date +%s` - $LAST))" -gt $TTL ]; then
UPDATE=1
fi
# determine version
if [ -z "$VERSION" ]; then
VERSION=$(
curl -s https://omahaproxy.appspot.com/all.json | \
jq -r '.[] | select(.os == "win64") | .versions[] | select(.channel == "stable") | .current_version'
)
fi
echo "ATTEMPTS: $ATTEMPTS"
echo "BASE: $BASE"
echo "JOBS: $JOBS"
echo "UPDATE: $UPDATE"
echo "VERSION: $VERSION"
mkdir -p $SRC/out
TMPDIR=$(mktemp -d -p /tmp content-shell-$VERSION.XXXXX 2&>/dev/null || mktemp -d /tmp/content-shell-$VERSION.XXXXX)
ARCHIVE=$SRC/out/content-shell-$VERSION.tar.bz2
echo "TMPDIR: $TMPDIR"
echo "ARCHIVE: $ARCHIVE"
# grab depot_tools
if [ ! -d $SRC/depot_tools ]; then
pushd $SRC &> /dev/null
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
popd &> /dev/null
fi
# grab icecc-chromium
#if [ ! -d $SRC/icecc-chromium ]; then
# pushd $SRC &> /dev/null
# git clone https://github.com/lilles/icecc-chromium.git
# popd &> /dev/null
#fi
# update to latest depot_tools and icecc-chromium
if [ "$UPDATE" -eq "1" ]; then
echo "UPDATING $SRC/depot_tools ($(date))"
pushd $SRC/depot_tools &> /dev/null
git reset --hard
git checkout main
git pull
popd &> /dev/null
# echo "UPDATING $SRC/icecc-chromium ($(date))"
# pushd $SRC/icecc-chromium
# git reset --hard
# git checkout master
# git pull
# popd &> /dev/null
fi
export PATH=$SRC/depot_tools:$PATH
#export PATH=$SRC/depot_tools:$SRC/icecc-chromium:$PATH
#source $SRC/icecc-chromium/ccache-env
mkdir -p $BASE/chromium
# retrieve chromium source tree
if [ ! -d $BASE/chromium/src ]; then
echo "RETRIEVING $BASE/chromium/src ($(date))"
# retrieve
pushd $BASE/chromium &> /dev/null
fetch --nohooks chromium
popd &> /dev/null
# run hooks
echo "RUNNING GCLIENT HOOKS $BASE/chromium/src ($(date))"
pushd $BASE/chromium/src &> /dev/null
gclient runhooks
popd &> /dev/null
fi
pushd $BASE/chromium/src &> /dev/null
# update chromium source tree
if [ "$UPDATE" -eq "1" ]; then
# # files in content that contain the HeadlessChrome user-agent string
# USERAGENT_FILES=$(find ./headless/ -type f -iname \*.cc -print0|xargs -r0 egrep -Hi '"(Headless)?Chrome"'|awk -F: '{print $1}'|sort|uniq)
# echo "RESETTING FILES $USERAGENT_FILES ($(date))"
# for f in $USERAGENT_FILES; do
# git checkout $f
# done
# update
echo "CHANGING TO main ($(date))"
git checkout main
echo "REBASING TREE ($(date))"
git rebase-update
# mark last
date +%s > $SRC/.last
echo "NEW LAST: $(cat $SRC/.last) ($(date))"
fi
PROJECT=out/content-shell
# determine sync status
SYNC=$UPDATE
if [ "$VERSION" != "$(git name-rev --tags --name-only $(git rev-parse HEAD))" ]; then
SYNC=1
fi
if [ "$SYNC" -eq "1" ]; then
# # files in headless that contain the HeadlessChrome user-agent string
# USERAGENT_FILES=$(find ./headless/ -type f -iname \*.cc -print0|xargs -r0 egrep -Hi '"(Headless)?Chrome"'|awk -F: '{print $1}'|sort|uniq)
# echo "RESETTING FILES $USERAGENT_FILES ($(date))"
# for f in $USERAGENT_FILES; do
# git checkout $f
# done
# checkout and sync third-party dependencies
echo "CHECKING OUT $VERSION ($(date))"
git checkout $VERSION
echo "GCLIENT SYNC $VERSION ($(date))"
gclient sync \
--with_branch_heads \
--with_tags \
--delete_unversioned_trees \
--reset
# # change user-agent
# # files in headless that contain the HeadlessChrome user-agent string
# USERAGENT_FILES=$(find ./headless/ -type f -iname \*.cc -print0|xargs -r0 egrep -Hi '"(Headless)?Chrome"'|awk -F: '{print $1}'|sort|uniq)
# for f in $USERAGENT_FILES; do
# perl -pi -e 's/"HeadlessChrome"/"Chrome"/' $f
# done
# ensure build directory exists
mkdir -p $PROJECT
# gn build args
# import(\"$SRC/icecc-chromium/icecc.gni\") # icecc parameters (removed)
echo "
is_debug=false
is_official_build=true
symbol_level=0
blink_symbol_level=0
enable_nacl=false
chrome_pgo_phase=0
" > $PROJECT/args.gn
# generate build files
gn gen $PROJECT
fi
# build
RET=1
for i in $(seq 1 $ATTEMPTS); do
RET=1
echo "STARTING BUILD ATTEMPT $i FOR $VERSION ($(date))"
#$SRC/icecc-chromium/icecc-ninja -j $JOBS -C $PROJECT content_shell chrome_sandbox && RET=$?
$SRC/depot_tools/ninja -j $JOBS -C $PROJECT content_shell && RET=$?
if [ $RET -eq 0 ]; then
echo "COMPLETED BUILD ATTEMPT $i FOR $VERSION ($(date))"
break
fi
echo "BUILD ATTEMPT $i FOR $VERSION FAILED ($(date))"
done
if [ $RET -ne 0 ]; then
echo "ERROR: COULD NOT COMPLETE BUILD FOR $VERSION ($(date))"
exit 1
fi
# build stamp
echo $VERSION > $PROJECT/.stamp
# copy files
mkdir -p $TMPDIR/content-shell
cp -a $PROJECT/{content_shell,.stamp} $TMPDIR/content-shell
cp -a $PROJECT/{libEGL.so,libGLESv2.so,libvk_swiftshader.so,libvulkan.so.1,vk_swiftshader_icd.json} $TMPDIR/content-shell
cp -a $PROJECT/{content_shell.pak,shell_resources.pak,ui_resources_100_percent.pak,ui_test.pak} $TMPDIR/content-shell
cp -a $PROJECT/{icudtl.dat,snapshot_blob.bin,v8_context_snapshot.bin} $TMPDIR/content-shell
popd &> /dev/null
pushd $TMPDIR/content-shell &> /dev/null
# rename and strip
mv content_shell content-shell
strip content-shell *.so *.so.1
chmod -x *.so *.so.1
## verify content-shell runs and reports correct version
#./content-shell --remote-debugging-port=5000 &> /dev/null & PID=$!
#sleep 1
#BROWSER=$(curl --silent --connect-timeout 5 http://localhost:5000/json/version|jq -r '.Browser')
#kill -s SIGTERM $PID
#set +e
#wait $PID 2>/dev/null
#set -e
#if [ "$BROWSER" != "Chrome/$VERSION" ]; then
# echo "ERROR: CONTENT-SHELL REPORTED VERSION '$BROWSER', NOT 'Chrome/$VERSION'!"
# exit 1
#else
# echo "CONTENT SHELL REPORTED VERSION '$BROWSER'"
#fi
#popd &> /dev/null
# remove previous
rm -f $ARCHIVE
# package tar
pushd $TMPDIR &> /dev/null
tar -cjf $ARCHIVE content-shell
popd &> /dev/null