| # Copyright lowRISC contributors. |
| # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| # SPDX-License-Identifier: Apache-2.0 |
| # A wrapper around clang-format, used for CI. |
| # Expects a single argument, which is the pull request's target branch |
| echo >&2 "Usage: clang-format.sh <tgt-branch>" |
| merge_base="$(git merge-base origin/$tgt_branch HEAD)" || { |
| echo >&2 "Failed to find fork point for origin/$tgt_branch." |
| echo "Running C/C++ lint checks on files changed since $merge_base" |
| echo >&2 "Failed to create temporary file" |
| trap 'rm -f "$TMPFILE"' EXIT |
| git diff -U0 "$merge_base" -- "*.cpp" "*.cc" "*.c" "*.h" ':!*/vendor/*' | \ |
| clang-format-diff -p1 | \ |
| if [ -s "$TMPFILE" ]; then |
| echo -n "##vso[task.logissue type=error]" |
| echo "C/C++ lint failed. Use 'git clang-format' with appropriate options to reformat the changed code." |