summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--PREUPLOAD.cfg3
-rwxr-xr-xtools/check-bpfmt.sh32
2 files changed, 35 insertions, 0 deletions
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index 3a75225b6e..24292c1b61 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -8,3 +8,6 @@ checkstyle-luni-json-xml = java -jar ${REPO_ROOT}/prebuilts/checkstyle/checkstyl
# Ensure there are no Apache-licensed files under:
# * ojluni/src/main/java
checkstyle-ojluni = java -jar ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.jar -c tools/checkstyle/checkstyle-forbid-apache.xml ojluni/src/main/java
+
+# Ensure that bp files are correctly formatted:
+bpfmt-check = tools/check-bpfmt.sh ${PREUPLOAD_COMMIT}
diff --git a/tools/check-bpfmt.sh b/tools/check-bpfmt.sh
new file mode 100755
index 0000000000..8ca1df51fa
--- /dev/null
+++ b/tools/check-bpfmt.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+SHA=$1
+
+FIX=
+for file in $(git show --name-only --pretty=format: $SHA | grep -E "\.bp$"); do
+ if [[ -n "$(bpfmt -d <(git show $SHA:$file))" ]]; then
+ FIX="$FIX $file"
+ fi
+done
+
+if [[ -n "$FIX" ]]; then
+ # Remove leading space.
+ FIX=$(echo $FIX)
+ echo -e "\e[1m\e[31mSome .bp files are incorrectly formatted, run the following commands to fix them:\e[0m"
+ echo -e "\e[1m\e[31m bpfmt -w $FIX\e[0m"
+ exit 1
+fi