@@ -46,7 +46,7 @@ ___helium_configure() {
4646 cd " $_src_dir "
4747 python3 ./tools/gn/bootstrap/bootstrap.py -o out/Default/gn --skip-generate-buildfiles
4848 python3 ./tools/rust/build_bindgen.py --rust-target $_rust_target --skip-test
49- ./out/Default/gn gen out/Default --fail-on-unused-args
49+ ./out/Default/gn gen out/Default --fail-on-unused-args --export-compile-commands
5050}
5151
5252___helium_resources () {
@@ -207,6 +207,56 @@ ___helium_validate() {
207207 fi
208208}
209209
210+ ___helium_format () {
211+ cd " $_src_dir "
212+ quilt diff | " $_clang_dir /share/clang/clang-format-diff.py" -p1 -i -style=file
213+ }
214+
215+ ___helium_find_tidy_diff () {
216+ if [ -n " $_tidy_diff_script " ]; then
217+ return
218+ elif command -v clang-tidy-diff > /dev/null 2>&1 ; then
219+ _tidy_diff_script=$( command -v clang-tidy-diff)
220+ elif command -v clang-tidy-diff.py > /dev/null 2>&1 ; then
221+ _tidy_diff_script=$( command -v clang-tidy-diff.py)
222+ else
223+ _tidy_diff_script=$( find /opt/homebrew/Cellar/llvm -name clang-tidy-diff.py | head -1)
224+ fi
225+
226+ if [ -z " $_tidy_diff_script " ]; then
227+ echo " could not find clang-tidy-diff.py script." >&2
228+ echo " ensure that you have llvm installed on your system" >&2
229+ return 1
230+ fi
231+ }
232+
233+ ___helium_strip_compile_commands () {
234+ _ccmd_path=" $_src_dir /out/Default/compile_commands.json"
235+ [ " $_ccmd_stripped " = 1 ] && return ;
236+ _ccmd_stripped=1
237+
238+ echo " normalizing compile_commands.json, this will take a while..."
239+ cp " $_ccmd_path " " $_ccmd_path .orig" ;
240+ gsed -Ei ' s/^(\s*"command": ").*?\s(\S+bin\/clang)/\1\2/g' " $_ccmd_path "
241+ }
242+
243+ ___helium_tidy () {
244+ ___helium_find_tidy_diff || return ;
245+ ___helium_strip_compile_commands;
246+ quilt diff | " $_tidy_diff_script " \
247+ -regex ' .*\.(cc|mm)' \
248+ -use-color \
249+ -p1 \
250+ -path " $_src_dir /out/Default" \
251+ -quiet \
252+ -j$( nproc)
253+ }
254+
255+ ___helium_lint () {
256+ ___helium_format;
257+ ___helium_tidy;
258+ }
259+
210260__helium_menu () {
211261 set -e
212262 case $1 in
@@ -225,6 +275,9 @@ __helium_menu() {
225275 pull) ___helium_pull;;
226276
227277 validate) ___helium_validate " $2 " ;;
278+ format) ___helium_format;;
279+ tidy) ___helium_tidy;;
280+ lint) ___helium_lint;;
228281
229282 build) ___helium_build;;
230283 run) ___helium_run;;
@@ -254,6 +307,9 @@ __helium_menu() {
254307 echo " \tvalidate config - validates the build configuration" >&2
255308 echo " \tvalidate patches - validates that patches are applied correctly" >&2
256309 echo " \tvalidate series - checks the consistency of the series file" >&2
310+ echo " \tformat - formats the topmost patch according to Chromium coding style" >&2
311+ echo " \ttidy - runs clang-tidy on the topmost patch" >&2
312+ echo " \tlint - he format + he tidy" >&2
257313
258314 echo " \n" >&2
259315 echo " \tbuild - builds a development binary" >&2
0 commit comments