Serenity Operating System
1#!/usr/bin/env bash
2
3set -eo pipefail
4
5script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
6cd "${script_path}/.."
7
8MISSING_FLAGS=n
9
10while IFS= read -r FLAG; do
11 # Ignore false positives that are not debug flags.
12 if [ "$FLAG" = "ELF_DEBUG" ] || [ "$FLAG" = "IA32_DEBUG_INTERFACE" ]; then
13 continue
14 fi
15
16 # We simply search whether the CMakeLists.txt *ever* sets the flag.
17 # There are (basically) no false positives, but there might be false negatives,
18 # for example we intentionally don't check for commented-out lines here.
19 if ! grep -qF "set(${FLAG}" Meta/CMake/all_the_debug_macros.cmake ; then
20 echo "'all_the_debug_macros.cmake' is missing ${FLAG}"
21 MISSING_FLAGS=y
22 fi
23done < <(
24 if [ "$#" -eq "0" ]; then
25 git ls-files -- \
26 '*.cpp' \
27 '*.h' \
28 '*.in' \
29 ':!:Kernel/FileSystem/Ext2FS/Definitions.h'
30 else
31 # We're in the middle of a pre-commit run, so we should only check the files that have
32 # actually changed. The reason is that "git ls-files | grep" on the entire repo takes
33 # about 100ms. That is perfectly fine during a CI run, but becomes noticable during a
34 # pre-commit hook. It is unnecessary to check the entire repository on every single
35 # commit, so we save some time here.
36 for file in "$@"; do
37 if [[ ("${file}" =~ \.cpp || "${file}" =~ \.h || "${file}" =~ \.in) ]]; then
38 echo "$file"
39 fi
40 done
41 fi \
42 | xargs grep -E '(_DEBUG|DEBUG_)' \
43 | sed -re 's,^.*[^a-zA-Z0-9_]([a-zA-Z0-9_]*DEBUG[a-zA-Z0-9_]*).*$,\1,' \
44 | sort -u
45)
46
47if [ "n" != "${MISSING_FLAGS}" ] ; then
48 echo "Some flags are missing for the ALL_THE_DEBUG_MACROS feature."
49 echo "If you just added a new SOMETHING_DEBUG flag, that's great!"
50 echo "We want to enable all of these in automated builds, so that the code doesn't rot."
51 echo "Please add it to Meta/CMake/all_the_debug_macros.cmake"
52 exit 1
53fi