[
https://issues.apache.org/jira/browse/ARROW-1728?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16222465#comment-16222465
]
ASF GitHub Bot commented on ARROW-1728:
---------------------------------------
wesm closed pull request #1251: ARROW-1728: [C++] Run clang-format checks in
Travis CI
URL: https://github.com/apache/arrow/pull/1251
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/.travis.yml b/.travis.yml
index c682a9d9d..039ae9520 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -56,6 +56,8 @@ matrix:
- export ARROW_TRAVIS_USE_TOOLCHAIN=1
- export ARROW_TRAVIS_VALGRIND=1
- export ARROW_TRAVIS_PLASMA=1
+ - export ARROW_TRAVIS_CLANG_FORMAT=1
+ - $TRAVIS_BUILD_DIR/ci/travis_install_clang_tools.sh
- $TRAVIS_BUILD_DIR/ci/travis_lint.sh
- $TRAVIS_BUILD_DIR/ci/travis_before_script_cpp.sh
script:
diff --git a/ci/travis_install_clang_tools.sh b/ci/travis_install_clang_tools.sh
old mode 100644
new mode 100755
diff --git a/ci/travis_lint.sh b/ci/travis_lint.sh
index 8c956646c..e234b7b01 100755
--- a/ci/travis_lint.sh
+++ b/ci/travis_lint.sh
@@ -26,6 +26,10 @@ pushd $TRAVIS_BUILD_DIR/cpp/lint
cmake ..
make lint
+if [ "$ARROW_TRAVIS_CLANG_FORMAT" == "1" ]; then
+ make check-format
+fi
+
popd
# Fail fast on style checks
diff --git a/ci/travis_script_cpp.sh b/ci/travis_script_cpp.sh
index a2079036c..3d61bc5b8 100755
--- a/ci/travis_script_cpp.sh
+++ b/ci/travis_script_cpp.sh
@@ -27,14 +27,6 @@ git archive HEAD --prefix=apache-arrow/
--output=arrow-src.tar.gz
pushd $CPP_BUILD_DIR
-# ARROW-209: checks depending on the LLVM toolchain are disabled temporarily
-# until we are able to install the full LLVM toolchain in Travis CI again
-
-# if [ $TRAVIS_OS_NAME == "linux" ]; then
-# make check-format
-# make check-clang-tidy
-# fi
-
ctest -VV -L unittest
popd
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index a159b1e56..d8dc5df88 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -446,10 +446,10 @@ add_custom_target(format
${BUILD_SUPPORT_DIR}/run_clang_format.py
# 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)
+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
diff --git a/cpp/build-support/run_clang_format.py
b/cpp/build-support/run_clang_format.py
index f1a448f53..fcf39ecc6 100755
--- a/cpp/build-support/run_clang_format.py
+++ b/cpp/build-support/run_clang_format.py
@@ -31,6 +31,12 @@
EXCLUDE_GLOBS_FILENAME = sys.argv[2]
SOURCE_DIR = sys.argv[3]
+if len(sys.argv) > 4:
+ CHECK_FORMAT = int(sys.argv[4]) == 1
+else:
+ CHECK_FORMAT = False
+
+
exclude_globs = [line.strip() for line in open(EXCLUDE_GLOBS_FILENAME, "r")]
files_to_format = []
@@ -49,18 +55,24 @@
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
+if CHECK_FORMAT:
+ output = subprocess.check_output([CLANG_FORMAT, '-output-replacements-xml']
+ + files_to_format,
+ stderr=subprocess.STDOUT).decode('utf8')
+
+ to_fix = []
+ for line in output.split('\n'):
+ if 'offset' in line:
+ to_fix.append(line)
-try:
- cmd = [CLANG_FORMAT, '-i'] + files_to_format
- subprocess.check_output(cmd, stderr=subprocess.STDOUT)
-except Exception as e:
- print(e)
- print(' '.join(cmd))
- raise
+ if len(to_fix) > 0:
+ print("clang-format checks failed, run 'make format' to fix")
+ sys.exit(-1)
+else:
+ try:
+ cmd = [CLANG_FORMAT, '-i'] + files_to_format
+ subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+ except Exception as e:
+ print(e)
+ print(' '.join(cmd))
+ raise
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> [C++] Run clang-format checks in Travis CI
> ------------------------------------------
>
> Key: ARROW-1728
> URL: https://issues.apache.org/jira/browse/ARROW-1728
> Project: Apache Arrow
> Issue Type: Improvement
> Components: C++
> Reporter: Wes McKinney
> Assignee: Wes McKinney
> Labels: pull-request-available
> Fix For: 0.8.0
>
>
> I think it's reasonable to expect contributors to run clang-format on their
> code. This may lead to a higher number of failed builds but will eliminate
> noise diffs in unrelated patches
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)