blob: 7c4429a1983117acff7da9cb2ac35f7b6dd6905a [file] [log] [blame]
Dan Sinclair6e581892020-03-02 15:47:43 -05001#!/bin/bash
2# Copyright 2020 The Tint Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Ben Claytonf2b8d2b2022-12-06 18:29:08 +000016SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
17ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )"
18
19set -e # fail on error
20
21if ! command -v clang_format.py &> /dev/null; then
22 echo "clang_format.py not found on PATH"
23 exit 1
24fi
25
Ben Clayton1591a162023-02-05 12:38:23 +000026if ! command -v gn &> /dev/null; then
27 echo "gn not found on PATH"
28 exit 1
29fi
30
31CLANG_FORMAT_FILES=""
32CLANG_FORMAT_FILES+="`find src -name "*.h"` "
33CLANG_FORMAT_FILES+="`find src -name "*.cc"` "
34CLANG_FORMAT_FILES+="`find src -name "*.cpp"` "
35CLANG_FORMAT_FILES+="`find src -name "*.m"` "
36CLANG_FORMAT_FILES+="`find src -name "*.mm"` "
37CLANG_FORMAT_FILES+="`find include -name "*.h"` "
38
39GN_FILES="BUILD.gn "
40GN_FILES+="`find src -name "*.gn"` "
Ben Claytonf2b8d2b2022-12-06 18:29:08 +000041
42if command -v go &> /dev/null; then
Ben Clayton1591a162023-02-05 12:38:23 +000043 # Go is installed. Run in parallel for speed wins
Ben Claytonf2b8d2b2022-12-06 18:29:08 +000044 ${SCRIPT_DIR}/run run-parallel \
45 clang_format.py -i \
Ben Clayton1591a162023-02-05 12:38:23 +000046 $ -- $CLANG_FORMAT_FILES
47
48 ${SCRIPT_DIR}/run run-parallel \
49 gn format \
50 $ -- $GN_FILES
Ben Claytonf2b8d2b2022-12-06 18:29:08 +000051else
Ben Clayton1591a162023-02-05 12:38:23 +000052 clang_format.py -i $CLANG_FORMAT_FILES
53 gn format $GN_FILES
Ben Claytonf2b8d2b2022-12-06 18:29:08 +000054fi