diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..b8292571 --- /dev/null +++ b/.clang-format @@ -0,0 +1,112 @@ +--- +BasedOnStyle: LLVM +IndentWidth: 4 +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: true +AlignTrailingComments: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: true +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 4 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... diff --git a/.travis.yml b/.travis.yml index da9c2049..29149668 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,10 @@ matrix: env: - OS_TYPE=doxygen addons: { apt: { packages: ["cmake", "graphviz"] } } + - os: linux + env: + - OS_TYPE=clangformat + addons: { apt: { packages: ["clang-format-6.0"], sources: ["llvm-toolchain-xenial-6.0"] } } before_install: diff --git a/CI/travis/before_install_linux b/CI/travis/before_install_linux index fe548e7c..0c1ce407 100755 --- a/CI/travis/before_install_linux +++ b/CI/travis/before_install_linux @@ -53,6 +53,10 @@ handle_doxygen() { cd .. } +handle_clangformat() { + echo "Clang-format version: " "$(/usr/bin/clang-format-6.0 --version)" +} + OS_TYPE=${1:-default} OS_VERSION=${2} diff --git a/CI/travis/clangformat.sh b/CI/travis/clangformat.sh new file mode 100755 index 00000000..374917cc --- /dev/null +++ b/CI/travis/clangformat.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +echo_red() { printf "\033[1;31m$*\033[m\n"; } +echo_green() { printf "\033[1;32m$*\033[m\n"; } + +############################################################################ +# Check if the file given as input has .h or .cpp extension +############################################################################ +is_source_file() { + local file="$1" + + EXTENSIONS=".hpp .cpp" + + for extension in $EXTENSIONS; do + [[ "${file: -2}" == "$extension" || "${file: -4}" == "$extension" ]] && return 0 + done; + + return 1 +} + + +############################################################################ +# Check if the files modified in the current commit / commit range respect +# the coding style defined in the .clang-format file +############################################################################ +COMMIT_RANGE=$TRAVIS_COMMIT_RANGE + +if [ -z "$TRAVIS_PULL_REQUEST_SHA" ] +then + COMMIT_RANGE=HEAD~1 +fi + +git diff --name-only --diff-filter=d $COMMIT_RANGE | while read -r file; do + if is_source_file "$file" + then + /usr/bin/clang-format-6.0 -i "$file" + fi +done; + +git diff --exit-code || { + echo_red "The code is not properly formatted!" + exit 1 +} + +echo_green "The code is properly formatted!" diff --git a/CI/travis/make_linux b/CI/travis/make_linux index 787ddf49..ccb49912 100755 --- a/CI/travis/make_linux +++ b/CI/travis/make_linux @@ -35,6 +35,10 @@ handle_doxygen() { ./CI/travis/doxygen.sh } +handle_clangformat() { + ./CI/travis/clangformat.sh +} + LIBNAME="$1" OS_TYPE=${2:-default} OS_VERSION="$3" diff --git a/src/digital/m2kdigital.cpp b/src/digital/m2kdigital.cpp index 3bea5616..51e8ff21 100644 --- a/src/digital/m2kdigital.cpp +++ b/src/digital/m2kdigital.cpp @@ -28,6 +28,9 @@ using namespace std; M2kDigital::M2kDigital(struct iio_context *ctx, std::string logic_dev, bool sync) : m_pimpl(std::unique_ptr(new M2kDigitalImpl(ctx, logic_dev, sync))) { + + + // test format should fail } M2kDigital::~M2kDigital()