Skip to content

Conversation

goldsborough
Copy link
Contributor

@goldsborough goldsborough commented Sep 30, 2018

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

.travis.yml Outdated

This comment was marked as off-topic.

This comment was marked as off-topic.

.travis.yml Outdated

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@ezyang
Copy link
Contributor

ezyang commented Oct 1, 2018

The job doesn't seem to be failing on errors. On https://travis-ci.org/pytorch/pytorch/jobs/435471449 I see:

1.33s$ python tools/clang_tidy.py -c "$(which clang-tidy-6.0)" -d clang-tidy-build -p torch/csrc -r HEAD~1
/home/travis/build/pytorch/pytorch/torch/csrc/jit/interned_strings.h:9:10: error: 'torch/csrc/jit/generated/aten_interned_strings.h' file not found [clang-diagnostic-error]
#include "torch/csrc/jit/generated/aten_interned_strings.h"

CMakeLists.txt Outdated

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

CONTRIBUTING.md Outdated

This comment was marked as off-topic.

This comment was marked as off-topic.

CONTRIBUTING.md Outdated

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@ezyang ezyang left a 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.

@goldsborough
Copy link
Contributor Author

What you're seeing are clang compiler errors (clang-diagnostic-error). Those are because I don't do a full build of PyTorch since that would take too long in CI. I only generate the .compile_commands.json and clang-tidy will happily lint 99% of code that it can parse and compile. The clang diagnostics can be ignored. It means we're not linting generated files, but I think that's fine. In any case, there is nothing broken here, it's expected. When there is an actual lint error (which I have verified of course), those will make the CI error.

@goldsborough
Copy link
Contributor Author

Now that I think of it, I can just run our gen.py script to generate the missing files. I also do that in our doc CI build. In any case the lint job will take 2 minutes and not 20 minutes or however long it takes to build PyTorch

@goldsborough goldsborough force-pushed the clang-tidy-ci branch 3 times, most recently from f94f3b9 to 5564d8c Compare October 1, 2018 17:12
CONTRIBUTING.md Outdated

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@ezyang
Copy link
Contributor

ezyang commented Oct 3, 2018

CR on clang_tidy.py

@ezyang ezyang closed this Oct 3, 2018
@ezyang ezyang reopened this Oct 3, 2018
@ezyang
Copy link
Contributor

ezyang commented Oct 3, 2018

(sorry, accidentally closed the PR with an incorrect comment, please disregard)

@ezyang
Copy link
Contributor

ezyang commented Oct 3, 2018

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
@goldsborough
Copy link
Contributor Author

goldsborough commented Oct 3, 2018

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

@goldsborough
Copy link
Contributor Author

No, please don't do this. If you pass the base directory, this will walk recursively into the build directory and .git and grab you all of your build products too. Even if you use it on a subdirectory, it will still grab any build products. Use git-ls-files to get an accurate listing of all files in Git which are checked into source control and can be profitably linted.

Why would you pass the base directory? This gets e.g. torch/csrc as its argument, that would certainly only include source files?

@ezyang
Copy link
Contributor

ezyang commented Oct 3, 2018

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.

That's fine, but then it should be commented in the code :)

Why would you pass the base directory? This gets e.g. torch/csrc as its argument, that would certainly only include source files?

I've seen too many programs written using os.walk (it worked fine on my machine!) blow up to be that sympathetic to this argument :) It should work without weird performance cliffs in all cases, or we shouldn't provide it at all.

@ezyang
Copy link
Contributor

ezyang commented Oct 3, 2018

In terms of priorities, the main things I want to see fixed are:

  • Removal of footguns from the Python script (this is mostly from the perspective of, this kind of Python code tends to replicate itself in the codebase if let alone for a while, and I don't want the footguns replicating themselves.)
  • Some resolution on the issue where clang-tidy will silently choke if compile commands are busted without erroring. I'm willing to be convinced this is not a problem in practice, but we've had multiple cases in the past where we silently stopped testing code and if there is something easy we can do now to prevent this from happening, I'd prefer it.

Everything else is non-essential.

@goldsborough goldsborough force-pushed the clang-tidy-ci branch 2 times, most recently from b979fea to 048e9bb Compare October 3, 2018 21:57
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants