Corentin Wallez | 4c35101 | 2018-08-27 10:10:28 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2018 The Dawn Authors |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | clang_format=$1 |
| 18 | base_commit=$2 |
| 19 | |
| 20 | echo |
| 21 | skipped_directories="(examples|generator|src/tests/(unittests|end2end)|third_party)" |
| 22 | # Find the files modified that need formatting |
| 23 | files_to_check=$(git diff --diff-filter=ACMR --name-only $base_commit | grep -E "*\.(c|cpp|mm|h)$" | grep -vE "^$skipped_directories/*") |
| 24 | if [ -z "$files_to_check" ]; then |
| 25 | echo "No modified files to format." |
| 26 | exit 0 |
| 27 | fi |
| 28 | echo "Checking formatting diff on these files:" |
| 29 | echo "$files_to_check" |
| 30 | echo |
| 31 | files_to_check=$(echo $files_to_check | tr '\n' ' ') |
| 32 | |
| 33 | # Run git-clang-format, check if it formatted anything |
| 34 | format_output=$(scripts/git-clang-format --binary $clang_format --commit $base_commit --diff --style=file $files_to_check) |
| 35 | if [ "$format_output" == "clang-format did not modify any files" ] || [ "$format_output" == "no modified files to format" ] ; then |
| 36 | exit 0 |
| 37 | fi |
| 38 | |
| 39 | # clang-format made changes, print them and fail Travis |
| 40 | echo "Following formatting changes needed:" |
| 41 | echo |
| 42 | echo "$format_output" |
| 43 | echo |
| 44 | exit 1 |