diff options
author | Colm Donelan <Colm.Donelan@arm.com> | 2021-03-02 10:30:34 +0000 |
---|---|---|
committer | Kevin May <kevin.may@arm.com> | 2023-08-24 08:52:47 +0000 |
commit | e40cc8359b02a7786908294300c45b672cf6b0e4 (patch) | |
tree | afaaccc2b41a71b17ba714d061ab6bf631b3fd94 /scripts/clang-format.sh | |
parent | 7fbf8109a972f0508f82ea40acc103b5959d115b (diff) | |
download | armnn-e40cc8359b02a7786908294300c45b672cf6b0e4.tar.gz |
IVGCVSW-3979 Introduce clang-format scripts to ArmNN.
* Adding a .clang-format file and a script to call it.
Signed-off-by: Colm Donelan <Colm.Donelan@arm.com>
Change-Id: Ia686557f66a6bc09a647b430161f9f7e29ffeed7
Diffstat (limited to 'scripts/clang-format.sh')
-rwxr-xr-x | scripts/clang-format.sh | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/clang-format.sh b/scripts/clang-format.sh new file mode 100755 index 0000000000..5d203ad161 --- /dev/null +++ b/scripts/clang-format.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Copyright © 2021-2023 Arm Ltd. All rights reserved. +# SPDX-License-Identifier: MIT +# + +# +# Usage: clang-format.sh [path to file or directory] +# +# Formats all git-tracked files in the repository according to clang-format rules. +# +# Takes an optional parameter to limit the scope to a specific directory or file. +# +# The clang-format rules can be found in the top level directory: .clang-format +# To prevent clang-format on a section of code, use the following: +# // clang-format off +# my code that i dont want to be clang-formatted goes here +# // clang-format on +# + +# Check that clang-format is available. +CLANG_FORMAT=`command -v clang-format` +if [ -z $CLANG_FORMAT ]; then + # Maybe path isn't set. Try a well known location. + CLANG_FORMAT=/usr/bin/clang-format + if [ ! -x "$CLANG_FORMAT" ]; then + echo "Unable to locate clang-format. Try installing it: sudo apt-get install clang-format" + fi +fi + +# Find all hpp and cpp files excluding some directories. +files=$(git ls-files ${1} | egrep -v '^(build-tool|docker|docs|generated|third-party)' | egrep '\.[ch](pp)?$') + +num_files_changed=0 + +for file in $files; do + echo "[CLANG-FORMAT] ${file}" + # Run clang-format in-place to update the file + $CLANG_FORMAT -style=file ${file} -i + if [ $? -ne 0 ]; then + echo "Error: Execution of $CLANG_FORMAT failed." + exit -1 + else + ((num_files_changed++)) + fi +done + +echo "${num_files_changed} file(s) changed" +exit ${num_files_changed} |