aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColm Donelan <Colm.Donelan@arm.com>2021-03-02 10:30:34 +0000
committerKevin May <kevin.may@arm.com>2023-08-24 08:52:47 +0000
commite40cc8359b02a7786908294300c45b672cf6b0e4 (patch)
treeafaaccc2b41a71b17ba714d061ab6bf631b3fd94
parent7fbf8109a972f0508f82ea40acc103b5959d115b (diff)
downloadarmnn-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
-rw-r--r--.clang-format34
-rwxr-xr-xscripts/clang-format.sh49
2 files changed, 83 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000000..df1588d8de
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,34 @@
+BasedOnStyle: LLVM
+AccessModifierOffset: -4
+AllowShortFunctionsOnASingleLine: None
+AlwaysBreakTemplateDeclarations: true
+BinPackParameters: false
+BraceWrapping:
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: true
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ AfterExternBlock: false
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: true
+BreakBeforeBraces: Custom
+BreakConstructorInitializersBeforeComma: true
+BreakConstructorInitializers: BeforeColon
+Cpp11BracedListStyle: false
+IndentCaseLabels: true
+IndentWidth: 4
+IndentWrappedFunctionNames: true
+PointerAlignment: Left
+SpacesInContainerLiterals: false
+AlignConsecutiveAssignments: true
+ColumnLimit: 120
+ReflowComments: false
+SpacesBeforeTrailingComments: 4
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}