-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Enable clang-tidy in CI #12213
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
Enable clang-tidy in CI #12213
Conversation
8cd3ee4
to
56e25cc
Compare
@@ -29,3 +29,18 @@ matrix: | |||
- env: CPP_DOC_CHECK | |||
install: sudo apt-get install -y doxygen | |||
script: cd docs/cpp/source && ./check-doxygen.sh | |||
- env: CLANG_TIDY |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
.travis.yml
Outdated
- git submodule update --init --recursive | ||
- mkdir clang-tidy-build | ||
- cd clang-tidy-build | ||
- cmake -DBUILD_TORCH=ON .. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
The job doesn't seem to be failing on errors. On https://travis-ci.org/pytorch/pytorch/jobs/435471449 I see:
|
@@ -10,6 +10,8 @@ if (NOT MSVC) | |||
set(CMAKE_C_STANDARD 11) | |||
endif() | |||
|
|||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
CONTRIBUTING.md
Outdated
how to install the latest version. Note that newer versions of clang-tidy will | ||
have more checks than older versions. In our CI, we run clang-tidy-6.0. | ||
|
||
2. Use our driver script to run clang-tidy over your git revision (you may want |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
$ python tools/clang_tidy.py -d /path/to/build/ -p torch/csrc -r HEAD~1 | ||
``` | ||
|
||
Above, it is assumed you are in the PyTorch root folder. `path/to/build` should |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
// NB: Must be at the top of file to avoid including the deprecated "math.h". | ||
// https://stackoverflow.com/questions/6563810/m-pi-works-with-math-h-but-not-with-cmath-in-visual-studio | ||
#ifdef _MSC_VER | ||
#define _USE_MATH_DEFINES |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
tools/clang_tidy.py
Outdated
@@ -8,28 +8,35 @@ | |||
import sys | |||
|
|||
|
|||
DEFAULT_FILE_PATTERN = r".*\.[ch](pp)?" | |||
DEFAULT_FILE_PATTERN = r".*\.c(c|pp)?" |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
"""Executes a shell command.""" | ||
assert len(arguments) > 0 | ||
try: | ||
output = subprocess.check_output(arguments, stderr=subprocess.STDOUT) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@@ -7,6 +7,7 @@ else() | |||
project(torch CXX C) | |||
find_package(Caffe2 REQUIRED) | |||
option(USE_CUDA "Use CUDA" ON) | |||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
tools/clang_tidy.py
Outdated
output = subprocess.check_output(arguments, stderr=subprocess.STDOUT) | ||
except OSError: | ||
_, e, _ = sys.exc_info() | ||
if verbose: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
tools/clang_tidy.py
Outdated
process_name = process_name or arguments[0] | ||
raise RuntimeError("Error executing {}: {}".format(process_name, e)) | ||
_, error, _ = sys.exc_info() | ||
message = "Error executing '{}'".format(process_name) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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 quibbles about how the Python script is written, but I'm requesting changes here because it doesn't seem like it is actually flagging errors as failures in CI.
What you're seeing are clang compiler errors ( |
Now that I think of it, I can just run our |
f94f3b9
to
5564d8c
Compare
should be able to install it easily with your package manager, e.g. by writing | ||
`apt-get install clang-tidy` on Ubuntu. See https://apt.llvm.org for details on | ||
how to install the latest version. Note that newer versions of clang-tidy will | ||
have more checks than older versions. In our CI, we run clang-tidy-6.0. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
||
set -ex | ||
|
||
if [[ ! -d build ]]; then |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
popd | ||
|
||
# Generate ATen files. | ||
time python aten/src/ATen/gen.py \ |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@@ -8,28 +8,35 @@ | |||
import sys |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
CR on
|
(sorry, accidentally closed the PR with an incorrect comment, please disregard) |
Message me if you want to chat more about the verbose output situation. I want to understand what's going on here. |
Move code into script
Hard to respond to your comments directly this way. I'll fix the code you commented on. I think the only open ended question was "why pass the .yaml file to clang-tidy". Believe me, I've spent many hours fighting clang tidy because it wouldn't pick up my .clang-tidy file. It seems a thing about different clang tidy versions. There's unanswered stackoverflow questions about this too. The best way to ensure that all the config gets picked up is to pass it in directly the way I do. I'll see how hard it is to create a cmake target to generate the files. I think it's more important to have clang tidy in CI as soon as possible than for this to be 100% clean. We could literally already be finding tons of bugs right now |
Why would you pass the base directory? This gets e.g. |
That's fine, but then it should be commented in the code :)
I've seen too many programs written using |
In terms of priorities, the main things I want to see fixed are:
Everything else is non-essential. |
b979fea
to
048e9bb
Compare
048e9bb
to
e38318e
Compare
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.
goldsborough has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
At long last, we will have clang-tidy enabled in CI. For a while I thought I could clean up the project enough to enable clang-tidy with all checks enabled, but I figure it's smarter to set up the minimal checks and at least have those in CI. We can fix more going forward.
@ezyang @apaszke