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/FileManager.h" 14 #include "clang/Basic/LLVM.h" 15 #include "clang/Frontend/PCHContainerOperations.h" 16 #include "clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h" 17 #include "clang/Tooling/CompilationDatabase.h" 18 #include "llvm/Support/Error.h" 19 #include "llvm/Support/FileSystem.h" 20 #include <string> 21 22 namespace clang { 23 24 class DependencyOutputOptions; 25 26 namespace tooling { 27 namespace dependencies { 28 29 class DependencyScanningService; 30 class DependencyScanningWorkerFilesystem; 31 32 class DependencyConsumer { 33 public: 34 virtual ~DependencyConsumer() {} 35 36 virtual void handleFileDependency(const DependencyOutputOptions &Opts, 37 StringRef Filename) = 0; 38 39 // FIXME: Add support for reporting modular dependencies. 40 }; 41 42 /// An individual dependency scanning worker that is able to run on its own 43 /// thread. 44 /// 45 /// The worker computes the dependencies for the input files by preprocessing 46 /// sources either using a fast mode where the source files are minimized, or 47 /// using the regular processing run. 48 class DependencyScanningWorker { 49 public: 50 DependencyScanningWorker(DependencyScanningService &Service); 51 52 /// Run the dependency scanning tool for a given clang driver invocation (as 53 /// specified for the given Input in the CDB), and report the discovered 54 /// dependencies to the provided consumer. 55 /// 56 /// \returns A \c StringError with the diagnostic output if clang errors 57 /// occurred, success otherwise. 58 llvm::Error computeDependencies(const std::string &Input, 59 StringRef WorkingDirectory, 60 const CompilationDatabase &CDB, 61 DependencyConsumer &Consumer); 62 63 private: 64 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts; 65 std::shared_ptr<PCHContainerOperations> PCHContainerOps; 66 std::unique_ptr<ExcludedPreprocessorDirectiveSkipMapping> PPSkipMappings; 67 68 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> RealFS; 69 /// The file system that is used by each worker when scanning for 70 /// dependencies. This filesystem persists accross multiple compiler 71 /// invocations. 72 llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS; 73 /// The file manager that is reused accross multiple invocations by this 74 /// worker. If null, the file manager will not be reused. 75 llvm::IntrusiveRefCntPtr<FileManager> Files; 76 }; 77 78 } // end namespace dependencies 79 } // end namespace tooling 80 } // end namespace clang 81 82 #endif // LLVM_CLANG_TOOLING_DEPENDENCY_SCANNING_WORKER_H 83