Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add make style target and refactor RAJA with clang-format #1731

Closed
wants to merge 12 commits into from
Closed
  •  
  •  
  •  
72 changes: 58 additions & 14 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,27 +1,71 @@
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
AlwaysBreakAfterDefinitionReturnType: false

# 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: true
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
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
BreakBeforeBinaryOperators : None

SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInConditionalStatement: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ project(RAJA LANGUAGES CXX C
VERSION ${RAJA_LOADED})

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/thirdparty" ${CMAKE_MODULE_PATH})

set(BLT_REQUIRED_CLANGFORMAT_VERSION "14" CACHE STRING "")
include(cmake/SetupRajaOptions.cmake)

cmake_minimum_required(VERSION 3.23)
Expand Down Expand Up @@ -136,6 +136,9 @@ include(cmake/SetupCompilers.cmake)
# Macros for building executables and libraries
include (cmake/RAJAMacros.cmake)

# Configure `style` target for enforcing code style
raja_add_code_checks()

set (raja_sources
src/AlignedRangeIndexSetBuilders.cpp
src/DepGraphNode.cpp
Expand Down
59 changes: 59 additions & 0 deletions cmake/RAJAMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,62 @@ macro(raja_add_benchmark)
NUM_OMP_THREADS ${arg_NUM_OMP_THREADS}
COMMAND ${TEST_DRIVER} ${arg_NAME})
endmacro(raja_add_benchmark)

##------------------------------------------------------------------------------
## raja_add_code_checks()
##
## Adds code checks for all source files recursively in the RAJA repository.
##
## This creates the following parent build targets:
## check - Runs a non file changing style check and CppCheck
## style - In-place code formatting
##
## Creates various child build targets that follow this pattern:
## raja_<check|style>
## raja_<cppcheck|clangformat>_<check|style>
##------------------------------------------------------------------------------
macro(raja_add_code_checks)

set(options)
set(singleValueArgs)
set(multiValueArgs)

# Parse the arguments to the macro
cmake_parse_arguments(arg
"${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN})

# Only do code checks if building raja by itself and not included in
# another project
if ("${PROJECT_SOURCE_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
# Create file globbing expressions that only include directories that contain source
# TODO(bowen) Add examples, exercises and benchmark to the list below
set(_base_dirs "RAJA" "benchmark" "include" "src" "test")
set(_ext_expressions "*.cpp" "*.hpp" "*.inl"
"*.cxx" "*.hxx" "*.cc" "*.c" "*.h" "*.hh")

set(_glob_expressions)
foreach(_exp ${_ext_expressions})
foreach(_base_dir ${_base_dirs})
list(APPEND _glob_expressions "${PROJECT_SOURCE_DIR}/${_base_dir}/${_exp}")
endforeach()
endforeach()

# Glob for list of files to run code checks on
set(_sources)
file(GLOB_RECURSE _sources ${_glob_expressions})

blt_add_code_checks(PREFIX RAJA
SOURCES ${_sources}
CLANGFORMAT_CFG_FILE ${PROJECT_SOURCE_DIR}/.clang-format
CPPCHECK_FLAGS --enable=all --inconclusive)

# Set FOLDER property for code check targets
foreach(_suffix clangformat_check clangformat_style clang_tidy_check clang_tidy_style)
set(_tgt ${arg_PREFIX}_${_suffix})
if(TARGET ${_tgt})
set_target_properties(${_tgt} PROPERTIES FOLDER "RAJA/code_checks")
endif()
endforeach()
endif()

endmacro(raja_add_code_checks)
10 changes: 6 additions & 4 deletions include/RAJA/RAJA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#endif

#if defined(RAJA_ENABLE_DESUL_ATOMICS)
#include "RAJA/policy/desul.hpp"
#include "RAJA/policy/desul.hpp"
#endif

#include "RAJA/index/IndexSet.hpp"
Expand Down Expand Up @@ -197,11 +197,13 @@

#include "RAJA/pattern/sort.hpp"

namespace RAJA {
namespace expt{}
namespace RAJA
{
namespace expt
{}
// // provide a RAJA::expt namespace for experimental work, but bring alias
// // it into RAJA so it doesn't affect user code
// using namespace expt;
}
} // namespace RAJA

#endif // closing endif for header file include guard
Loading
Loading