[clang][ScanDeps] Fix issue with multiple commands with the same input.
authorMichael Spencer <bigcheesegs@gmail.com>
Wed, 30 Oct 2019 21:04:11 +0000 (14:04 -0700)
committerMichael Spencer <bigcheesegs@gmail.com>
Thu, 31 Oct 2019 21:22:01 +0000 (14:22 -0700)
commitd816d9bdc585bbf77a7a1c47a7199fd9e0c34402
tree2394fbb01b91de50f7bd7d7cb99884f2a8270a17
parent19f1dc7b527eade11dae9425c420cc9f450393b6
[clang][ScanDeps] Fix issue with multiple commands with the same input.

Previously, given a CompilationDatabase with two commands for the same
source file we would report that file twice with the union of the
dependencies for each command both times.

This was due to the way `ClangTool` runs actions given an input source
file (see the comment in `DependencyScanningTool.cpp`). This commit adds
a `SingleCommandCompilationDatabase` that is created with each
`CompileCommand` in the original CDB, which is then used for each
`ClangTool` invocation. This gives us a single run of
`DependencyScanningAction` per `CompileCommand`.

I looked at using `AllTUsToolExecutor` which is a parallel tool
executor, but I'm not sure it's suitable for `clang-scan-deps` as it
does a lot more sharing of state than `AllTUsToolExecutor` expects.

Differential Revision: https://reviews.llvm.org/D69643
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
clang/test/ClangScanDeps/Inputs/regular_cdb.json
clang/test/ClangScanDeps/error.cpp
clang/test/ClangScanDeps/regular_cdb.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp