2022-02-05 13:31:48 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
|
|
|
cd "${script_path}/.." || exit 1
|
|
|
|
|
|
|
|
if [ -z "${GML_FORMAT:-}" ] ; then
|
|
|
|
if ! [ -d Build/lagom/ ] ; then
|
|
|
|
echo "Directory Build/lagom/ does not exist. Skipping GML formatting."
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-03-18 15:23:35 +00:00
|
|
|
if ! [ -r Build/lagom/bin/gml-format ] ; then
|
2022-02-05 13:31:48 +00:00
|
|
|
echo "Lagom executable gml-format was not built. Skipping GML formatting."
|
|
|
|
echo "To enable this check, you may need to run './Meta/serenity.sh build lagom' first."
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-03-18 15:23:35 +00:00
|
|
|
GML_FORMAT="Build/lagom/bin/gml-format"
|
2022-02-05 13:31:48 +00:00
|
|
|
fi
|
|
|
|
|
2022-09-18 18:10:57 +00:00
|
|
|
if [ "$#" -gt "0" ] ; then
|
|
|
|
# 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
|
2023-10-02 14:26:32 +00:00
|
|
|
# about 100ms. That is perfectly fine during a CI run, but becomes noticeable during a
|
2022-09-18 18:10:57 +00:00
|
|
|
# pre-commit hook. It is unnecessary to check the entire repository on every single
|
|
|
|
# commit, so we save some time here.
|
|
|
|
for file in "$@"; do
|
|
|
|
if [[ "${file}" =~ \.gml ]]; then
|
|
|
|
echo "$file"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
find AK Base Documentation Kernel Meta Ports Tests Userland -type f -name '*.gml' -print
|
|
|
|
fi \
|
|
|
|
| xargs -r "${GML_FORMAT}" -i
|