[PATCH] D137534: [C++20] [Modules] [ClangScanDeps] Allow clang-scan-deps to without specified compilation database in P1689 (3/4)

Ben Boeckel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 22 18:56:48 PST 2022


ben.boeckel added a comment.

In D137534#4014571 <https://reviews.llvm.org/D137534#4014571>, @ChuanqiXu wrote:

>> Why is it necessary to add new command-line flags for this? Can't the input and output be inherited from the specified Clang command line? Would such command line make sense?
>
> CMake wants to query the dependency information for a single file from time to time due to its current structure. And according to @ben.boeckel , the compilation database can't do very well for the files which don't exist during the configuration time. (Maybe @ben.boeckel can add some additional information).

A special compilation database would be required for scanning because the "real" command lines have `@rspfile` which CMake writes *during the build* with module dependency information (where to put the `.pcm` from this compile and where anything imported actually lives). Since this file is non-existent in a fresh build and potentially out-of-date after that, CMake would need to write a compilation database just for scanning purposes. Note that this would mean that any change to any command line would necessitate scanning *all* TUs sharing that database because none of them know if their command line is the one that changed. I feel this is a pessimization in the general case (batch scanning may be better for scratch builds, but measurements need to be made).

> For the reason why we need `--p1689-targeted-file-name` and  `--p1689-targeted-output` is that `FixedCompilationDatabase` wouldn't generate the input and output entry from the command line. See the inline comments for example. I feel it is easier and simpler to add 2 flags for it. I add the prefix `-p1689` to tell all other users to not use it unintentionally.

My GCC patch names it `-fdepfile-output=` instead of `--p1689-targeted-output`, gets `--p1689-targeted-file-name` from the regular command line (it looks like a preprocessor command overall) and the `--p1689-makeformat-output` flag is handled by the normal `-MT` and `-MF` flags. While I'm not thrilled with the P1689 <https://reviews.llvm.org/P1689> naming in the flags (as it'll become P2222 <https://reviews.llvm.org/P2222> once the TR it's heading for is accepted, aliases should be simple to maintain. My GCC patch uses `-fdep-format=p1689r5` so a rename there is easier than a whole flag name. But I suspect that `clang-scan-deps` is much more of a "tooling's tool" than something people type out by hand, so it's probably not a big deal?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137534/new/

https://reviews.llvm.org/D137534



More information about the cfe-commits mailing list