mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
* Enforce clang-format on all files in commit This re-enforces clang-format across all files changed in the commit. In c10c417, we enabled checking only for the lines changed in the diff in order to reduce the change of merge conflicts with the shell refactor landed in 58e84c8. * Reformat sources to match latest clang-format As part of re-enabling clang-format across the codebase, reformat all code to match the latest toolchain.
53 lines
1.1 KiB
Bash
Executable File
53 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Code formatting presubmit
|
|
#
|
|
# This presubmit script ensures that code under the src/flutter directory is
|
|
# formatted according to the Flutter engine style requirements. On failure, a
|
|
# diff is emitted that can be applied from within the src/flutter directory
|
|
# via:
|
|
#
|
|
# patch -p0 < diff.patch
|
|
|
|
set -e
|
|
echo "Checking formatting..."
|
|
|
|
case "$(uname -s)" in
|
|
Darwin)
|
|
OS="mac-x64"
|
|
;;
|
|
Linux)
|
|
OS="linux-x64"
|
|
;;
|
|
*)
|
|
echo "Unknown operating system."
|
|
exit -1
|
|
;;
|
|
esac
|
|
|
|
# Tools
|
|
CLANG_FORMAT="../buildtools/$OS/clang/bin/clang-format"
|
|
$CLANG_FORMAT --version
|
|
|
|
# Compute the diffs.
|
|
FILETYPES="*.c *.cc *.cpp *.h *.m *.mm"
|
|
DIFF_OPTS="-U0 --no-color --name-only"
|
|
FILES_TO_CHECK="$(git diff $DIFF_OPTS -- master $FILETYPES)"
|
|
|
|
FAILED_CHECKS=0
|
|
for f in $FILES_TO_CHECK; do
|
|
set +e
|
|
CUR_DIFF="$(diff -u "$f" <("$CLANG_FORMAT" --style=file "$f"))"
|
|
set -e
|
|
if [[ ! -z "$CUR_DIFF" ]]; then
|
|
echo "$CUR_DIFF"
|
|
FAILED_CHECKS=$(($FAILED_CHECKS+1))
|
|
fi
|
|
done
|
|
|
|
if [[ $FAILED_CHECKS -ne 0 ]]; then
|
|
echo ""
|
|
echo "ERROR: Some files are formatted incorrectly. To fix, apply diffs above via patch -p0."
|
|
exit 1
|
|
fi
|