Added builddir option to clang-tidy to point to json folder#688
Conversation
|
It would be better to search for this automatically with a list of names for the build directory, which can be changed with an option. Set the option to |
|
If I run CMake in the build dir and have CMAKE_EXPORT_COMPILE_COMMANDS on,
then the json is directly in the build folder and not in a bin
subdirectory. Maybe just searching upwards for build folder and then just
check for an existing compilé_commands.json ? That would mean using only 1
string for the option
Le 23 juin 2017 16:47, "w0rp" <notifications@github.com> a écrit :
… It would be better to search for this automatically with a list of names
for the build directory, which can be changed with an option. Set the
option to ['bin', 'build'] by default, and search upwards through
directories to find 'bin/compile_commands.json'.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#688 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AKAoo1HkaDvtnareS3VQyBvaikXpx4Prks5sG9AFgaJpZM4ODqGP>
.
|
|
In that case, just use |
|
I have one example case to illustrate why I finally wasn't able to work out a solution with
Therefore I feel like the quicker solution to this problem would be to give directly the build directory as an option. But I agree that I could :
And have that as a default behaviour if the option is not set. |
It allows looking for specific names in the project tree. Setting a default value for this option means clang-tidy should work out of the box for most "out-of-source build" projects. Overriding either this value or the builddir option allows to finely control the expected location of compile_commands.json
Since the build folder is found upwards from current directory the returned path for the linter is absolute, and it needs to be adjusted to follow Travis architecture.
|
I finally got over my dumbness and implemented the behaviour mentioned earlier :
The method relies on |
w0rp
left a comment
There was a problem hiding this comment.
Nice. This is looking better. My hope is that with the right list of default names, it will work automatically for the majority of projects.
| if empty(l:user_builddir) | ||
| let l:builddir_names = ale#Var(a:buffer, 'cpp_clangtidy_builddirnames') | ||
| for l:name in l:builddir_names | ||
| let l:candidates = finddir(l:name, expand('#' . a:buffer.':p:h') . ';', -1) |
There was a problem hiding this comment.
Have a look at the implementation of ale#python#FindVirtualenv. You can use the ale#path#Upwards function with the isdirectory function for implementing this. I suggest implementing this as a ale#c#FindCompileCommands function. It could be useful for other tools.
| " Build directory has the priority if | ||
| " both builddir and builddirnames options are defined | ||
| if empty(l:user_builddir) | ||
| let l:builddir_names = ale#Var(a:buffer, 'cpp_clangtidy_builddirnames') |
There was a problem hiding this comment.
I recommend calling this variable ale_c_build_dir_names. It can be used for a few C and C++ tools, and that name will match the ale_virtualenv_dir_names variable name.
There was a problem hiding this comment.
I agree that this variable should be shared betwwen c-family linters, I wasn't sure about how to do it, I'll look into this
| let l:extra_options = !empty(l:user_options) | ||
| \ ? ' -- ' . l:user_options | ||
| \ : '' | ||
| let l:user_builddir = ale#Var(a:buffer, 'cpp_clangtidy_builddir') |
There was a problem hiding this comment.
I'm not sure if this one should be left as-is, or should be named c_build_dir, or maybe cpp_build_dir. I think leave it for now.
| " flags are contained in the json | ||
| let g:ale_cpp_clangtidy_builddir = get(g:, 'ale_cpp_clangtidy_builddir', '') | ||
|
|
||
| let g:ale_cpp_clangtidy_builddirnames = |
There was a problem hiding this comment.
You can initialize this in autoload/ale/c.vim with the function below.
|
|
||
| AssertEqual | ||
| \ 'clang-tidy -checks=''*'' %s -p ''/testplugin/test/test_c_projects/json_project/build''' | ||
| \ , ale_linters#cpp#clangtidy#GetCommand(bufnr('')) |
The goal is to use the same variables for all C-family linters
It implies using the new autoload/ale/c.vim file, and cleaning up variable names to be less linter-specific and more language-specific
Calling only ale#Var is bad, since we need to look at least once in ale#c autoload file in order to load the relevant global variable
Removed the trailing /, as it is taken into account in ale#c#FindCompileCommands by looking for `/compile_commands.json` in each candidate folder
|
I'm so bad with these tests it's incredible. Well, I've done the changes as proposed. It looks better this way indeed.
Then a discussion can be started on the right choice of EDIT : And arguably a new test file should be done to test the features of |
|
Yeah, you can document the option like the Python virtualenv option. |
w0rp
left a comment
There was a problem hiding this comment.
Looks good. 👍 I'll wait for the option documentation.
|
Cheers! 🍻 |
|
Yay ! Last step is to actually add a test for autoload/ale/c.vim, but I'll look into this a little later, for the time being the behaviour to test is actually exactly the same as in FindVirtualEnv in python projects |
Related to #392 but does not fix it (it only gives clang-tidy the possibility to read properly compilation db in order to find all includes)
Clangtidy linter currently deactivates the look for json compilation databases if the option cpp_clangtidy_options is set to a non-empty string. This is problematic when the only option we want to pass to clangtidy is actually a compilation database.
To compensate for this, another option is added to clangtidy linter, named
ale_cpp_clangtidy_builddirthat specifically only takes the path to the build directory. Setting this option will nullify all otherale_cpp_clangtidy_optionsset, since finding a compilation database means we have all the compilation flags we care about. (Also this behaviour means we can have default flags in the vimrc, that will be overwritten by compilation db flags for the specific projects/folders that do support it).Only the vader test is missing, the only fringe case I can imagine is to verify that when both sets, clang-tidy effectively takes the builddir option. I'll look into vader folder to try and implement the test.