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

Problem: code duplication and unnecessary nesting around ZMQ_THREAD_SAFE querying #2914

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
53 changes: 53 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: Never
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: false
IndentBraces: false

AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: true
BinPackArguments: true
BinPackParameters: false
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortFunctionsOnASingleLine: InlineOnly
AlwaysBreakTemplateDeclarations: false
ColumnLimit: 80
MaxEmptyLinesToKeep: 2
KeepEmptyLinesAtTheStartOfBlocks: false
ContinuationIndentWidth: 2
PointerAlignment: Right
ReflowComments: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Always
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11

SortIncludes: false

FixNamespaceComments: false
BreakBeforeBinaryOperators: NonAssignment
SpaceAfterTemplateKeyword: true
AlignAfterOpenBracket: Align
AlignOperands: true
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
SpaceAfterCStyleCast: true
BreakBeforeTernaryOperators: true
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ matrix:
- env: BUILD_TYPE=android CURVE=tweetnacl
os: linux
dist: trusty
- env: BUILD_TYPE=cmake DO_CLANG_FORMAT_CHECK=1 CLANG_FORMAT=/usr/local/clang-5.0.0/bin/clang-format
os: linux
addons:
apt:
sources:
- llvm-toolchain-trusty-5.0
packages:
- clang-5.0

sudo: required

Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ if (MSVC AND ENABLE_CPACK)
# add_crt_version (v100)
# add_crt_version (v90)

set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}")
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_BINARY_DIR})
set (CPACK_GENERATOR "NSIS")
set (CPACK_PACKAGE_NAME "ZeroMQ")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "ZeroMQ lightweight messaging kernel")
Expand Down Expand Up @@ -1138,3 +1138,5 @@ if (MSVC_VERSION EQUAL 1600)
file (APPEND "${ZMQ_SLN_FILENAME}" "\n# This should be regenerated!\n")
endif ()
endif ()

include(ClangFormat)
41 changes: 41 additions & 0 deletions builds/cmake/Modules/ClangFormat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# additional target to perform clang-format run, requires clang-format

# get all project files
file(GLOB_RECURSE ALL_SOURCE_FILES
RELATIVE ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src/*.cpp ${CMAKE_SOURCE_DIR}/src/*.h ${CMAKE_SOURCE_DIR}/src/*.hpp
${CMAKE_SOURCE_DIR}/tests/*.cpp ${CMAKE_SOURCE_DIR}/tests/*.h ${CMAKE_SOURCE_DIR}/tests/*.hpp
${CMAKE_SOURCE_DIR}/perf/*.cpp ${CMAKE_SOURCE_DIR}/perf/*.h ${CMAKE_SOURCE_DIR}/perf/*.hpp
${CMAKE_SOURCE_DIR}/tools/*.cpp ${CMAKE_SOURCE_DIR}/tools/*.h ${CMAKE_SOURCE_DIR}/tools/*.hpp
${CMAKE_SOURCE_DIR}/include/*.h
)

if("${CLANG_FORMAT}" STREQUAL "")
set(CLANG_FORMAT "clang-format")
endif()

add_custom_target(
clang-format
COMMAND ${CLANG_FORMAT} -style=file -i ${ALL_SOURCE_FILES}
)

function(JOIN VALUES GLUE OUTPUT)
string (REPLACE ";" "${GLUE}" _TMP_STR "${VALUES}")
set (${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction()

configure_file(builds/cmake/clang-format-check.sh.in clang-format-check.sh @ONLY)

add_custom_target(
clang-format-check
COMMAND chmod +x clang-format-check.sh
COMMAND ./clang-format-check.sh
COMMENT "Checking correct formatting according to .clang-format file using ${CLANG_FORMAT}"
)

add_custom_target(
clang-format-diff
COMMAND ${CLANG_FORMAT} -style=file -i ${ALL_SOURCE_FILES}
COMMAND git diff ${ALL_SOURCE_FILES}
COMMENT "Formatting with clang-format (using ${CLANG_FORMAT}) and showing differences with latest commit"
)
16 changes: 15 additions & 1 deletion builds/cmake/ci_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ CMAKE_OPTS+=("-DCMAKE_PREFIX_PATH:PATH=${BUILD_PREFIX}")
CMAKE_OPTS+=("-DCMAKE_LIBRARY_PATH:PATH=${BUILD_PREFIX}/lib")
CMAKE_OPTS+=("-DCMAKE_INCLUDE_PATH:PATH=${BUILD_PREFIX}/include")

if [ "$CLANG_FORMAT" != "" ] ; then
CMAKE_OPTS+=("-DCLANG_FORMAT=${CLANG_FORMAT}")
fi

if [ -z $CURVE ]; then
CMAKE_OPTS+=("-DENABLE_CURVE=OFF")
elif [ $CURVE == "libsodium" ]; then
Expand All @@ -31,4 +35,14 @@ elif [ $CURVE == "libsodium" ]; then
fi

# Build, check, and install from local source
( cd ../..; mkdir build_cmake && cd build_cmake && PKG_CONFIG_PATH=${BUILD_PREFIX}/lib/pkgconfig cmake "${CMAKE_OPTS[@]}" .. && make -j5 all VERBOSE=1 && make install && make -j5 test ) || exit 1
cd ../..
mkdir build_cmake
cd build_cmake
if [ "$DO_CLANG_FORMAT_CHECK" -eq "1" ] ; then
if ! ( PKG_CONFIG_PATH=${BUILD_PREFIX}/lib/pkgconfig cmake "${CMAKE_OPTS[@]}" .. && make clang-format-check) ; then
make clang-format-diff
exit 1
fi
else
( PKG_CONFIG_PATH=${BUILD_PREFIX}/lib/pkgconfig cmake "${CMAKE_OPTS[@]}" .. && make -j5 all VERBOSE=1 && make install && make -j5 test ) || exit 1
fi
14 changes: 14 additions & 0 deletions builds/cmake/clang-format-check.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
FAILED=0
IFS=";"
FILES="@ALL_SOURCE_FILES@"
IDS=$(echo -en "\n\b")
for FILE in $FILES
do
@CLANG_FORMAT@ -style=file -output-replacements-xml "$FILE" | grep "<replacement " >/dev/null &&
{
echo "$FILE is not correctly formatted"
FAILED=1
}
done
if [ "$FAILED" -eq "1" ] ; then exit 1 ; fi
Loading