arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject arrow git commit: ARROW-1221: [C++] Add run_clang_format.py script, exclusions file. Pin clang-format-3.9
Date Mon, 17 Jul 2017 16:11:10 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 5fbfd8e58 -> b474cacf7


ARROW-1221: [C++] Add run_clang_format.py script, exclusions file. Pin clang-format-3.9

Author: Wes McKinney <wes.mckinney@twosigma.com>

Closes #859 from wesm/ARROW-1221 and squashes the following commits:

dc0c997 [Wes McKinney] Add run_clang_format.py script, exclusions file. Pin clang-format-3.9


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/b474cacf
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/b474cacf
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/b474cacf

Branch: refs/heads/master
Commit: b474cacf77050b7bba242340d5a469ddeb67e92d
Parents: 5fbfd8e
Author: Wes McKinney <wes.mckinney@twosigma.com>
Authored: Mon Jul 17 18:11:03 2017 +0200
Committer: Uwe L. Korn <uwelk@xhochy.com>
Committed: Mon Jul 17 18:11:03 2017 +0200

----------------------------------------------------------------------
 cpp/CMakeLists.txt                            | 31 +++++------
 cpp/build-support/clang_format_exclusions.txt |  8 +++
 cpp/build-support/run-clang-format.sh         | 42 ---------------
 cpp/build-support/run_clang_format.py         | 61 ++++++++++++++++++++++
 dev/release/rat_exclude_files.txt             |  1 +
 5 files changed, 84 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/b474cacf/cpp/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index 3146b87..2891a5d 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -518,25 +518,22 @@ endif (UNIX)
 ############################################################
 # "make format" and "make check-format" targets
 ############################################################
-if (${CLANG_FORMAT_FOUND})
-  # runs clang format and updates files in place.
-  add_custom_target(format ${BUILD_SUPPORT_DIR}/run-clang-format.sh ${CMAKE_CURRENT_SOURCE_DIR}
${CLANG_FORMAT_BIN} 1
-    `find ${CMAKE_CURRENT_SOURCE_DIR}/src -name \\*.cc -or -name \\*.h |
-    sed -e '/_generated/g' |
-    sed -e '/windows_compatibility.h/g' |
-    sed -e '/pyarrow_api.h/g' |
-    sed -e '/config.h/g' |   # python/config.h
-    sed -e '/platform.h/g' |  # python/platform.h
-    sed -e '/ae.h/g' |
-    sed -e '/xxhash.cc/g' |
-    sed -e '/xxhash.h/g'`
-    )
 
