diff options
| author | Michael Spencer <bigcheesegs@gmail.com> | 2019-10-30 14:04:11 -0700 | 
|---|---|---|
| committer | Michael Spencer <bigcheesegs@gmail.com> | 2019-10-31 14:22:01 -0700 | 
| commit | d816d9bdc585bbf77a7a1c47a7199fd9e0c34402 (patch) | |
| tree | 2394fbb01b91de50f7bd7d7cb99884f2a8270a17 /clang/lib | |
| parent | 19f1dc7b527eade11dae9425c420cc9f450393b6 (diff) | |
| download | bcm5719-llvm-d816d9bdc585bbf77a7a1c47a7199fd9e0c34402.tar.gz bcm5719-llvm-d816d9bdc585bbf77a7a1c47a7199fd9e0c34402.zip  | |
[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
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp | 20 | 
1 files changed, 14 insertions, 6 deletions
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp index 4b10f24167a..f643c538f8f 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp @@ -23,14 +23,12 @@ namespace tooling{  namespace dependencies{  DependencyScanningTool::DependencyScanningTool( -    DependencyScanningService &Service, -    const tooling::CompilationDatabase &Compilations) -    : Format(Service.getFormat()), Worker(Service), Compilations(Compilations) { +    DependencyScanningService &Service) +    : Format(Service.getFormat()), Worker(Service) {  } -llvm::Expected<std::string> -DependencyScanningTool::getDependencyFile(const std::string &Input, -                                          StringRef CWD) { +llvm::Expected<std::string> DependencyScanningTool::getDependencyFile( +    const tooling::CompilationDatabase &Compilations, StringRef CWD) {    /// Prints out all of the gathered dependencies into a string.    class MakeDependencyPrinterConsumer : public DependencyConsumer {    public: @@ -140,6 +138,16 @@ DependencyScanningTool::getDependencyFile(const std::string &Input,      std::string ContextHash;    }; +   +  // We expect a single command here because if a source file occurs multiple +  // times in the original CDB, then `computeDependencies` would run the +  // `DependencyScanningAction` once for every time the input occured in the +  // CDB. Instead we split up the CDB into single command chunks to avoid this +  // behavior. +  assert(Compilations.getAllCompileCommands().size() == 1 && +         "Expected a compilation database with a single command!"); +  std::string Input = Compilations.getAllCompileCommands().front().Filename; +      if (Format == ScanningOutputFormat::Make) {      MakeDependencyPrinterConsumer Consumer;      auto Result =  | 

