1 //===- DependencyScanningWorker.h - clang-scan-deps worker ===---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_WORKER_H
10 #define LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_WORKER_H
11 
12 #include "clang/Basic/DiagnosticOptions.h"
13 #include "clang/Basic/LLVM.h"
14 #include "clang/Frontend/PCHContainerOperations.h"
15 #include "clang/Tooling/CompilationDatabase.h"
16 #include "llvm/Support/Error.h"
17 #include "llvm/Support/FileSystem.h"
18 #include <string>
19 
20 namespace clang {
21 namespace tooling {
22 namespace dependencies {
23 
24 /// An individual dependency scanning worker that is able to run on its own
25 /// thread.
26 ///
27 /// The worker computes the dependencies for the input files by preprocessing
28 /// sources either using a fast mode where the source files are minimized, or
29 /// using the regular processing run.
30 class DependencyScanningWorker {
31 public:
32   DependencyScanningWorker();
33 
34   /// Print out the dependency information into a string using the dependency
35   /// file format that is specified in the options (-MD is the default) and
36   /// return it.
37   ///
38   /// \returns A \c StringError with the diagnostic output if clang errors
39   /// occurred, dependency file contents otherwise.
40   llvm::Expected<std::string> getDependencyFile(const std::string &Input,
41                                                 StringRef WorkingDirectory,
42                                                 const CompilationDatabase &CDB);
43 
44 private:
45   IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
46   std::shared_ptr<PCHContainerOperations> PCHContainerOps;
47 
48   /// The file system that is used by each worker when scanning for
49   /// dependencies. This filesystem persists accross multiple compiler
50   /// invocations.
51   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> WorkerFS;
52 };
53 
54 } // end namespace dependencies
55 } // end namespace tooling
56 } // end namespace clang
57 
58 #endif // LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_WORKER_H
59