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