diff --git a/.ci/build.groovy b/.ci/build.groovy index 139dec9317f..a40620c5838 100644 --- a/.ci/build.groovy +++ b/.ci/build.groovy @@ -43,7 +43,7 @@ catchError { stage("Build & Upload") { timeout(time: 70, unit: 'MINUTES') { container("builder") { - sh "NPROC=5 BUILD_BRANCH=${ghprbTargetBranch} release-centos7/build/build-tiflash-ci.sh" + sh "NPROC=5 BUILD_BRANCH=${ghprbTargetBranch} ENABLE_FORMAT_CHECK=true release-centos7/build/build-tiflash-ci.sh" sh "PULL_ID=${ghprbPullId} COMMIT_HASH=${ghprbActualCommit} release-centos7/build/upload-ci-build.sh" } } diff --git a/README.md b/README.md index 6b96653b23c..16c4c3b72e4 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,12 @@ $ popd ``` Now you will get TiFlash binary under `WORKSPACE/tics/build/dbms/src/Server/tiflash`. + +### Notice + +Before submitting pull request, please use [format-diff.py](format-diff.py) to format source code, otherwise ci-build may raise error. +``` +# WORKSPACE/tics +$ python3 format-diff.py --diff_from `git merge-base ${TARGET_REMOTE_BRANCH} HEAD` +``` + diff --git a/dbms/src/Storages/DeltaMerge/.clang-format b/dbms/src/Storages/DeltaMerge/.clang-format deleted file mode 100644 index ccdb933ce7c..00000000000 --- a/dbms/src/Storages/DeltaMerge/.clang-format +++ /dev/null @@ -1,89 +0,0 @@ ---- -BasedOnStyle: Google -Language: Cpp -AlignAfterOpenBracket: true -BreakBeforeBraces: Custom -BraceWrapping: { - AfterClass: 'true' - AfterControlStatement: 'true' - AfterEnum : 'true' - AfterFunction : 'true' - AfterNamespace : 'true' - AfterStruct : 'true' - AfterUnion : 'true' - BeforeCatch : 'true' - BeforeElse : 'true' - IndentBraces : 'false' -} - -BreakConstructorInitializersBeforeComma: false -Cpp11BracedListStyle: true -ColumnLimit: 140 -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ExperimentalAutoDetectBinPacking: true -UseTab: Never -TabWidth: 4 -IndentWidth: 4 -Standard: Cpp11 -PointerAlignment: Middle -MaxEmptyLinesToKeep: 2 -KeepEmptyLinesAtTheStartOfBlocks: true -AllowShortFunctionsOnASingleLine: Inline -#AllowShortFunctionsOnASingleLine: Empty -AlwaysBreakTemplateDeclarations: true -IndentCaseLabels: false -#SpaceAfterTemplateKeyword: true -#SortIncludes: true -FixNamespaceComments: true - -ReflowComments: false -AlignEscapedNewlinesLeft: true - -# Not changed: -AccessModifierOffset: -4 -AlignConsecutiveAssignments: true -AlignConsecutiveDeclarations: true -AlignOperands: false -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakBeforeMultilineStrings: false -BinPackArguments: false -BinPackParameters: false -BreakBeforeBinaryOperators: All -BreakBeforeTernaryOperators: true -CommentPragmas: '^ IWYU pragma:' -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -DerivePointerAlignment: false -DisableFormat: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IndentWidth: 4 -IndentWrappedFunctionNames: false -MacroBlockBegin: '' -MacroBlockEnd: '' -NamespaceIndentation: None -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: true -ObjCSpaceBeforeProtocolList: true -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -SpaceAfterCStyleCast: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -... - diff --git a/dbms/src/Storages/Page/.clang-format b/dbms/src/Storages/Page/.clang-format deleted file mode 100644 index ccdb933ce7c..00000000000 --- a/dbms/src/Storages/Page/.clang-format +++ /dev/null @@ -1,89 +0,0 @@ ---- -BasedOnStyle: Google -Language: Cpp -AlignAfterOpenBracket: true -BreakBeforeBraces: Custom -BraceWrapping: { - AfterClass: 'true' - AfterControlStatement: 'true' - AfterEnum : 'true' - AfterFunction : 'true' - AfterNamespace : 'true' - AfterStruct : 'true' - AfterUnion : 'true' - BeforeCatch : 'true' - BeforeElse : 'true' - IndentBraces : 'false' -} - -BreakConstructorInitializersBeforeComma: false -Cpp11BracedListStyle: true -ColumnLimit: 140 -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ExperimentalAutoDetectBinPacking: true -UseTab: Never -TabWidth: 4 -IndentWidth: 4 -Standard: Cpp11 -PointerAlignment: Middle -MaxEmptyLinesToKeep: 2 -KeepEmptyLinesAtTheStartOfBlocks: true -AllowShortFunctionsOnASingleLine: Inline -#AllowShortFunctionsOnASingleLine: Empty -AlwaysBreakTemplateDeclarations: true -IndentCaseLabels: false -#SpaceAfterTemplateKeyword: true -#SortIncludes: true -FixNamespaceComments: true - -ReflowComments: false -AlignEscapedNewlinesLeft: true - -# Not changed: -AccessModifierOffset: -4 -AlignConsecutiveAssignments: true -AlignConsecutiveDeclarations: true -AlignOperands: false -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakBeforeMultilineStrings: false -BinPackArguments: false -BinPackParameters: false -BreakBeforeBinaryOperators: All -BreakBeforeTernaryOperators: true -CommentPragmas: '^ IWYU pragma:' -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -DerivePointerAlignment: false -DisableFormat: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IndentWidth: 4 -IndentWrappedFunctionNames: false -MacroBlockBegin: '' -MacroBlockEnd: '' -NamespaceIndentation: None -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: true -ObjCSpaceBeforeProtocolList: true -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -SpaceAfterCStyleCast: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -... - diff --git a/dbms/src/Storages/Page/stable/.clang-format b/dbms/src/Storages/Page/stable/.clang-format deleted file mode 100644 index ccdb933ce7c..00000000000 --- a/dbms/src/Storages/Page/stable/.clang-format +++ /dev/null @@ -1,89 +0,0 @@ ---- -BasedOnStyle: Google -Language: Cpp -AlignAfterOpenBracket: true -BreakBeforeBraces: Custom -BraceWrapping: { - AfterClass: 'true' - AfterControlStatement: 'true' - AfterEnum : 'true' - AfterFunction : 'true' - AfterNamespace : 'true' - AfterStruct : 'true' - AfterUnion : 'true' - BeforeCatch : 'true' - BeforeElse : 'true' - IndentBraces : 'false' -} - -BreakConstructorInitializersBeforeComma: false -Cpp11BracedListStyle: true -ColumnLimit: 140 -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ExperimentalAutoDetectBinPacking: true -UseTab: Never -TabWidth: 4 -IndentWidth: 4 -Standard: Cpp11 -PointerAlignment: Middle -MaxEmptyLinesToKeep: 2 -KeepEmptyLinesAtTheStartOfBlocks: true -AllowShortFunctionsOnASingleLine: Inline -#AllowShortFunctionsOnASingleLine: Empty -AlwaysBreakTemplateDeclarations: true -IndentCaseLabels: false -#SpaceAfterTemplateKeyword: true -#SortIncludes: true -FixNamespaceComments: true - -ReflowComments: false -AlignEscapedNewlinesLeft: true - -# Not changed: -AccessModifierOffset: -4 -AlignConsecutiveAssignments: true -AlignConsecutiveDeclarations: true -AlignOperands: false -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: true -AllowShortCaseLabelsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakBeforeMultilineStrings: false -BinPackArguments: false -BinPackParameters: false -BreakBeforeBinaryOperators: All -BreakBeforeTernaryOperators: true -CommentPragmas: '^ IWYU pragma:' -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -DerivePointerAlignment: false -DisableFormat: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IndentWidth: 4 -IndentWrappedFunctionNames: false -MacroBlockBegin: '' -MacroBlockEnd: '' -NamespaceIndentation: None -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: true -ObjCSpaceBeforeProtocolList: true -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -SpaceAfterCStyleCast: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -... - diff --git a/format-diff.py b/format-diff.py index c75e3f93be4..959607c065e 100755 --- a/format-diff.py +++ b/format-diff.py @@ -15,11 +15,10 @@ def run_cmd(cmd, show_cmd=False): def main(): default_suffix = ['.cpp', '.h', '.cc', '.hpp'] parser = argparse.ArgumentParser(description='TiFlash Code Format', - formatter_class=argparse.RawTextHelpFormatter) + formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--repo_path', help='path of tics repository', default=os.getcwd()) parser.add_argument('--suffix', - help='suffix of files to format, split by space, default: {}'.format(' '.join(default_suffix)), - default=' '.join(default_suffix)) + help='suffix of files to format, split by space', default=' '.join(default_suffix)) parser.add_argument('--ignore_suffix', help='ignore files with suffix, split by space') parser.add_argument('--diff_from', help='commit hash/branch to check git diff', default='HEAD') parser.add_argument('--check_formatted', help='exit -1 if NOT formatted', action='store_true') @@ -32,7 +31,7 @@ def main(): os.chdir(tics_repo_path) files_to_check = run_cmd('git diff HEAD --stat') if args.diff_from == 'HEAD' else run_cmd( - 'git diff HEAD {} --stat'.format(args.diff_from)) + 'git diff {} --stat'.format(args.diff_from)) files_to_check = [os.path.join(tics_repo_path, s.split()[0]) for s in files_to_check[:-1]] files_to_format = [] for f in files_to_check: @@ -55,14 +54,17 @@ def main(): cmd = 'clang-format -i {}'.format(' '.join(files_to_format)) if subprocess.Popen(cmd, shell=True, cwd=tics_repo_path).wait(): exit(-1) - if run_cmd('git diff --stat'): + diff_res = run_cmd('git diff --stat') + if diff_res: print('Error: found files NOT formatted') + print('\n'.join(diff_res[:-1])) exit(-1) else: print("Format check passed") else: cmd = 'clang-format -i {}'.format(' '.join(files_to_format)) subprocess.Popen(cmd, shell=True, cwd=tics_repo_path).wait() + print("Finish code format") else: print('No file to format') diff --git a/release-centos7/build/build-tiflash-ci.sh b/release-centos7/build/build-tiflash-ci.sh index 105fc3e65d0..548e22e3f18 100755 --- a/release-centos7/build/build-tiflash-ci.sh +++ b/release-centos7/build/build-tiflash-ci.sh @@ -9,15 +9,27 @@ else echo "ccache has been installed" fi +command -v clang-format > /dev/null 2>&1 +if [[ $? != 0 ]]; then + curl -o "/usr/local/bin/clang-format" http://fileserver.pingcap.net/download/builds/pingcap/tiflash/ci-cache/clang-format + chmod +x "/usr/local/bin/clang-format" +else + echo "clang-format has been installed" +fi + set -ueox pipefail SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" SRCPATH=${1:-$(cd $SCRIPTPATH/../..; pwd -P)} -# DO NOT enable format check until standards unified -#curl -o "/usr/local/bin/clang-format" http://fileserver.pingcap.net/download/builds/pingcap/tiflash/ci-cache/clang-format -#chmod +x "/usr/local/bin/clang-format" -#python3 ${SRCPATH}/format-diff.py --repo_path "${SRCPATH}" --check_formatted --diff_from `git merge-base origin/master HEAD` +CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} +BUILD_BRANCH=${BUILD_BRANCH:-master} +ENABLE_FORMAT_CHECK=${ENABLE_FORMAT_CHECK:-false} + +if [[ "${ENABLE_FORMAT_CHECK}" == "true" ]]; then + python3 ${SRCPATH}/format-diff.py --repo_path "${SRCPATH}" --check_formatted --diff_from `git merge-base origin/${BUILD_BRANCH} HEAD` + export ENABLE_FORMAT_CHECK=false +fi CI_CCACHE_USED_SRCPATH="/build/tics" export INSTALL_DIR=${INSTALL_DIR:-"$SRCPATH/release-centos7/tiflash"} @@ -33,9 +45,7 @@ fi NPROC=${NPROC:-$(nproc || grep -c ^processor /proc/cpuinfo)} ENABLE_TEST=${ENABLE_TEST:-1} ENABLE_EMBEDDED_COMPILER="FALSE" -CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} UPDATE_CCACHE=${UPDATE_CCACHE:-false} -BUILD_BRANCH=${BUILD_BRANCH:-master} BUILD_UPDATE_DEBUG_CI_CCACHE=${BUILD_UPDATE_DEBUG_CI_CCACHE:-false} CCACHE_REMOTE_TAR="${BUILD_BRANCH}-${CMAKE_BUILD_TYPE}.tar" CCACHE_REMOTE_TAR=$(echo "${CCACHE_REMOTE_TAR}" | tr 'A-Z' 'a-z')