[PATCH] D51729: [Tooling] JSONCompilationDatabasePlugin infers compile commands for missing files
Peter Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 6 04:54:14 PST 2018
Lekensteyn added a comment.
In https://reviews.llvm.org/D51729#1288360, @sammccall wrote:
> > I'm not entirely sure what to do here. The old behavior works great in cases where a complete database is available (produced by CMake). The new behavior might work better for clangd (?), but it breaks a use case (see above).
> For clangd, but also clang-tidy and clang-query when the user *does* want to use it on files not represented in the CDB. (e.g. stale or headers)
> There's indeed a tension here, because the CDB discovery needs to have a default configuration.
Support for querying header files seems valuable and a good argument to keep this change.
> That said, in this case the behavior looks appropriate to me: you've explicitly specified files on the command line, ignoring them and returning with status 0 seems surprising.
The test explicitly lists them, but in practice the `find` or `grep -rl` provides the file names which might contain uninteresting matches that are not present in the CDB. As a compromise, it could return with status 1 but proceed querying files that were successfully parsed.
> For the case of "search over all TUs in CDB", the CDB does offer the ability to list TUs and iterate over compile commands, and ClangTool lets you run in this mode. We've discussed in the past adding a filename filter to `AllTUsExecutor`, which would be useful for this purpose and others. @ioeric
`AllTUsToolExecutor` looks useful to enable concurrency, but a filename filter would not help in my case. The reason I do a "cheap" grep first before using clang-query is because building the AST is slow and consumes a lot of memory (after ~1k .c files, 12G was in use).
Querying the CDB and filtering out entries is currently possible, but quite verbose:
grep -le 'search term' $(jq -r '..file' compile_commands.json) | xargs clang-query -c 'm ...'
Thank you for the feedback, my concerns with this CDB patch has been resolved.
More information about the cfe-commits