8000 feature: clang-tidy&format by ObiWahn · Pull Request #10209 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

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
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
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 Oct 8, 2019
87570a8
make version selectable and add more search location
ObiWahn Oct 9, 2019
54ce5de
Add notes on what needs to be done to get clang-tidy/format
ObiWahn Oct 9, 2019
641e1dd
add script for formating touched files only
ObiWahn Oct 9, 2019
38b22b3
remove leftover from experiments
ObiWahn Oct 9, 2019
971ba6b
add script for clang tidy
ObiWahn Oct 9, 2019
5e61964
reduce checks done to basic checks
ObiWahn Oct 9, 2019
dd0b8d4
add script works on a diff
ObiWahn Oct 10, 2019
7cb37d4
run tidy on cpp files only
ObiWahn Oct 10, 2019
6b9b233
allow travis to run on test branch
ObiWahn Oct 10, 2019
6c5fb46
let clang-tidy be less verbose
ObiWahn Oct 10, 2019
a7e444a
prepare travis yaml
ObiWahn Oct 11, 2019
cb50c1a
try to run camke to get compile database
ObiWahn Oct 11, 2019
7f4fd0a
fix packages
ObiWahn Oct 11, 2019
258b7b5
add llvm tool chain
ObiWahn Oct 11, 2019
a69db53
add check script to travis
ObiWahn Oct 11, 2019
91ac241
try to swith to clang 9
ObiWahn Oct 11, 2019
91893eb
fix current directory before calling script
ObiWahn Oct 11, 2019
6bca460
change toolchain
ObiWahn Oct 11, 2019
e61eab5
try to make clang9 available
ObiWahn Oct 11, 2019
3865544
try to make it work with clang 6 - we hate travis
ObiWahn Oct 11, 2019
93da1ef
try again official mirror
ObiWahn Oct 11, 2019
d620df1
use llvm script
ObiWahn Oct 11, 2019
26a1309
select llvm versoin
ObiWahn Oct 11, 2019
80c5221
add tools
ObiWahn Oct 11, 2019
3445b73
last desperate tries
ObiWahn Oct 11, 2019
8381617
add sourceline
ObiWahn Oct 11, 2019
756b95e
get rid of clang-7
ObiWahn Oct 11, 2019
75d2fb8
list clang packages
ObiWahn Oct 11, 2019
221802c
how can clang 7 be used if it is not installed?
ObiWahn Oct 11, 2019
0a86b0a
show clang packages
ObiWahn Oct 11, 2019
fcabfda
another way to see the files
ObiWahn Oct 11, 2019
6041650
add format that is not part of tools
ObiWahn Oct 11, 2019
b49ecbb
remove debug lines
ObiWahn Oct 11, 2019
1e52aad
remove cmake step as we do not need it if we are not using tidy
ObiWahn Oct 11, 2019
c367fa1
break formatting and exit with 1 if there is a diff
ObiWahn Oct 11, 2019
27bd703
add colordiff and fix/break formatting
ObiWahn Oct 11, 2019
b5a75ad
diff against correct branch
ObiWahn Oct 11, 2019
b3009ed
add code that will enable the check for prs only
ObiWahn Oct 11, 2019
4d152a3
make it work for PR and non PR
ObiWahn Oct 11, 2019
087e704
fix formatting
ObiWahn Oct 11, 2019
8be3f31
run on all branches
ObiWahn Oct 12, 2019
42ee81f
add some quotes
ObiWahn Oct 14, 2019
c8e583f
Update utils/clang-tidy
ObiWahn Oct 15, 2019
f06b680
Update arangod/Aql/Query.cpp
ObiWahn Oct 15, 2019
4c102da
make it work outside of travis
ObiWahn Oct 15, 2019
723f850
use clang-format-diff instead of find
ObiWahn Oct 15, 2019
2345c5b
Merge branch 'feature/clang-tidy-format' of https://github.com/arango…
ObiWahn Oct 15, 2019
f4c7205
fix clang version so it matches what we have available in travis
ObiWahn Oct 15, 2019
04e90b7
fix clang-format-diff call
ObiWahn Oct 15, 2019
433ccfe
remove sudo
ObiWahn Oct 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 37 additions & 46 deletions .travis.yml
10000
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
18 changes: 18 additions & 0 deletions README_maintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -841,3 +841,21 @@ Currently available analyzers are:


./scripts/examine_results.js -- 'yaml,locateLongRunning' --readFile out/UNITTEST_RESULT.json

### Tooling

## clang-format / clang-tidy

You can get prebuild llvm/clang packages at:
http://releases.llvm.org/download.html

If you want to build the tools for yourself, because there are no packages for
your platform, then you need to clone
`https://github.com/llvm/llvm-project.git` and configure the build with a
command similar to the following.

```
cmake -G Ninja -DCMAKE_INSTALL_PREFIX=$HOME/.local -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" ../llvm-project/llvm/
ninja -j8
ninja install
```
1 change: 1 addition & 0 deletions compile_commands.json
76 changes: 76 additions & 0 deletions utils/clang-format-changed-only
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
set -u
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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


## 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

73 changes: 73 additions & 0 deletions utils/clang-format-check
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
48 changes: 48 additions & 0 deletions utils/clang-format-everything
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[@]}
49 changes: 49 additions & 0 deletions utils/clang-tidy
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}
Loading
0