https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0c64aed86af2f79d95287…
commit 0c64aed86af2f79d95287b899cd8ff10b2ae208b
Author: Victor Perevertkin <victor.perevertkin(a)reactos.org>
AuthorDate: Tue Dec 24 13:55:30 2019 +0300
Commit: Victor Perevertkin <victor(a)perevertkin.ru>
CommitDate: Sat Dec 28 01:23:49 2019 +0200
[REACTOS] Introduce .clang-format file
And set up a Travis job for checking formatting on PRs
---
.clang-format | 35 +++++++++++++++++++++++++++++++++++
.travis.yml | 31 +++++++++++++++++++++++++++----
sdk/tools/check_code_format.sh | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 4 deletions(-)
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000000..f7e2e07f624
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,35 @@
+# full manual is at
https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+---
+BasedOnStyle: Microsoft
+
+IndentWidth: 4
+UseTab: Never
+
+IndentCaseLabels: true
+
+AllowAllArgumentsOnNextLine: false
+AllowAllParametersOfDeclarationOnNextLine: false
+
+BinPackParameters: false
+BinPackArguments: true
+
+# This applies to () [] <>
+AlignAfterOpenBracket: AlwaysBreak
+
+# Always break before braces
+BreakBeforeBraces: Allman
+
+# return type on it's own line
+AlwaysBreakAfterReturnType: All
+
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+...
diff --git a/.travis.yml b/.travis.yml
index a91c8c95fd9..01e6d118601 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,35 @@
-language: bash
+dist: bionic
+language: cpp
+
+addons:
+ apt:
+ sources:
+ - sourceline: 'deb
http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9
main'
+ key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
+ packages:
+ clang-format-9
git:
- depth: 5
+ depth: 1
+
+env:
+ global:
+ - DO_BUILD=0
+ - DO_CHECK=0
+ - CLFORMAT_BINARY=clang-format-9
+ jobs:
+ - DO_BUILD=1
+ - DO_CHECK=1
-before_script:
+before_install:
+ - ln -s /usr/share/clang/clang-format-9/clang-format-diff.py ./sdk/tools/;
- wget
https://svn.reactos.org/amine/RosBEBinFull.tar.gz -O RosBE.tar.gz
- tar -xzf RosBE.tar.gz
- echo 'mkdir ../Build && cd ../Build &&
$TRAVIS_BUILD_DIR/configure.sh -DENABLE_ROSTESTS=1 && ninja -k 0 && ninja
bootcd' > tmp_file
script:
- - ./RosBEBinFull/RosBE.sh < tmp_file
+ - if [ $DO_BUILD == "1" ]; then
+ ./RosBEBinFull/RosBE.sh < tmp_file;
+ elif [ $DO_CHECK == "1" ]; then
+ ./sdk/tools/check_code_format.sh;
+ fi
diff --git a/sdk/tools/check_code_format.sh b/sdk/tools/check_code_format.sh
new file mode 100755
index 00000000000..8b282a15d13
--- /dev/null
+++ b/sdk/tools/check_code_format.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+# Copyright (c) 2017 Google Inc.
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Script to determine if source code in Pull Request is properly formatted.
+# Exits with non 0 exit code if formatting is needed.
+#
+# This script assumes to be invoked at the project root directory.
+
+BASE_BRANCH=${1:-master}
+
+FILES_TO_CHECK=$(git diff --name-only ${BASE_BRANCH} | grep -E
".*\.(cpp|cc|c\+\+|cxx|c|h|hpp)$")
+
+if [ -z "${FILES_TO_CHECK}" ]; then
+ echo "No source code to check for formatting."
+ exit 0
+fi
+
+FORMAT_DIFF=$(git diff -U0 ${BASE_BRANCH} -- ${FILES_TO_CHECK} | python3
./sdk/tools/clang-format-diff.py -binary ${CLFORMAT_BINARY} -p1 -style=file)
+
+if [ -z "${FORMAT_DIFF}" ]; then
+ echo "All source code in PR properly formatted."
+ exit 0
+else
+ echo "Found formatting errors!"
+ echo "${FORMAT_DIFF}"
+ exit 1
+fi