-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CMake style target and githooks for formatting
- Loading branch information
1 parent
5023196
commit f279264
Showing
6 changed files
with
207 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,84 @@ | ||
BasedOnStyle : google | ||
BasedOnStyle : LLVM | ||
# Indent formatting | ||
IndentWidth : 2 | ||
BreakBeforeBraces : Linux | ||
Language: Cpp | ||
UseTab: Never | ||
KeepEmptyLinesAtTheStartOfBlocks : true | ||
MaxEmptyLinesToKeep : 2 | ||
AccessModifierOffset : -2 | ||
UseTab: Never | ||
# This must be off so that include order in RAJA is preserved | ||
SortIncludes: false | ||
|
||
# Alignment of consecutive declarations, assignments etc | ||
AlignConsecutiveAssignments : true | ||
AlignConsecutiveDeclarations : false | ||
AlignConsecutiveMacros : true | ||
AlignTrailingComments : true | ||
|
||
# Control curly brace placement | ||
BreakBeforeBraces : Custom | ||
BraceWrapping: | ||
AfterCaseLabel: true | ||
AfterClass: true | ||
AfterControlStatement: true | ||
AfterEnum: true | ||
AfterFunction: true | ||
AfterNamespace: true | ||
AfterObjCDeclaration: false | ||
AfterStruct: true | ||
AfterUnion: true | ||
AfterExternBlock: false | ||
BeforeCatch: true | ||
BeforeElse: true | ||
BeforeLambdaBody: false | ||
IndentBraces: false | ||
SplitEmptyFunction: false | ||
SplitEmptyRecord: false | ||
SplitEmptyNamespace: false | ||
|
||
# Pointer alignment | ||
DerivePointerAlignment: false | ||
PointerAlignment: Left | ||
|
||
# Single line config | ||
AllowShortIfStatementsOnASingleLine : true | ||
ConstructorInitializerAllOnOneLineOrOnePerLine : true | ||
AllowShortFunctionsOnASingleLine : true | ||
AllowShortLoopsOnASingleLine : false | ||
BinPackParameters : false | ||
AllowShortLambdasOnASingleLine : None | ||
PackConstructorInitializers : CurrentLine | ||
AllowAllArgumentsOnNextLine : true | ||
AllowAllParametersOfDeclarationOnNextLine : false | ||
AlignTrailingComments : true | ||
BinPackArguments : true | ||
BinPackParameters : false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine : true | ||
ColumnLimit : 80 | ||
PenaltyBreakBeforeFirstCallParameter : 100 | ||
PenaltyReturnTypeOnItsOwnLine : 65000 | ||
PenaltyBreakString : 10 | ||
|
||
# These improve formatting results but require clang 3.6/7 or higher | ||
BreakBeforeBinaryOperators : None | ||
AlignAfterOpenBracket: true | ||
BinPackArguments : false | ||
AlignAfterOpenBracket: Align | ||
AlignOperands : true | ||
AlwaysBreakTemplateDeclarations : true | ||
Cpp11BracedListStyle : true | ||
AlwaysBreakAfterDefinitionReturnType : None | ||
PenaltyReturnTypeOnItsOwnLine : 10000 | ||
BreakBeforeBinaryOperators : None | ||
|
||
# Indents | ||
IndentCaseLabels: true | ||
|
||
# Lambda body | ||
LambdaBodyIndentation : Signature | ||
|
||
SeparateDefinitionBlocks : Always | ||
|
||
# Space before/after settings | ||
SpaceAfterTemplateKeyword: false | ||
SpaceBeforeCpp11BracedList: true | ||
SpaceBeforeCtorInitializerColon: true | ||
SpaceBeforeInheritanceColon: true | ||
SpaceBeforeRangeBasedForLoopColon: true | ||
SpaceInEmptyBlock: false | ||
SpacesBeforeTrailingComments: 2 | ||
SpacesInAngles: false | ||
SpacesInCStyleCastParentheses: false | ||
SpacesInContainerLiterals: false | ||
SpacesInConditionalStatement: false | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Copyright (c) 2016-24, Lawrence Livermore National Security, LLC | ||
# and RAJA project contributors. See the RAJA/LICENSE file for details. | ||
# | ||
# SPDX-License-Identifier: (BSD-3-Clause) | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
# List of file extensions to format | ||
file_extensions=("cpp" "h" "c" "hpp") | ||
__clang_format_executable="" | ||
# Check if clang-format exists | ||
if command -v "$RAJA_CLANG_FORMAT" &> /dev/null; then | ||
__clang_format_executable="$RAJA_CLANG_FORMAT" | ||
elif command -v clang-format &> /dev/null; then | ||
__clang_format_executable=clang-format | ||
else | ||
echo "Warning: clang-format and the environment variable RAJA_CLANG_FORMAT are not available. | ||
Please set RAJA_CLANG_FORMAT to enable the automatic file formatting git hook." | ||
exit 0 | ||
fi | ||
|
||
# Check the major version of the provided clang-format | ||
VERSION_STRING=$($__clang_format_executable --version) | ||
MAJOR_VERSION=$(echo "$VERSION_STRING" | grep -oP '\d+' | head -1) | ||
|
||
if [ "$MAJOR_VERSION" != "14" ]; then | ||
echo "Warning: RAJA_CLANG_FORMAT not set to a valid version number." | ||
exit 0 | ||
else | ||
echo "Using clang-format at $RAJA_CLANG_FORMAT" | ||
fi | ||
|
||
# Convert file extensions array to regex pattern | ||
IFS="|" | ||
file_extensions_pattern="\.(${file_extensions[*]})$" | ||
unset IFS | ||
|
||
RAJA_DIR="$(git rev-parse --show-toplevel)" | ||
|
||
# Function to format files | ||
format_file() { | ||
local loc_file="$1" | ||
"$__clang_format_executable" -i "$loc_file" | ||
git add "$loc_file" | ||
} | ||
|
||
# Find and format staged files with the specified extensions | ||
for file in $(git diff --cached --name-only --diff-filter=ACM | grep -E "$file_extensions_pattern"); do | ||
if [[ -f "$RAJA_DIR/$file" ]]; then | ||
echo "Formatting $RAJA_DIR/$file" | ||
format_file "$RAJA_DIR/$file" | ||
fi | ||
done | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Copyright (c) 2016-24, Lawrence Livermore National Security, LLC | ||
# and RAJA project contributors. See the RAJA/LICENSE file for details. | ||
# | ||
# SPDX-License-Identifier: (BSD-3-Clause) | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
#------------------------------------------------------------------------------ | ||
# This script installs client-side hooks | ||
#------------------------------------------------------------------------------ | ||
basedir=`git rev-parse --show-toplevel` | ||
hooksdir="$basedir/.git/hooks/" | ||
cp -v $basedir/scripts/githooks/pre-commit $hooksdir |