blob: 82b572c23cd41bb6a6a63e5c679bb0304270064e [file] [log] [blame]
Corentin Wallez4c351012018-08-27 10:10:28 +02001#!/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
17clang_format=$1
18base_commit=$2
19
20echo
21skipped_directories="(examples|generator|src/tests/(unittests|end2end)|third_party)"
22# Find the files modified that need formatting
23files_to_check=$(git diff --diff-filter=ACMR --name-only $base_commit | grep -E "*\.(c|cpp|mm|h)$" | grep -vE "^$skipped_directories/*")
24if [ -z "$files_to_check" ]; then
25 echo "No modified files to format."
26 exit 0
27fi
28echo "Checking formatting diff on these files:"
29echo "$files_to_check"
30echo
31files_to_check=$(echo $files_to_check | tr '\n' ' ')
32
33# Run git-clang-format, check if it formatted anything
34format_output=$(scripts/git-clang-format --binary $clang_format --commit $base_commit --diff --style=file $files_to_check)
35if [ "$format_output" == "clang-format did not modify any files" ] || [ "$format_output" == "no modified files to format" ] ; then
36 exit 0
37fi
38
39# clang-format made changes, print them and fail Travis
40echo "Following formatting changes needed:"
41echo
42echo "$format_output"
43echo
44exit 1