-  # runs clang format and exits with a non-zero exit code if any files need to be reformatted
-  add_custom_target(check-format ${BUILD_SUPPORT_DIR}/run-clang-format.sh ${CMAKE_CURRENT_SOURCE_DIR}
${CLANG_FORMAT_BIN} 0
-  `find ${CMAKE_CURRENT_SOURCE_DIR}/src -name \\*.cc -or -name \\*.h | sed -e '/_generated/g'`)
-endif()
+set(CLANG_FORMAT_VERSION 3.9)
+
+# runs clang format and updates files in place.
+add_custom_target(format ${BUILD_SUPPORT_DIR}/run_clang_format.py
+  ${CLANG_FORMAT_VERSION}
+  ${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt
+  ${CMAKE_CURRENT_SOURCE_DIR}/src)
+
+# runs clang format and exits with a non-zero exit code if any files need to be reformatted
 
+# TODO(wesm): Make this work in run_clang_format.py
+# add_custom_target(check-format ${BUILD_SUPPORT_DIR}/run_clang_format.py
+#   ${CLANG_FORMAT_VERSION}
+#   ${BUILD_SUPPORT_DIR}/clang_format_exclusions.txt
+#   ${CMAKE_CURRENT_SOURCE_DIR}/src 1)
 
 ############################################################
 # "make clang-tidy" and "make check-clang-tidy" targets

http://git-wip-us.apache.org/repos/asf/arrow/blob/b474cacf/cpp/build-support/clang_format_exclusions.txt
----------------------------------------------------------------------
diff --git a/cpp/build-support/clang_format_exclusions.txt b/cpp/build-support/clang_format_exclusions.txt
new file mode 100644
index 0000000..2d5d86d
--- /dev/null
+++ b/cpp/build-support/clang_format_exclusions.txt
@@ -0,0 +1,8 @@
+*_generated*
+*windows_compatibility.h
+*pyarrow_api.h
+*python/config.h
+*python/platform.h
+*thirdparty/ae/*
+*xxhash.cc
+*xxhash.h

http://git-wip-us.apache.org/repos/asf/arrow/blob/b474cacf/cpp/build-support/run-clang-format.sh
----------------------------------------------------------------------
diff --git a/cpp/build-support/run-clang-format.sh b/cpp/build-support/run-clang-format.sh
deleted file mode 100755
index ba525df..0000000
--- a/cpp/build-support/run-clang-format.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-# Runs clang format in the given directory
-# Arguments:
-#   $1 - Path to the source tree
-#   $2 - Path to the clang format binary
-#   $3 - Apply fixes (will raise an error if false and not there where changes)
-#   $ARGN - Files to run clang format on
-#
-SOURCE_DIR=$1
-shift
-CLANG_FORMAT=$1
-shift
-APPLY_FIXES=$1
-shift
-
-# clang format will only find its configuration if we are in 
-# the source tree or in a path relative to the source tree
-pushd $SOURCE_DIR
-if [ "$APPLY_FIXES" == "1" ]; then
-  $CLANG_FORMAT -i $@
-else
-
-  NUM_CORRECTIONS=`$CLANG_FORMAT -output-replacements-xml  $@ | grep offset | wc -l`
-  if [ "$NUM_CORRECTIONS" -gt "0" ]; then
-    echo "clang-format suggested changes, please run 'make format'!!!!"
-    exit 1
-  fi
-fi 
-popd

http://git-wip-us.apache.org/repos/asf/arrow/blob/b474cacf/cpp/build-support/run_clang_format.py
----------------------------------------------------------------------
diff --git a/cpp/build-support/run_clang_format.py b/cpp/build-support/run_clang_format.py
new file mode 100755
index 0000000..ab800e6
--- /dev/null
+++ b/cpp/build-support/run_clang_format.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+# 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.
+
+import fnmatch
+import os
+import subprocess
+import sys
+
+if len(sys.argv) < 4:
+    sys.stderr.write("Usage: %s $CLANG_FORMAT_VERSION exclude_globs.txt "
+                     "$source_dir\n" %
+                     sys.argv[0])
+    sys.exit(1)
+
+CLANG_FORMAT = 'clang-format-{0}'.format(sys.argv[1])
+EXCLUDE_GLOBS_FILENAME = sys.argv[2]
+SOURCE_DIR = sys.argv[3]
+
+exclude_globs = [line.strip() for line in open(EXCLUDE_GLOBS_FILENAME, "r")]
+
+files_to_format = []
+matches = []
+for directory, subdirs, files in os.walk(SOURCE_DIR):
+    for name in files:
+        name = os.path.join(directory, name)
+        if not (name.endswith('.h') or name.endswith('.cc')):
+            continue
+
+        excluded = False
+        for g in exclude_globs:
+            if fnmatch.fnmatch(name, g):
+                excluded = True
+                break
+        if not excluded:
+            files_to_format.append(name)
+
+# TODO(wesm): Port this to work with Python, for check-format
+# NUM_CORRECTIONS=`$CLANG_FORMAT -output-replacements-xml  $@ |
+# grep offset | wc -l`
+# if [ "$NUM_CORRECTIONS" -gt "0" ]; then
+#   echo "clang-format suggested changes, please run 'make format'!!!!"
+#   exit 1
+# fi
+
+subprocess.check_output([CLANG_FORMAT, '-i'] + files_to_format,
+                        stderr=subprocess.STDOUT)

http://git-wip-us.apache.org/repos/asf/arrow/blob/b474cacf/dev/release/rat_exclude_files.txt
----------------------------------------------------------------------
diff --git a/dev/release/rat_exclude_files.txt b/dev/release/rat_exclude_files.txt
index 286793e..5a0b8a3 100644
--- a/dev/release/rat_exclude_files.txt
+++ b/dev/release/rat_exclude_files.txt
@@ -7,6 +7,7 @@ cpp/src/arrow/status.cc
 cpp/src/arrow/status.h
 cpp/build-support/asan_symbolize.py
 cpp/build-support/cpplint.py
+cpp/build-support/clang_format_exclusions.txt
 cpp/cmake_modules/BuildUtils.cmake
 cpp/cmake_modules/FindPythonLibsNew.cmake
 cpp/cmake_modules/FindNumPy.cmake


Mime
View raw message