| #!/bin/bash | |
| # | |
| # Copyright 2022 The Fuchsia Authors. All rights reserved. | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/helpers.sh || exit $? | |
| echo-info "Formatting C++ code using clang-format..." | |
| clang_format="${FUCHSIA_EMBEDDER_DIR}"/bazel-flutter-embedder/external/fuchsia_clang/bin/clang-format | |
| if [[ ! -f "${clang_format}" ]] | |
| then | |
| if [[ -z "${LOCAL_FUCHSIA_PLATFORM_BUILD}" ]] | |
| then | |
| echo-warning "Failed to format C++ code because ${clang_format} does not exist." | |
| echo-warning "You can usually fix this by running:" | |
| echo-warning "bazel build --config=fuchsia_x64 //src/embedder" | |
| echo-warning "If that does not work, please open a bug at https://fxbug.dev " | |
| else | |
| # TODO(akbiggs): Make this case work. | |
| echo-warning "Formatting C++ code on commit does not work when LOCAL_FUCHSIA_PLATFORM_BUILD is set." | |
| fi | |
| else | |
| # Format any C++ code that is: | |
| # 1. Being modified by the commit. | |
| # 2. Not copied from the engine repo, which has its own formatting rules. | |
| # 3. Not in third_party repos, which have their own formatting rules. | |
| source_files="$(git diff --cached --name-only --diff-filter=ACM | grep -v "/engine/" | grep -v "/third_party/" | grep -E "\.(cc|h)$")" | |
| if [[ ! -z "$source_files" ]] | |
| then | |
| $clang_format -i $source_files | |
| git add $source_files | |
| fi | |
| fi | |
| # TODO(akbiggs): Add clang-tidy checks to lint C++ code. | |
| # TODO(akbiggs): Format markdown code. | |
| # TODO(akbiggs): Format bazel code. |