summaryrefslogtreecommitdiff
path: root/misc/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'misc/scripts')
-rwxr-xr-xmisc/scripts/black_format.sh4
-rwxr-xr-xmisc/scripts/clang_format.sh4
-rwxr-xr-xmisc/scripts/file_format.sh27
3 files changed, 16 insertions, 19 deletions
diff --git a/misc/scripts/black_format.sh b/misc/scripts/black_format.sh
index 04dfe32f60..f93e8cbc2a 100755
--- a/misc/scripts/black_format.sh
+++ b/misc/scripts/black_format.sh
@@ -16,11 +16,9 @@ PY_FILES=$(find \( -path "./.git" \
black -l 120 $PY_FILES
git diff > patch.patch
-FILESIZE="$(stat -c%s patch.patch)"
-MAXSIZE=5
# If no patch has been generated all is OK, clean up, and exit.
-if (( FILESIZE < MAXSIZE )); then
+if [ ! -s patch.patch ] ; then
printf "Files in this commit comply with the black style rules.\n"
rm -f patch.patch
exit 0
diff --git a/misc/scripts/clang_format.sh b/misc/scripts/clang_format.sh
index 5131f7fe33..e686305dea 100755
--- a/misc/scripts/clang_format.sh
+++ b/misc/scripts/clang_format.sh
@@ -39,11 +39,9 @@ while IFS= read -rd '' f; do
done
git diff > patch.patch
-FILESIZE="$(stat -c%s patch.patch)"
-MAXSIZE=5
# If no patch has been generated all is OK, clean up, and exit.
-if (( FILESIZE < MAXSIZE )); then
+if [ ! -s patch.patch ] ; then
printf "Files in this commit comply with the clang-format style rules.\n"
rm -f patch.patch
exit 0
diff --git a/misc/scripts/file_format.sh b/misc/scripts/file_format.sh
index 30988e51c6..c570ec23a7 100755
--- a/misc/scripts/file_format.sh
+++ b/misc/scripts/file_format.sh
@@ -1,7 +1,13 @@
#!/usr/bin/env bash
# This script ensures proper POSIX text file formatting and a few other things.
-# This is supplementary to clang-black-format.sh, but should be run before it.
+# This is supplementary to clang_format.sh and black_format.sh, but should be
+# run before them.
+
+# We need dos2unix and recode.
+if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v recode)" ]; then
+ printf "Install 'dos2unix' and 'recode' to use this script.\n"
+fi
set -uo pipefail
IFS=$'\n\t'
@@ -25,26 +31,21 @@ while IFS= read -rd '' f; do
elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then
continue
fi
- # Ensures that files are UTF-8 formatted.
+ # Ensure that files are UTF-8 formatted.
recode UTF-8 "$f" 2> /dev/null
- # Ensures that files have LF line endings.
+ # Ensure that files have LF line endings and do not contain a BOM.
dos2unix "$f" 2> /dev/null
- # Ensures that files do not contain a BOM.
- sed -i '1s/^\xEF\xBB\xBF//' "$f"
- # Ensures that files end with newline characters.
- tail -c1 < "$f" | read -r _ || echo >> "$f";
- # Remove trailing space characters.
- sed -z -i 's/\x20\x0A/\x0A/g' "$f"
+ # Remove trailing space characters and ensures that files end
+ # with newline characters. -l option handles newlines conveniently.
+ perl -i -ple 's/\s*$//g' "$f"
# Remove the character sequence "== true" if it has a leading space.
- sed -z -i 's/\x20== true//g' "$f"
+ perl -i -pe 's/\x20== true//g' "$f"
done
git diff > patch.patch
-FILESIZE="$(stat -c%s patch.patch)"
-MAXSIZE=5
# If no patch has been generated all is OK, clean up, and exit.
-if (( FILESIZE < MAXSIZE )); then
+if [ ! -s patch.patch ] ; then
printf "Files in this commit comply with the formatting rules.\n"
rm -f patch.patch
exit 0