kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [kudu] branch master updated: Add .clang-format file
Date Tue, 25 Aug 2020 22:31:05 GMT
This is an automated email from the ASF dual-hosted git repository.

todd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new fc9b614  Add .clang-format file
fc9b614 is described below

commit fc9b614b3ae729a6f76ec2e47945e6331863c015
Author: Todd Lipcon <todd@lipcon.org>
AuthorDate: Thu Jul 30 15:27:52 2020 -0700

    Add .clang-format file
    
    This clang-format file seems to capture our existing style relatively
    well. I've been using it on my patches and only gotten a few complaints
    where the automatic formatting isn't quite what people expected, but I
    think the benefits of uniformity outweigh any particular aesthetic
    choices we might make.
    
    This patch updates the documentation to suggest running this on patches
    to modify only the changed lines using clang-format-diff.
    
    Change-Id: I41def9a77bd98bf09353fe9a7789756a1bff30c1
    Reviewed-on: http://gerrit.cloudera.org:8080/16260
    Reviewed-by: Attila Bukor <abukor@apache.org>
    Tested-by: Todd Lipcon <todd@apache.org>
---
 build-support/clang_format_diff.sh | 38 ++++++++++++++++++++++++++++++++++++++
 docs/contributing.adoc             | 20 ++++++++++++++++++--
 src/kudu/.clang-format             | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 2 deletions(-)

diff --git a/build-support/clang_format_diff.sh b/build-support/clang_format_diff.sh
new file mode 100755
index 0000000..2d0d2c1
--- /dev/null
+++ b/build-support/clang_format_diff.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+# This script acts as a simple wrapper to run clang-format-diff.phy
+# from the installed thirdparty directory, with the appropriate
+# clang-format binary passed in.
+
+set -e
+
+ROOT="$(dirname $BASH_SOURCE)/.."
+TP="$ROOT/thirdparty/installed/uninstrumented/"
+TOOL="$TP/share/clang/clang-format-diff.py"
+CLANG_FORMAT="$TP/bin/clang-format"
+
+for path in "$TOOL" "$CLANG_FORMAT" ; do
+  if [ ! -x $path ]; then
+    >&2 echo $path not found, please build thirdparty first
+    exit 1
+  fi
+done
+
+exec $TOOL -binary "$CLANG_FORMAT" "$@"
diff --git a/docs/contributing.adoc b/docs/contributing.adoc
index ab419c9..a638409 100644
--- a/docs/contributing.adoc
+++ b/docs/contributing.adoc
@@ -191,8 +191,24 @@ Get familiar with these guidelines so that your contributions can be
reviewed an
 integrated quickly and easily.
 
 In general, Kudu follows the
-link:https://google.github.io/styleguide/cppguide.html[Google {cpp} Style Guide],
-with the following exceptions:
+link:https://google.github.io/styleguide/cppguide.html[Google {cpp} Style Guide].
+
+A `clang-format` file is provided in `src/kudu/.clang-format` which allows
+automatic formatting of source code whitespacing, indentation, etc. Not all
+existing code conforms to this automatic formatting, so prefer using
+`clang-format-diff` to format only the lines changed by your patch. For example,
+after making a commit, run the following from the root of your checked out
+source:
++
+[source,bash]
+----
+git show -U0 | build-support/clang_format_diff.sh -i -p1
+git commit -a --amend
+----
+
+=== Exceptions from Google Style Guide
+Kudu's code base makes the following notable exceptions from the Google Style Guide
+referenced above:
 
 ==== Notes on {cpp} 11
 
diff --git a/src/kudu/.clang-format b/src/kudu/.clang-format
new file mode 100644
index 0000000..f7f51d3
--- /dev/null
+++ b/src/kudu/.clang-format
@@ -0,0 +1,38 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+# This file describes formatting conventions for the Kudu source
+# code. The options are documented at:
+#   https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+
+BasedOnStyle: Google
+ColumnLimit: 100
+
+# We use IWYU to sort includes, so we disable clang-format's
+# sorting.
+SortIncludes: false
+
+# Some of the older code uses 'Foo *bar' instead of 'Foo* bar'. But,
+# for new code, we want to switch to the latter formatting regardless
+# of what the rest of the file uses.
+DerivePointerAlignment: false
+
+# We prefer to put arguments and parameters on separate lines when they
+# don't fit on one line, rather than bin-packing them into as few lines
+# as possible.
+BinPackArguments: false
+BinPackParameters: false


Mime
View raw message