From 5c49bb98ce17ca45349b633cc1709c0e662de18c Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Wed, 25 Dec 2024 18:08:53 +0000 Subject: [PATCH] Set up auto-formatter --- .clang-format | 21 +++++++++++++++++++++ CMakeLists.txt | 9 +++++++++ scripts/check-format.sh | 2 ++ scripts/format.sh | 2 ++ scripts/sources.sh | 3 +++ 5 files changed, 37 insertions(+) create mode 100644 .clang-format create mode 100755 scripts/check-format.sh create mode 100755 scripts/format.sh create mode 100755 scripts/sources.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..3840d47 --- /dev/null +++ b/.clang-format @@ -0,0 +1,21 @@ +--- +BasedOnStyle: WebKit +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: DontAlign +AlignOperands: false +AlignTrailingComments: false +TabWidth: 4 +UseTab: ForIndentation +DerivePointerAlignment: false +PointerAlignment: Right +BinPackArguments: true +BinPackParameters: true +ExperimentalAutoDetectBinPacking: false +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: None +ColumnLimit: 77 +... diff --git a/CMakeLists.txt b/CMakeLists.txt index 40dc82b..202e440 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,15 @@ macro(set_default_target_options target) endif() endmacro() +add_custom_target(format + COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/format.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) +add_custom_target(check-format + COMMAND sh ${CMAKE_SOURCE_DIR}/scripts/check-format.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} +) + add_subdirectory(engine) if (${TESTS}) diff --git a/scripts/check-format.sh b/scripts/check-format.sh new file mode 100755 index 0000000..423cec7 --- /dev/null +++ b/scripts/check-format.sh @@ -0,0 +1,2 @@ +scripts_dir=`dirname $0` +sh "$scripts_dir/sources.sh" | xargs -n 1 clang-format --dry-run --Werror diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100755 index 0000000..6a2c92c --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,2 @@ +scripts_dir=`dirname $0` +sh "$scripts_dir/sources.sh" | xargs -n 1 clang-format -i diff --git a/scripts/sources.sh b/scripts/sources.sh new file mode 100755 index 0000000..4074056 --- /dev/null +++ b/scripts/sources.sh @@ -0,0 +1,3 @@ +#!/bin/sh +root=`git rev-parse --show-toplevel` +find "$root/engine" "$root/tests" -name '*.c' -o -name '*.h'