From 745cf6ff92ea147bfff55dd246f2af5333fbe219 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 7 Jul 2021 17:53:05 +0200 Subject: [PATCH] Added a script to reformat the entire codebase using clang-format. --- tools/reformat_codebase.sh | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 tools/reformat_codebase.sh diff --git a/tools/reformat_codebase.sh b/tools/reformat_codebase.sh new file mode 100755 index 000000000..c5658dc75 --- /dev/null +++ b/tools/reformat_codebase.sh @@ -0,0 +1,45 @@ +#!/usr/bin/bash +# SPDX-License-Identifier: MIT +# +# EmulationStation Desktop Edition +# reformat_codebase.sh +# +# Automatically reformats the codebase using clang-format. +# The .clang-format style configuration file in the root of the repository will be +# used to apply the code formatting to the "es-app/src" and "es-core/src" trees. +# All files will be formatted in-place meaning they will be overwritten with any changes. +# +# The purpose of this script is primarily to apply updated formatting as clang-format +# improves over time, but potentially also to apply any changes to the ES-DE coding style. +# +# This script is only intended to be used on Linux systems. +# + +if [ ! $(which clang-format 2>/dev/null) ]; then + echo "Can't find clang-format which is required to run this script" + exit +fi + +if [ ! -d ../es-app/src ]; then + echo "Can't find the ../es-app/src directory, this script must run from the tools directory" + exit +fi + +APP_CPP_NUM_FILES=$(find ../es-app/src -name '*.cpp' | wc -l) +APP_H_NUM_FILES=$(find ../es-app/src -name '*.h' | wc -l) + +find ../es-app/src -name '*.cpp' -exec echo clang-format -i {} \; +find ../es-app/src -name '*.cpp' -exec clang-format -i {} \; +find ../es-app/src -name '*.h' -exec echo clang-format -i {} \; +find ../es-app/src -name '*.h' -exec clang-format -i {} \; + +CORE_CPP_NUM_FILES=$(find ../es-core/src -name '*.cpp' | wc -l) +CORE_H_NUM_FILES=$(find ../es-core/src -name '*.h' | wc -l) + +find ../es-core/src -name '*.cpp' -exec echo clang-format -i {} \; +find ../es-core/src -name '*.cpp' -exec clang-format -i {} \; +find ../es-core/src -name '*.h' -exec echo clang-format -i {} \; +find ../es-core/src -name '*.h' -exec clang-format -i {} \; + +echo "Processed" $APP_CPP_NUM_FILES ".cpp files and" $APP_H_NUM_FILES ".h files in es-app/src" +echo "Processed" $CORE_CPP_NUM_FILES ".cpp files and" $CORE_H_NUM_FILES ".h files in es-core/src"