Repository navigation
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·388 lines (327 loc) · 12.2 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·388 lines (327 loc) · 12.2 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
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
if [ -z "${ZSH_VERSION:-}" ]; then
echo "dev.sh requires zsh; run 'source dev.sh' from zsh." >&2
return 1 2>/dev/null || exit 1
fi
_root_dir=$(dirname $(greadlink -f $0))
source "$_root_dir/devutils/shared.sh"
source "$_root_dir/devutils/set_quilt_vars.sh"
___helium_setup_presetup() {
local download=true
if [ $# -eq 1 ] && [ "$1" = -c ]; then
download=false
elif [ $# -ne 0 ]; then
echo "usage: he setup|presetup [-c]" >&2
return 1
fi
if [ -d "$_src_dir/out" ]; then
echo "$_src_dir/out already exists" >&2
return
fi
rm -rf "$_src_dir" && mkdir -p "$_src_dir"
fetch_sources "$download"
mkdir -p "$_out_dir"
cd "$_src_dir"
python3 "$_main_repo/utils/prune_binaries.py" --keep-build-dependencies "$_src_dir" "$_main_repo/pruning.list"
helium_resources
write_gn_args "$_arch" dev
python3 "$_main_repo/utils/helium_version.py" \
--tree "$_main_repo" \
--platform-tree "$_root_dir" \
--chromium-tree "$_src_dir"
}
___helium_setup() {
___helium_setup_presetup "$@"
"$_root_dir/devutils/update_patches.sh" merge
cd "$_src_dir"
quilt push -a --refresh
gn_gen --export-compile-commands
}
___helium_reset() {
"$_root_dir/devutils/update_patches.sh" unmerge || true
rm "$_subs_cache" || true
rm "$_namesubs_cache" || true
if mv "$_src_dir" "${_src_dir}x"; then
rm -rf "${_src_dir}x" &
fi
}
___helium_name_substitution() {
if [ "$1" = "nameunsub" ]; then
python3 "$_main_repo/utils/name_substitution.py" --unsub \
-t "$_src_dir" --backup-path "$_namesubs_cache"
elif [ "$1" = "namesub" ]; then
if [ -f "$_namesubs_cache" ]; then
echo "$_namesubs_cache exists, are you sure you want to do this?" >&2
echo "if yes, then delete the $_namesubs_cache file" >&2
return
fi
python3 "$_main_repo/utils/name_substitution.py" --sub \
-t "$_src_dir" --backup-path "$_namesubs_cache"
else
echo "unknown action: $1" >&2
return
fi
}
___helium_apply_translations() {
python3 "$_main_repo/utils/i18n_apply.py" -t "$_src_dir"
}
___helium_generate_translations() {
python3 "$_main_repo/devutils/i18n.py" generate
}
___helium_substitution() {
if [ "$1" = "unsub" ]; then
python3 "$_main_repo/utils/domain_substitution.py" revert \
-c "$_subs_cache" "$_src_dir"
___helium_name_substitution nameunsub
elif [ "$1" = "sub" ]; then
if [ -f "$_subs_cache" ]; then
echo "$_subs_cache exists, are you sure you want to do this?" >&2
echo "if yes, then delete the $_subs_cache file" >&2
return
fi
___helium_name_substitution namesub
python3 "$_main_repo/utils/domain_substitution.py" apply \
-r "$_main_repo/domain_regex.list" \
-f "$_main_repo/domain_substitution.list" \
-c "$_subs_cache" \
"$_src_dir"
else
echo "unknown action: $1" >&2
return
fi
}
___helium_build() {
local -a siso_flags=(${=SISO_FLAGS:-})
cd "$_src_dir"
if [ -n "${SISO_REAPI_ADDRESS:-}" ]; then
configure_siso || return
fi
helium_build -k 0 "${siso_flags[@]}" "$@"
}
___helium_run() {
local profile="$HOME/Library/Application Support/net.imput.helium.dev"
# .git is a file in linked worktrees, and a directory in the main checkout
if [ -f "$_root_dir/.git" ]; then
profile="$profile.wt/${_root_dir#*.wt/}"
fi
"$_out_dir/Helium.app/Contents/MacOS/Helium" \
--user-data-dir="$profile" \
--enable-ui-devtools \
--use-mock-keychain \
--disable-features=DialMediaRouteProvider \
"$@"
}
___helium_wt_path() {
local common
common=$(git -C "$_root_dir" rev-parse --path-format=absolute --git-common-dir)
echo "${common:h}.wt/$1"
}
___helium_wt_new() {
local name=${1:?usage: he wt new <name>} dest
dest=$(___helium_wt_path "$name")
if [ ! -f "$_root_dir/patches/series.merged" ] || [ ! -d "$_src_dir/.pc" ]; then
echo "$_src_dir must be set up with merged patches applied" >&2
return 1
fi
if git -C "$_root_dir" rev-parse -q --verify "refs/heads/$name" >/dev/null \
|| git -C "$_main_repo" rev-parse -q --verify "refs/heads/$name" >/dev/null; then
echo "branch $name already exists" >&2
return 1
fi
git -C "$_root_dir" worktree add -b "$name" "$dest" HEAD
git -C "$_main_repo" worktree add -b "$name" "$dest/helium-chromium" HEAD
git -C "$_root_dir" diff --binary HEAD -- . ":!patches" ":!helium-chromium" \
| git -C "$dest" apply --allow-empty
git -C "$_main_repo" diff --binary HEAD -- . ":!patches" \
| git -C "$dest/helium-chromium" apply --allow-empty
rm -rf "$dest/patches"
/bin/cp -c -R "$_root_dir/patches" "$dest/patches"
mkdir -p "$dest/build"
ln -s "${_download_cache:A}" "$dest/build/download_cache"
/bin/cp -c -R -p "$_src_dir" "$dest/build/src"
for f in "$_subs_cache" "$_namesubs_cache"; do
[ ! -f "$f" ] || /bin/cp -c -p "$f" "$dest/build/"
done
printf '%s\n' "$dest/patches" > "$dest/build/src/.pc/.quilt_patches"
(cd "$dest" && source ./dev.sh && he configure)
}
___helium_wt_rm() {
local dest
dest=$(___helium_wt_path "${1:?usage: he wt rm <name>}")
[ -f "$dest/.git" ] || { echo "$dest is not a worktree" >&2; return 1; }
rm -rf "$dest/build"
git -C "$_main_repo" worktree remove --force "$dest/helium-chromium" || true
git -C "$_root_dir" worktree remove --force "$dest"
}
___helium_wt() {
case "${1:-}" in
new) shift; ___helium_wt_new "$@";;
rm) shift; ___helium_wt_rm "$@";;
ls) git -C "$_root_dir" worktree list;;
*)
echo "usage: he wt <new <name>|rm <name>|ls>" >&2
return 1
esac
}
___helium_pull() {
if [ -f "$_subs_cache" ]; then
echo "source files are substituted, please run 'he unsub' first" >&2
return 1
fi
cd "$_src_dir" && quilt pop -a || true
"$_root_dir/devutils/update_patches.sh" unmerge || true
for dir in "$_root_dir" "$_main_repo"; do
git -C "$dir" stash \
&& git -C "$dir" fetch \
&& git -C "$dir" rebase origin/main \
&& git -C "$dir" stash pop \
|| true
done
"$_root_dir/devutils/update_patches.sh" merge
cd "$_src_dir" && quilt push -a --refresh
}
___helium_patches_merge() {
"$_root_dir/devutils/update_patches.sh" merge
}
___helium_patches_unmerge() {
"$_root_dir/devutils/update_patches.sh" unmerge
}
___helium_quilt_push() {
cd "$_src_dir" && quilt push -a --refresh
}
___helium_quilt_pop() {
cd "$_src_dir" && quilt pop -a
}
___helium_validate() {
if [ "$1" = "config" ]; then
python3 "$_main_repo/devutils/validate_config.py"
elif [ "$1" = "patches" ]; then
if [ ! -f "patches/series.merged" ]; then
echo "patches/series.merged doesn't exist. did you forget to merge?" >&2
return 1
fi
python3 "$_main_repo/devutils/validate_patches.py" \
-l "$_src_dir" \
-s patches/series.merged
elif [ "$1" = "series" ]; then
"$_root_dir/devutils/check_patch_files.sh"
else
echo "unknown validate action. usage: he validate <config|patches|series>" >&2
fi
}
___helium_format() {
cd "$_src_dir"
quilt diff | "$_src_dir/third_party/clang-format/script/clang-format-diff.py" \
-p1 -i -style=file
}
___helium_find_tidy_diff() {
if [ -n "$_tidy_diff_script" ]; then
return
elif command -v clang-tidy-diff >/dev/null 2>&1; then
_tidy_diff_script=$(command -v clang-tidy-diff)
elif command -v clang-tidy-diff.py >/dev/null 2>&1; then
_tidy_diff_script=$(command -v clang-tidy-diff.py)
else
_tidy_diff_script=$(find /opt/homebrew/Cellar/llvm -name clang-tidy-diff.py | head -1)
fi
if [ -z "$_tidy_diff_script" ]; then
echo "could not find clang-tidy-diff.py script." >&2
echo "ensure that you have llvm installed on your system" >&2
return 1
fi
}
___helium_strip_compile_commands() {
_ccmd_path="$_out_dir/compile_commands.json"
[ "$_ccmd_stripped" = 1 ] && return;
_ccmd_stripped=1
echo "normalizing compile_commands.json, this will take a while..."
cp "$_ccmd_path" "$_ccmd_path.orig";
gsed -Ei 's/^(\s*"command": ").*?\s(\S+bin\/clang)/\1\2/g' "$_ccmd_path"
}
___helium_tidy() {
___helium_find_tidy_diff || return;
___helium_strip_compile_commands;
quilt diff | "$_tidy_diff_script" \
-regex '.*\.(cc|mm)' \
-use-color \
-p1 \
-path "$_out_dir" \
-quiet \
-j$(nproc)
}
___helium_lint() {
___helium_format;
___helium_tidy;
}
___helium_menu() {
set -e
case $1 in
setup) shift; ___helium_setup "$@";;
presetup) shift; ___helium_setup_presetup "$@";;
configure) gn_gen --export-compile-commands;;
resources) helium_resources;;
sub|unsub) ___helium_substitution "$1";;
namesub|nameunsub) ___helium_name_substitution "$1";;
translate) ___helium_apply_translations;;
transgen) ___helium_generate_translations;;
merge) ___helium_patches_merge;;
unmerge) ___helium_patches_unmerge;;
push) ___helium_quilt_push;;
pop) ___helium_quilt_pop;;
pull) ___helium_pull;;
validate) ___helium_validate "$2";;
format) ___helium_format;;
tidy) ___helium_tidy;;
lint) ___helium_lint;;
build) shift; ___helium_build "$@";;
run) shift; ___helium_run "$@";;
reset) ___helium_reset;;
wt) shift; ___helium_wt "$@";;
*)
echo "usage: he <command>" >&2
echo "\tsetup [-c] - sets up the dev environment, optionally cloning Chromium" >&2
echo "\t equivalent of: [presetup, merge, push, configure]" >&2
echo "\tpresetup [-c] - prepares sources and dependencies, optionally cloning Chromium" >&2
echo "\tconfigure - generates build configuration and tools" >&2
echo "\tresources - generates and copies helium resources (such as icons)" >&2
echo "\n" >&2
echo "\tsub - apply google domain and name substitutions" >&2
echo "\tunsub - undo google domain and name substitutions" >&2
echo "\tnamesub - apply only name substitutions" >&2
echo "\tnameunsub - undo only name substitutions" >&2
echo "\ttranslate - apply translations from i18n directory" >&2
echo "\ttransgen - generate source strings for translation" >&2
echo "\n" >&2
echo "\tmerge - merges all patches" >&2
echo "\tunmerge - unmerges all patches" >&2
echo "\tpush - applies all patches" >&2
echo "\tpop - undoes all patches" >&2
echo "\tpull - undoes all patches, pulls from git, redoes all patches" >&2
echo "\n" >&2
echo "\tvalidate config - validates the build configuration" >&2
echo "\tvalidate patches - validates that patches are applied correctly" >&2
echo "\tvalidate series - checks the consistency of the series file" >&2
echo "\tformat - formats the topmost patch according to Chromium coding style" >&2
echo "\ttidy - runs clang-tidy on the topmost patch" >&2
echo "\tlint - he format + he tidy" >&2
echo "\n" >&2
echo "\tbuild - builds a development binary" >&2
echo "\trun [args] - runs a development build of helium with dev data dir & ui devtools enabled" >&2
echo "\treset - nukes everything" >&2
echo "\n" >&2
echo "\twt new <name> - creates a worktree with an APFS clone of the current source tree" >&2
echo "\twt rm <name> - removes a worktree and its source tree, keeping its branches" >&2
echo "\twt ls - lists worktrees" >&2
esac
}
he() {
(___helium_menu "$@")
}
if ! (return 0 2>/dev/null); then
printf "usage:\n\t$ source dev.sh\n\t$ he\n" 2>&1
exit 1
else
if [ "$__helium_loaded" = "" ]; then
__helium_loaded=1
PS1="🎈 $PS1"
fi
fi