diff options
author | Paul Duffin <paulduffin@google.com> | 2019-05-15 10:52:02 +0100 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2019-05-15 12:27:01 +0100 |
commit | 4f818e3cb428a79db73103b7db4000df9c5953eb (patch) | |
tree | a39b73410f64bd0a49101b16c08694c2fe35801b /tools | |
parent | f65dbf1269bcffd4e2c7951415915dbe4e681b46 (diff) |
Add pre-upload check to enforce correct formatting of .bp files
Bug: 132757397
Test: tools/check-bpfmt.sh 16a057f0c8ed4f7212043615228da9311760850a
Change-Id: Ia3cd3f7fa075d469b5b6126fb739df915a65bab6
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/check-bpfmt.sh | 32 |
1 files changed, 32 insertions, 0 deletions
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 |