-
Notifications
You must be signed in to change notification settings - Fork 853
feature: clang-tidy&format #10209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
feature: clang-tidy&format #10209
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
5c88149
add new format script
ObiWahn 87570a8
make version selectable and add more search location
ObiWahn 54ce5de
Add notes on what needs to be done to get clang-tidy/format
ObiWahn 641e1dd
add script for formating touched files only
ObiWahn 38b22b3
remove leftover from experiments
ObiWahn 971ba6b
add script for clang tidy
ObiWahn 5e61964
reduce checks done to basic checks
ObiWahn dd0b8d4
add script works on a diff
ObiWahn 7cb37d4
run tidy on cpp files only
ObiWahn 6b9b233
allow travis to run on test branch
ObiWahn 6c5fb46
let clang-tidy be less verbose
ObiWahn a7e444a
prepare travis yaml
ObiWahn cb50c1a
try to run camke to get compile database
ObiWahn 7f4fd0a
fix packages
ObiWahn 258b7b5
add llvm tool chain
ObiWahn a69db53
add check script to travis
ObiWahn 91ac241
try to swith to clang 9
ObiWahn 91893eb
fix current directory before calling script
ObiWahn 6bca460
change toolchain
ObiWahn e61eab5
try to make clang9 available
ObiWahn 3865544
try to make it work with clang 6 - we hate travis
ObiWahn 93da1ef
try again official mirror
ObiWahn d620df1
use llvm script
ObiWahn 26a1309
select llvm versoin
ObiWahn 80c5221
add tools
ObiWahn 3445b73
last desperate tries
ObiWahn 8381617
add sourceline
ObiWahn 756b95e
get rid of clang-7
ObiWahn 75d2fb8
list clang packages
ObiWahn 221802c
how can clang 7 be used if it is not installed?
ObiWahn 0a86b0a
show clang packages
ObiWahn fcabfda
another way to see the files
ObiWahn 6041650
add format that is not part of tools
ObiWahn b49ecbb
remove debug lines
ObiWahn 1e52aad
remove cmake step as we do not need it if we are not using tidy
ObiWahn c367fa1
break formatting and exit with 1 if there is a diff
ObiWahn 27bd703
add colordiff and fix/break formatting
ObiWahn b5a75ad
diff against correct branch
ObiWahn b3009ed
add code that will enable the check for prs only
ObiWahn 4d152a3
make it work for PR and non PR
ObiWahn 087e704
fix formatting
ObiWahn 8be3f31
run on all branches
ObiWahn 42ee81f
add some quotes
ObiWahn c8e583f
Update utils/clang-tidy
ObiWahn f06b680
Update arangod/Aql/Query.cpp
ObiWahn 4c102da
make it work outside of travis
ObiWahn 723f850
use clang-format-diff instead of find
ObiWahn 2345c5b
Merge branch 'feature/clang-tidy-format' of https://github.com/arango…
ObiWahn f4c7205
fix clang version so it matches what we have available in travis
ObiWahn 04e90b7
fix clang-format-diff call
ObiWahn 433ccfe
remove sudo
ObiWahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,44 @@ | ||
branches: | ||
only: | ||
- master | ||
- devel | ||
- "1.4" | ||
- "2.3" | ||
- "2.4" | ||
- "2.5" | ||
- "2.6" | ||
- "2.7" | ||
- "2.8" | ||
- "3.0" | ||
- "3.1" | ||
- "3.2" | ||
#branches: | ||
# only: | ||
# - master | ||
# - devel | ||
# - feature/clang-tidy-format | ||
|
||
language: cpp | ||
cache: ccache | ||
compiler: g++ | ||
sudo: false | ||
dist: trusty | ||
#cache: ccache | ||
|
||
addons: | ||
apt: | ||
sources: | ||
- ubuntu-toolchain-r-test | ||
- george-edison55-trusty-backports | ||
packages: | ||
- g++-5 | ||
- gcc-5 | ||
- binutils-gold | ||
- gdb | ||
- cmake-data | ||
- cmake | ||
#see https://apt.llvm.org/ | ||
matrix: | ||
include: | ||
- name: "clang-format" | ||
compiler: clang++-9 | ||
addons: | ||
apt: | ||
sources: | ||
- [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-xenial-8'] | ||
- sourceline: 'deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main' | ||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key" | ||
packages: [ 'clang-9', 'clang-tools-9', 'clang-tidy-9', 'clang-format-9', 'colordiff'] | ||
env: | ||
- MATRIX_ENV="export CXX=clang++-9 CC=clang-9" | ||
|
||
before_install: | ||
install: | ||
before_script: | ||
# we need this only to create the compilation databse for clang tidy | ||
# - eval "${MATRIX_ENV}" | ||
# - mkdir build && cd build || exit 1 | ||
# - cmake .. | ||
# - cd .. | ||
script: | ||
- ./utils/clang-format-check | ||
|
||
# prepare environment | ||
- export PATH="$HOME/bin:$PATH" | ||
- export CC="$HOME/bin/gcc" | ||
- export CXX="$HOME/bin/g++" | ||
- export CFLAGS="-B$HOME/bin/gold $CFLAGS" | ||
- export CXXFLAGS="-B$HOME/bin/gold $CXXFLAGS" | ||
after_suceess: | ||
after_failure: | ||
after_script: | ||
|
||
before_script: "bash -c Installation/travisCI/before_script.sh" | ||
script: "bash -c Installation/travisCI/build.sh" | ||
after_failure: "bash -c Installation/travisCI/after_failure.sh" | ||
after_script: "bash -c Installation/travisCI/after_script.sh" | ||
|
||
notifications: | ||
slack: | ||
secure: JrnDfdroyURrS85HIVsI4xw82taol+lvOJxduxz4T8mQuckaE3ECRYcxX7MzLJfjpeSLST5kttUiZBckHdZ/pnmraZlQ+1/b1VE6k5hFzkbeM0ShjXKTxHdudXaJKuENunMxDAjVWaBaTTh/iy8ZZbKUYQtWLtLfw3xa5zCKVaQ= | ||
on_success: change | ||
on_failure: always | ||
#notifications: | ||
# slack: | ||
# secure: JrnDfdroyURrS85HIVsI4xw82taol+lvOJxduxz4T8mQuckaE3ECRYcxX7MzLJfjpeSLST5kttUiZBckHdZ/pnmraZlQ+1/b1VE6k5hFzkbeM0ShjXKTxHdudXaJKuENunMxDAjVWaBaTTh/iy8ZZbKUYQtWLtLfw3xa5zCKVaQ= | ||
# on_success: change | ||
# on_failure: always |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/compile_commands.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env bash | ||
set -u | ||
|
||
## locate executable | ||
clang_format="${ARANGODB_CLANG_FORMAT:-""}" | ||
clang_format_version="${ARANGODB_CLANG_FORMAT_VERSION:-"6.0.1"}" | ||
|
||
# fallback if nothing is found | ||
if [[ -z $clang_format ]]; then | ||
for candidate in "$HOME/.local/bin/clang-format" "clang-format-arangodb" "clang-format-6" "clang-format"; do | ||
echo "checking candidate $candidate" | ||
path="$(type -p "${candidate}")" | ||
if [[ -n $path ]]; then | ||
clang_format="$path" | ||
echo "selecting this candidate" | ||
break; | ||
fi | ||
done | ||
else | ||
echo "clang-format provided by environment" | ||
fi | ||
|
||
# fallback if nothing is found | ||
if [[ -z $clang_format ]]; then | ||
echo "using fallback" | ||
clang_format="clang-format" | ||
fi | ||
|
||
## check version | ||
echo "checking version of $clang_format" | ||
version_string=$(${clang_format} --version) | ||
re=".*version ${clang_format_version}.*" | ||
if ! [[ $version_string =~ $re ]]; then | ||
echo "your version: '$version_string' does not match version 6.0.1" | ||
exit 1 | ||
fi | ||
|
||
|
||
diff="$(git diff -U0 --no-color)" | ||
# do final formatting | ||
${clang_format} -i -verbose -style=file ${files_final[@]} | ||
command=( | ||
"${bash_source_dir}/lib/clang-format-diff.py" | ||
--verbose | ||
-i | ||
-binary "${clang_format}" | ||
-style=file | ||
-regex '(lib|tests|arangod)/.*' | ||
-p1 | ||
) | ||
|
||
echo "${command[@]}" | ||
"${command[@]}" <<<"$diff" | ||
|
||
## keep this for now | ||
# ## find relevant files | ||
# files="$( | ||
# find arangod arangosh lib enterprise \ | ||
# -name Zip -prune -o \ | ||
# -type f "(" -name "*.cpp" -o -name "*.h" ")" \ | ||
# "!" "(" -name "tokens.*" -o -name "v8-json.*" -o -name "voc-errors.*" -o -name "grammar.*" -o -name "xxhash.*" -o -name "exitcodes.*" ")" | ||
# )" | ||
# | ||
# git_files=$(gi 741A t diff --name-only) | ||
# files_final=() | ||
# for gf in ${git_files[@]}; do | ||
# echo "---------------------" | ||
# for f in ${files[@]}; do | ||
# echo "$gf -- $f" | ||
# if [[ $gf == "$f" ]]; then | ||
# files_final+=( "$f" ) | ||
# continue | ||
# fi | ||
# done | ||
# done | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env bash | ||
set -u | ||
|
||
# Make any failure in piped commands be reflected in the exit code. | ||
set -o pipefail | ||
|
||
diff_target="${1:-HEAD}" | ||
TRAVIS=${TRAVIS:-false} | ||
|
||
readonly bash_source_dir="$(dirname $(readlink -f ${BASH_SOURCE[0]}))" | ||
readonly project_dir="$(readlink -f $(dirname $(readlink -f ${BASH_SOURCE[0]}))/..)" | ||
|
||
## locate executable | ||
readonly clang_format_version="${ARANGODB_CLANG_FORMAT_VERSION:-"9.0.1"}" | ||
clang_format="${ARANGODB_CLANG_FORMAT:-""}" | ||
|
||
# fallback if nothing is found | ||
if [[ -z $clang_format ]]; then | ||
for candidate in "$HOME/.local/bin/clang-format" "clang-format-arangodb" "clang-format-9" "clang-format"; do | ||
echo "checking candidate $candidate" | ||
path="$(type -p "${candidate}")" | ||
if [[ -n $path ]]; then | ||
clang_format="$path" | ||
echo "selecting this candidate" | ||
break; | ||
fi | ||
done | ||
else | ||
echo "clang-format provided by environment" | ||
fi | ||
|
||
# fallback if nothing is found | ||
if [[ -z $clang_format ]]; then | ||
echo "using fallback" | ||
clang_format="clang-format" | ||
fi | ||
|
||
## check version | ||
echo "checking version of $clang_format" | ||
version_string=$(${clang_format} --version) | ||
re=".*version ${clang_format_version}.*" | ||
if ! [[ $version_string =~ $re ]]; then | ||
echo "your version: '$version_string' does not match version regular expression '$re'" | ||
exit 1 | ||
fi | ||
|
||
if $TRAVIS; then | ||
diff_target="${TRAVIS_BRANCH}" | ||
if ! $TRAVIS_PULL_REQUEST; then | ||
diff_target="${diff_target}^" | ||
fi | ||
echo "diffing against ${diff_target}" | ||
fi | ||
|
||
diff="$(git diff -U0 --no-color "${diff_target}" )" | ||
|
||
#-regex "'${project_dir}"'/(lib|tests|arangod).*'"'" | ||
command=( | ||
"${bash_source_dir}/lib/clang-format-diff.py" | ||
--verbose | ||
-binary "${clang_format}" | ||
-style=file | ||
-regex '(lib|tests|arangod)/.*' | ||
-p1 | ||
) | ||
|
||
echo "${command[@]}" | ||
if type colordiff 2>/dev/null; then | ||
#need pipefail option | ||
"${command[@]}" <<<"$diff" | colordiff -u3 | ||
else | ||
"${command[@]}" <<<"$diff" | ||
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bash | ||
set -u | ||
|
||
## locate executable | ||
clang_format="${ARANGODB_CLANG_FORMAT:-""}" | ||
clang_format_version="${ARANGODB_CLANG_FORMAT_VERSION:-"6.0.1"}" | ||
|
||
# fallback if nothing is found | ||
if [[ -z $clang_format ]]; then | ||
for candidate in "$HOME/.local/bin/clang-format" "clang-format-arangodb" "clang-format-6" "clang-format"; do | ||
echo "checking candidate $candidate" | ||
path="$(type -p "${candidate}")" | ||
if [[ -n $path ]]; then | ||
clang_format="$path" | ||
echo "selecting this candidate" | ||
break; | ||
fi | ||
done | ||
else | ||
echo "clang-format provided by environment" | ||
fi | ||
|
||
# fallback if nothing is found | ||
if [[ -z $clang_format ]]; then | ||
echo "using fallback" | ||
clang_format="clang-format" | ||
fi | ||
|
||
## check version | ||
echo "checking version of $clang_format" | ||
version_string=$(${clang_format} --version) | ||
re=".*version ${clang_format_version}.*" | ||
if ! [[ $version_string =~ $re ]]; then | ||
echo "your version: '$version_string' does not match version 6.0.1" | ||
exit 1 | ||
fi | ||
|
||
|
||
## find relevant files | ||
files="$( | ||
find arangod arangosh lib enterprise \ | ||
-name Zip -prune -o \ | ||
-type f "(" -name "*.cpp" -o -name "*.h" ")" \ | ||
"!" "(" -name "tokens.*" -o -name "v8-json.*" -o -name "voc-errors.*" -o -name "grammar.*" -o -name "xxhash.*" -o -name "exitcodes.*" ")" | ||
)" | ||
|
||
# do final formatting | ||
${clang_format} -i -verbose -style=file ${files[@]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
#!/usr/bin/env bash | ||
set -u | ||
|
||
## locate executable | ||
clang_tidy="${ARANGODB_CLANG_TIDY:-""}" | ||
clang_tidy_version="${ARANGODB_CLANG_TIDY_VERSION:-"9.0.0"}" | ||
|
||
# fallback if nothing is found | ||
if [[ -z $clang_tidy ]]; then | ||
for candidate in "$HOME/.local/bin/clang-tidy" "clang-tidy-arangodb" "clang-tidy-9" "clang-tidy"; do | ||
echo "checking candidate $candidate" | ||
path="$(type -p "${candidate}")" | ||
if [[ -n $path ]]; then | ||
clang_tidy="$path" | ||
echo "selecting this candidate" | ||
break; | ||
fi | ||
done | ||
else | ||
echo "clang-tidy provided by environment" | ||
fi | ||
|
||
# fallback if nothing is found | ||
if [[ -z $clang_tidy ]]; then | ||
echo "using fallback" | ||
clang_tidy="clang-tidy" | ||
fi | ||
|
||
## check version | ||
echo "checking version of $clang_tidy" | ||
version_string=$(${clang_tidy} --version) | ||
re=".*version ${clang_tidy_version}.*" | ||
if ! [[ $version_string =~ $re ]]; then | ||
echo "your version: '$version_string' does not match version 6.0.1" | ||
exit 1 | ||
fi | ||
|
||
## find relevant files | ||
#-type f "(" -name "*.cpp" -o -name "*.h" ")" \ | ||
files="$( | ||
find arangod arangosh lib enterprise \ | ||
-name Zip -prune -o \ | ||
-type f "(" -name "*.cpp" ")" \ | ||
"!" "(" -name "tokens.*" -o -name "v8-json.*" -o -name "voc-errors.*" -o -name "grammar.*" -o -name "xxhash.*" -o -name "exitcodes.*" ")" | ||
)" | ||
|
||
${clang_tidy} --quiet --checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* ${files} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this like clang-format-diff ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - This checks the clang version to be used.
But instead of using the logic provided by franks awesome find command one could have come up with some regular expression for clang-format-diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the script to use clang-format-diff