-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv.sh
495 lines (428 loc) · 15.2 KB
/
env.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# ex: ts=2 sw=4 et filetype=sh
is_bash() { test -n "$BASH_VERSION"; }
is_zsh() { test -n "$ZSH_VERSION"; }
if is_bash; then
thisscript="${BASH_SOURCE[0]}"
elif is_zsh; then
thisscript="${(%):-%N}"
else
echo "Unsupported shell!"
exit 1
fi
chromiumdir="$(cd $(dirname $thisscript); pwd)"
srcdir="${chromiumdir}/src"
gn_args=()
use_icecc=${CHR_USE_ICECC:-1}
_has() {
type $1 >/dev/null 2>&1
}
chr_bootstrap() {
echo "## Trying to bootstrap chromium env ${1:+(reason: $1)}" >&2
_has git || { echo "!! Error: git not installed" >&2; return 1; }
GIT_DIR="${chromiumdir}/.git" git submodule update --init --recursive
if [ $? -ne 0 ]; then
echo "WARN: Bootstrap failed!" >&2
return 1
else
source $thisscript
echo "Bootstrap done."
return 0
fi
}
ccache_ensure_config() {
local config_file=$1 key=$2 value=$3
local config_file_dir=$(dirname $config_file)
test -d $config_file_dir || mkdir -p $config_file_dir
test -f $config_file || touch $config_file
grep -qw $key $config_file || echo "$key = $value" >> $config_file
}
chr_ccache_setup() {
if [ -z $variant ]; then
echo "!! Error: Cannot setup ccache with no \$variant set!" >&2
echo "!! Run chr_config ??" >&2
return 1
fi
export CCACHE_BASEDIR=$chromiumdir
export CCACHE_DIR="${chromiumdir}/cache/ccache/${variant}"
export CCACHE_CPP2=yes
export CCACHE_SLOPPINESS='include_file_mtime,time_macros'
export CCACHE_DEPEND=true
ccache_ensure_config "${CCACHE_DIR}/ccache.conf" \
max_size ${CHR_CCACHE_SIZE:-50G}
}
chr_dump_config() {
echo "### srcdir: $srcdir"
echo "### outdir: $srcdir/$builddir"
echo "### variant: $variant"
echo "### type: $build_type"
echo "### python: $(which python)"
# Verbose?
[ "$1" != '-v' ] && return
echo "### python ver: $(python --version 2>&1)"
echo "### gn args:"
for arg in "${gn_args[@]}"; do
echo " $arg"
done
if [ "${#extra_gn_args[@]}" -gt 0 ]; then
echo "### extra gn args:"
for arg in "${extra_gn_args[@]}"; do
echo " $arg"
done
fi
}
_config_opts=( --variant=linux --variant=cros --variant=lacros --variant=custom
--type=release --type=debug --no-glib --ccache --component
--check --update-compdb --enable-lacros-support --quiet
--no-siso)
chr_setconfig() {
local quiet=0
local use_component=0
local use_glib=1
local use_siso=1
# output
variant='linux'
build_type='release'
gn_args=( 'enable_nacl=false' 'proprietary_codecs=true' 'ffmpeg_branding="Chrome"')
extra_gn_args=()
use_reclient=1
use_ccache=0
use_icecc=0
update_compdb=0
cros_with_lacros_support=0
# Tmp for debugging. TODO: Add cmd line option?
cros_camera=${cros_camera:-0}
enable_vaapi=${enable_vaapi:-0}
while (( $# )); do
case $1 in
--variant=*)
variant=${1##--variant=}
;;
--type=*)
build_type=${1##--type=}
;;
--ccache)
use_ccache=1
;;
--no-glib)
use_glib=0
;;
--component)
use_component=1
;;
--update-compdb)
update_compdb=1
;;
--enable-lacros-support)
cros_with_lacros_support=1
;;
--no-siso)
use_siso=0
;;
--quiet|-q)
quiet=1
;;
--*)
extra_gn_args+=("$1")
;;
esac
shift
done
case "$variant" in
linux)
gn_args+=('ozone_auto_platforms=false' 'use_ozone=true'
'use_xkbcommon=true' 'ozone_platform_wayland=true'
'ozone_platform_x11=true' 'use_bundled_weston=true')
(( enable_vaapi )) && gn_args+=('use_vaapi=true')
(( cros_camera )) && gn_args+=('enable_chromeos_camera_capture=true')
# Disable custom chromium build of libvulkan.so as gtk4 fails to load
# with it. See https://issues.chromium.org/345261080.
gn_args+=('angle_shared_libvulkan=false')
;;
cros)
use_glib=0
gn_args+=('target_os="chromeos"' 'use_xkbcommon=true'
'use_system_minigbm=false' 'use_intel_minigbm=true')
;;
lacros)
use_glib=0
gn_args+=('target_os="chromeos"' 'use_ozone=true'
'use_xkbcommon=true' 'ozone_auto_platforms=false'
'ozone_platform_wayland=true' 'ozone_platform="wayland"'
'ozone_platform_x11=false' 'use_system_minigbm=true'
'use_system_libdrm=true' 'use_wayland_gbm=false'
'use_glib=false' 'use_gtk=false'
'chromeos_is_browser_only=true'
'also_build_ash_chrome=false')
;;
esac
if (( use_reclient )); then
use_component=1
use_ccache=0
use_icecc=0
elif (( use_component )); then
use_icecc=1
use_ccache=1
fi
gn_opts=()
for arg in "${extra_gn_args}"; do
if [[ ! "$arg" =~ --args=.+ ]]; then
gn_opts+=("$arg")
continue
fi
local args_val=$(eval "echo ${arg##--args=}")
gn_args+=($args_val)
done
# reclient build
if (( use_reclient )); then
gn_args+=('use_remoteexec=true'
'reclient_cfg_dir="../../buildtools/reclient_cfgs/linux"')
else
# FIXME: Work around ENOENT errors for polymer.m.js
gn_args+=( 'optimize_webui=false' )
fi
# icecc
if (( use_icecc )); then
gn_args+=( 'linux_use_bundled_binutils=false' 'use_debug_fission=false' )
# FIXME: Mainly when using icecc, for some reason, we get
# some compiling warnings, so we disable warning-as-error for now
gn_args+=( 'treat_warnings_as_errors=false' )
fi
# component build
if (( use_component )); then
gn_args+=( 'is_component_build=true' )
(( use_reclient )) || variant+='-component'
fi
(( use_ccache )) && gn_args+=( 'cc_wrapper="ccache"' )
(( use_glib )) && gn_args+=( 'use_glib=true' )
(( use_siso )) && gn_args+=( 'use_siso=true' )
if [ "$build_type" = 'release' ]; then
builddir_base='out'
gn_args+=( 'is_debug=false' 'blink_symbol_level=0' )
# Make it more debuggable even for release builds
gn_args+=( 'symbol_level=1' 'dcheck_always_on=true' 'dcheck_is_configurable=false' )
else
builddir_base='out/debug'
gn_args+=( 'is_debug=true' 'symbol_level=1' )
fi
# Handle Google Keys (getting them from env vars).
test -n "$GOOGLE_API_KEY" &&
gn_args+=( "google_api_key=\"$GOOGLE_API_KEY\"" )
test -n "$GOOGLE_DEFAULT_CLIENT_SECRET" &&
gn_args+=( "google_default_client_secret=\"$GOOGLE_DEFAULT_CLIENT_SECRET\"" )
test -n "$GOOGLE_DEFAULT_CLIENT_ID" &&
gn_args+=( "google_default_client_id=\"$GOOGLE_DEFAULT_CLIENT_ID\"" )
if (( update_compdb )); then
local compdb_targets=${CHR_COMPDB_TARGETS:-chrome}
gn_opts+=(--export-compile-commands="$compdb_targets")
fi
builddir="${builddir_base}/${variant}"
lacros_sock='/tmp/lacros.sock'
# Keep this at the end of this function
chr_icecc_setup >/dev/null
chr_ccache_setup >/dev/null
(( quiet )) || chr_dump_config
}
chr_config() {
chr_setconfig $@
local cmd="gn gen \"$builddir\" ${gn_opts[@]} --args='${gn_args[*]}'"
local compdb="${srcdir}/compile_commands.json"
echo "Running cmd: $cmd"
( cd "$srcdir" && eval "$cmd" )
if (( update_compdb )) && [ ! -e $compdb ]; then
ln -sf "${builddir}/compile_commands.json" "$compdb" && \
echo "Updated $compdb" >&2
fi
}
chr_build() {
local artifact="${@:-chrome}"
local wrapper='time'
local cmd="$wrapper autoninja -C $builddir $artifact"
local result=0
echo "Running cmd: $cmd"
( cd "$srcdir" && eval "$cmd" )
result=$?
return $result
}
chr_get_user_data_dir() {
local suffix="${1:+-$1}"
local dir="${user_dir:-${chromiumdir}/tmp/user-data}-${variant}${suffix}"
echo $dir
}
chr_run() {
local user_dir
local wayland_ws=wayland
local clear=${clear:-0}
local ozone_plat_default=wayland
local extra_args=("$@")
local opts=( --enable-logging=stderr --no-sandbox )
local is_wayland=0
local is_lacros=0
local user_dir_suffix
case "$variant" in
linux)
user_dir_suffix=wayland
if [[ "${extra_args[*]}" =~ --ozone-platform=wayland ]]; then
is_wayland=1
elif [[ ! "${extra_args[*]}" =~ --ozone-platform=.+ ]]; then
echo "Using default ozone platform '$ozone_plat_default'"
extra_args+=( "--ozone-platform=${ozone_plat_default}" )
else
user_dir_suffix=x11
fi
;;
cros)
extra_args+=('--enable-wayland-server'
'--wayland-server-socket=wayland-exo'
'--no-startup-window --ash-dev-shortcuts')
if (( cros_with_lacros_support )); then
cros_features='LacrosProfileMigrationForceOff,LacrosOnly'
extra_args+=("--enable-features=${cros_features}"
"--lacros-mojo-socket-for-testing=${lacros_sock}")
fi
;;
lacros)
is_lacros=1
;;
esac
user_dir="$(chr_get_user_data_dir $user_dir_suffix)"
opts+=("--user-data-dir=${user_dir}")
if (( clear )) && [ -n "$user_dir" ]; then
echo "Cleaning ${user_dir}"
test -d "$user_dir" && rm -rf "$user_dir"
fi
local cmd="${builddir}/chrome ${opts[*]} ${extra_args[*]}"
local -a env prefix_cmd
if (( is_wayland )); then
cmd="env GDK_BACKEND=wayland $cmd"
# If running wayland compositor in an i3 session, move to the
# $wayland_ws workspace
_has 'i3-msg' && i3-msg workspace $wayland_ws
elif (( is_lacros )); then
env=('EGL_PLATFORM=surfaceless' 'WAYLAND_DISPLAY=wayland-exo')
prefix_cmd=('build/lacros/mojo_connection_lacros_launcher.py'
'-s' "$lacros_sock")
cmd="env ${env[*]} ${prefix_cmd[*]} $cmd"
fi
echo "Running cmd: $cmd"
( cd "$srcdir" && eval "$cmd" )
}
chr_icecc_setup() {
# 2. Update icecc bundle
(( use_icecc )) || return 0
test -d $ICECC_INSTALL_DIR || { echo "icecc install dir not found"; return 1; }
test -x $ICECC_CREATEENV || { echo "icecc-create-env not found"; return 1; }
test -x $ICECC_CCWRAPPER || { echo "icecc compilerwrapper not found"; return 1; }
local icecc_bundle_path="${ICECC_DATA_DIR}/icecc_clang.tgz"
if [[ "$1x" == "-ux" ]]; then
echo "Updating icecc bundle: ${icecc_bundle_path}"
local logfile="/tmp/chr_sync.log"
# Update icecc bundle accoring to current config
mkdir -pv $ICECC_DATA_DIR
(
set -e
cd $(mktemp -d)
eval "$ICECC_CREATEENV --clang ${LLVM_BIN_DIR}/clang"
mv -f *.tar.gz $icecc_bundle_path
) &>$logfile
fi
# Export config vars
export ICECC_CLANG_REMOTE_CPP=1
export ICECC_VERSION=$icecc_bundle_path
export CCACHE_PREFIX='icecc'
export PATH="${ICECC_INSTALL_DIR}/bin:$PATH"
echo 'Done.'
}
date_offset() {
date -d "$(date +%m/%d/%Y) -$*" +%m/%d/%y
}
_list_patches_opts=( --merged --week --month --year --markdown
--begin= --end= --user= --verbose )
chr_list_patches() {
local script=my_activity.py
local email=$(git config user.email)
local opts=('--quiet' '--changes')
local errors=$(mktemp /tmp/chr_XXXX.log)
local verbose=${V:-0}
local status_filter
local time_filter # Default is "last_week"
if ! type "$script" &>/dev/null; then
echo "$script not found in system \$PATH." >&2
return 1
fi
while (( $# )); do
case $1 in
-u | --user) shift && email=$1;;
-v | --verbose) verbose=1;;
--merged) status_filter='--merged-only';;
--week) time_filter='--last_week';;
--year) time_filter='--this_year';;
--month) time_filter="--begin=$(date +%m/01/%y)";;
[0-9]*d) time_filter="--begin=$(date_offset ${1:0:-1} day)";;
[0-9]*w) time_filter="--begin=$(date_offset ${1:0:-1} week)";;
[0-9]*m) time_filter="--begin=$(date_offset ${1:0:-1} month)";;
[0-9]*y) time_filter="--begin=$(date_offset ${1:0:-1} year)";;
--*) opts+=("$1");;
esac
shift
done
opts+=("-u $email" "$status_filter" "$time_filter" "${opts[@]}")
# Build fetch command
local cmd="$script ${opts[@]} 2> $errors"
(( verbose )) && echo "cmd: '$cmd'" >&2
# Fetch and process changes from crrev server
local patches=$(eval "$cmd" | tail -n +3)
# format and present output
local total=$(wc -l <<< $patches)
echo -e "Patches:\n"
echo "$patches" | cat -
echo -e "\nTotal: $total"
}
# bash/zsh completion
if is_bash; then
complete -W "${_config_opts[*]}" chr_setconfig
complete -W "${_config_opts[*]}" chr_config
complete -W "${_list_patches_opts[*]}" chr_list_patches
elif is_zsh; then
compctl -k "(${_config_opts[*]})" chr_setconfig
compctl -k "(${_config_opts[*]})" chr_config
compctl -k "(${_list_patches_opts[*]})" chr_list_patches
fi
# Setup depot_tools
depot="${chromiumdir}/tools/depot_tools"
if [ -r "$depot" ]; then
export PATH="${depot}:$PATH"
if [ -n "$BASH_VERSION" ]; then
source "${depot}/gclient_completion.sh"
fi
py2path="${chromiumdir}/tools/bin"
if [ -d "$py2path" ]; then
export PATH="${py2path}:${PATH}"
else
chr_bootstrap "python2 wrapper not found"
fi
else
chr_bootstrap "depot_tools not found"
fi
if test -r ~/.boto; then
export NO_AUTH_BOTO_CONFIG=~/.boto
fi
LLVM_BIN_DIR="${srcdir}/third_party/llvm-build/Release+Asserts/bin"
export PATH="$LLVM_BIN_DIR:$PATH"
# Basic icecc setup (the remaining is done in `chr_icecc_setup` function)
ICECC_DATA_DIR="${chromiumdir}/icecc"
ICECC_INSTALL_DIR=${ICECC_INSTALL_DIR:-/usr/lib/icecream}
ICECC_CREATEENV=${ICECC_CREATEENV:-$ICECC_INSTALL_DIR/bin/icecc-create-env}
ICECC_CCWRAPPER=${ICECC_CCWRAPPER:-$ICECC_INSTALL_DIR/libexec/icecc/compilerwrapper}
# Chrome env vars
# Needed for tests (browser tests?) when build dir is more than 1 level deeper
# (e.g: out/Default). If this is not set, embedded web test server fail to
# start cause it cannot find cert files.
export CR_SOURCE_ROOT=$srcdir
# Default config params
CHR_CONFIG_TARGET="${CHR_CONFIG_TARGET:---variant=linux}"
CHR_CONFIG_ARGS="${CHR_CONFIG_ARGS:---type=release}"
CHR_COMPDB_TARGETS="${CHR_COMPDB_TARGETS:-chrome,views_unittests,interactive_ui_tests,ozone_unittests}"
chr_setconfig -q $CHR_CONFIG_TARGET $CHR_CONFIG_ARGS
# Set a sufficiently large limit for file descriptors (Goma builds with
# -j2000 would complain if this is not set).
ulimit -n 4096