Dan Sinclair | 6e58189 | 2020-03-02 15:47:43 -0500 | [diff] [blame] | 1 | #!/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 Clayton | f2b8d2b | 2022-12-06 18:29:08 +0000 | [diff] [blame] | 16 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" |
| 17 | ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )" |
| 18 | |
| 19 | set -e # fail on error |
| 20 | |
| 21 | if ! command -v clang_format.py &> /dev/null; then |
| 22 | echo "clang_format.py not found on PATH" |
| 23 | exit 1 |
| 24 | fi |
| 25 | |
Ben Clayton | 1591a16 | 2023-02-05 12:38:23 +0000 | [diff] [blame] | 26 | if ! command -v gn &> /dev/null; then |
| 27 | echo "gn not found on PATH" |
| 28 | exit 1 |
| 29 | fi |
| 30 | |
| 31 | CLANG_FORMAT_FILES="" |
| 32 | CLANG_FORMAT_FILES+="`find src -name "*.h"` " |
| 33 | CLANG_FORMAT_FILES+="`find src -name "*.cc"` " |
| 34 | CLANG_FORMAT_FILES+="`find src -name "*.cpp"` " |
| 35 | CLANG_FORMAT_FILES+="`find src -name "*.m"` " |
| 36 | CLANG_FORMAT_FILES+="`find src -name "*.mm"` " |
| 37 | CLANG_FORMAT_FILES+="`find include -name "*.h"` " |
| 38 | |
| 39 | GN_FILES="BUILD.gn " |
| 40 | GN_FILES+="`find src -name "*.gn"` " |
Ben Clayton | f2b8d2b | 2022-12-06 18:29:08 +0000 | [diff] [blame] | 41 | |
| 42 | if command -v go &> /dev/null; then |
Ben Clayton | 1591a16 | 2023-02-05 12:38:23 +0000 | [diff] [blame] | 43 | # Go is installed. Run in parallel for speed wins |
Ben Clayton | f2b8d2b | 2022-12-06 18:29:08 +0000 | [diff] [blame] | 44 | ${SCRIPT_DIR}/run run-parallel \ |
| 45 | clang_format.py -i \ |
Ben Clayton | 1591a16 | 2023-02-05 12:38:23 +0000 | [diff] [blame] | 46 | $ -- $CLANG_FORMAT_FILES |
| 47 | |
| 48 | ${SCRIPT_DIR}/run run-parallel \ |
| 49 | gn format \ |
| 50 | $ -- $GN_FILES |
Ben Clayton | f2b8d2b | 2022-12-06 18:29:08 +0000 | [diff] [blame] | 51 | else |
Ben Clayton | 1591a16 | 2023-02-05 12:38:23 +0000 | [diff] [blame] | 52 | clang_format.py -i $CLANG_FORMAT_FILES |
| 53 | gn format $GN_FILES |
Ben Clayton | f2b8d2b | 2022-12-06 18:29:08 +0000 | [diff] [blame] | 54 | fi |