2021-01-22 16:44:05 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-11-28 17:16:38 +00:00
|
|
|
|
|
|
|
set -eo pipefail
|
|
|
|
|
|
|
|
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
|
|
|
cd "${script_path}/.."
|
|
|
|
|
|
|
|
MISSING_FLAGS=n
|
|
|
|
|
2024-07-16 09:51:33 +00:00
|
|
|
find_all_source_files () {
|
|
|
|
# We're in the middle of a pre-commit run, so we should only check the files that have
|
|
|
|
# actually changed. The reason is that "git ls-files | grep" on the entire repo takes
|
|
|
|
# about 100ms. That is perfectly fine during a CI run, but becomes noticeable during a
|
|
|
|
# pre-commit hook. It is unnecessary to check the entire repository on every single
|
|
|
|
# commit, so we save some time here.
|
|
|
|
#
|
|
|
|
# And see https://github.com/LadybirdBrowser/ladybird/issues/283; the reason this is
|
|
|
|
# pulled out into separate function is, Bash 3.2 apparently has a parser bug which
|
|
|
|
# makes it choke on the above comment if it's in the process substitution below.
|
|
|
|
for file in "$@"; do
|
|
|
|
if [[ ("${file}" =~ \.cpp || "${file}" =~ \.h || "${file}" =~ \.in) ]]; then
|
|
|
|
echo "$file"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-05-14 16:17:15 +00:00
|
|
|
# Check whether all_the_debug_macros.cmake sets all the flags used in C++ code.
|
2020-11-28 17:16:38 +00:00
|
|
|
while IFS= read -r FLAG; do
|
2023-05-14 16:17:15 +00:00
|
|
|
# We intentionally don't check for commented-out lines,
|
|
|
|
# in order to keep track of false positives.
|
|
|
|
if ! grep -qF "set(${FLAG} ON)" Meta/CMake/all_the_debug_macros.cmake ; then
|
2021-02-13 11:46:22 +00:00
|
|
|
echo "'all_the_debug_macros.cmake' is missing ${FLAG}"
|
2020-11-28 17:16:38 +00:00
|
|
|
MISSING_FLAGS=y
|
|
|
|
fi
|
|
|
|
done < <(
|
2022-09-18 18:10:57 +00:00
|
|
|
if [ "$#" -eq "0" ]; then
|
|
|
|
git ls-files -- \
|
|
|
|
'*.cpp' \
|
|
|
|
'*.h' \
|
2024-05-31 08:27:36 +00:00
|
|
|
'*.in'
|
2022-09-18 18:10:57 +00:00
|
|
|
else
|
2024-07-16 09:51:33 +00:00
|
|
|
find_all_source_files "$@"
|
2022-09-18 18:10:57 +00:00
|
|
|
fi \
|
2021-10-26 18:08:39 +00:00
|
|
|
| xargs grep -E '(_DEBUG|DEBUG_)' \
|
2020-11-28 17:16:38 +00:00
|
|
|
| sed -re 's,^.*[^a-zA-Z0-9_]([a-zA-Z0-9_]*DEBUG[a-zA-Z0-9_]*).*$,\1,' \
|
2022-09-18 18:10:57 +00:00
|
|
|
| sort -u
|
2020-11-28 17:16:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if [ "n" != "${MISSING_FLAGS}" ] ; then
|
2021-02-13 11:46:22 +00:00
|
|
|
echo "Some flags are missing for the ALL_THE_DEBUG_MACROS feature."
|
2020-11-28 17:16:38 +00:00
|
|
|
echo "If you just added a new SOMETHING_DEBUG flag, that's great!"
|
|
|
|
echo "We want to enable all of these in automated builds, so that the code doesn't rot."
|
2021-02-13 11:46:22 +00:00
|
|
|
echo "Please add it to Meta/CMake/all_the_debug_macros.cmake"
|
2023-05-14 16:17:15 +00:00
|
|
|
echo "Or perhaps it's not a debug flag?"
|
|
|
|
echo "Please also add it to Meta/CMake/all_the_debug_macros.cmake"
|
2020-11-28 17:16:38 +00:00
|
|
|
exit 1
|
|
|
|
fi
|