Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:11

0001 //===- DependencyScanningWorker.h - clang-scan-deps worker ===---*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
0010 #define LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H
0011 
0012 #include "clang/Basic/DiagnosticOptions.h"
0013 #include "clang/Basic/FileManager.h"
0014 #include "clang/Basic/LLVM.h"
0015 #include "clang/Frontend/PCHContainerOperations.h"
0016 #include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
0017 #include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
0018 #include "llvm/Support/Error.h"
0019 #include "llvm/Support/FileSystem.h"
0020 #include <optional>
0021 #include <string>
0022 
0023 namespace clang {
0024 
0025 class DependencyOutputOptions;
0026 
0027 namespace tooling {
0028 namespace dependencies {
0029 
0030 class DependencyScanningWorkerFilesystem;
0031 
0032 /// A command-line tool invocation that is part of building a TU.
0033 ///
0034 /// \see TranslationUnitDeps::Commands.
0035 struct Command {
0036   std::string Executable;
0037   std::vector<std::string> Arguments;
0038 };
0039 
0040 class DependencyConsumer {
0041 public:
0042   virtual ~DependencyConsumer() {}
0043 
0044   virtual void handleProvidedAndRequiredStdCXXModules(
0045       std::optional<P1689ModuleInfo> Provided,
0046       std::vector<P1689ModuleInfo> Requires) {}
0047 
0048   virtual void handleBuildCommand(Command Cmd) {}
0049 
0050   virtual void
0051   handleDependencyOutputOpts(const DependencyOutputOptions &Opts) = 0;
0052 
0053   virtual void handleFileDependency(StringRef Filename) = 0;
0054 
0055   virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) = 0;
0056 
0057   virtual void handleModuleDependency(ModuleDeps MD) = 0;
0058 
0059   virtual void handleDirectModuleDependency(ModuleID MD) = 0;
0060 
0061   virtual void handleContextHash(std::string Hash) = 0;
0062 };
0063 
0064 /// Dependency scanner callbacks that are used during scanning to influence the
0065 /// behaviour of the scan - for example, to customize the scanned invocations.
0066 class DependencyActionController {
0067 public:
0068   virtual ~DependencyActionController();
0069 
0070   virtual std::string lookupModuleOutput(const ModuleID &ID,
0071                                          ModuleOutputKind Kind) = 0;
0072 };
0073 
0074 /// An individual dependency scanning worker that is able to run on its own
0075 /// thread.
0076 ///
0077 /// The worker computes the dependencies for the input files by preprocessing
0078 /// sources either using a fast mode where the source files are minimized, or
0079 /// using the regular processing run.
0080 class DependencyScanningWorker {
0081 public:
0082   DependencyScanningWorker(DependencyScanningService &Service,
0083                            llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS);
0084 
0085   /// Run the dependency scanning tool for a given clang driver command-line,
0086   /// and report the discovered dependencies to the provided consumer. If \p
0087   /// ModuleName isn't empty, this function reports the dependencies of module
0088   /// \p ModuleName.
0089   ///
0090   /// \returns false if clang errors occurred (with diagnostics reported to
0091   /// \c DiagConsumer), true otherwise.
0092   bool computeDependencies(StringRef WorkingDirectory,
0093                            const std::vector<std::string> &CommandLine,
0094                            DependencyConsumer &DepConsumer,
0095                            DependencyActionController &Controller,
0096                            DiagnosticConsumer &DiagConsumer,
0097                            std::optional<StringRef> ModuleName = std::nullopt);
0098   /// \returns A \c StringError with the diagnostic output if clang errors
0099   /// occurred, success otherwise.
0100   llvm::Error computeDependencies(
0101       StringRef WorkingDirectory, const std::vector<std::string> &CommandLine,
0102       DependencyConsumer &Consumer, DependencyActionController &Controller,
0103       std::optional<StringRef> ModuleName = std::nullopt);
0104 
0105   bool shouldEagerLoadModules() const { return EagerLoadModules; }
0106 
0107   llvm::vfs::FileSystem &getVFS() const { return *BaseFS; }
0108 
0109 private:
0110   std::shared_ptr<PCHContainerOperations> PCHContainerOps;
0111   /// The file system to be used during the scan.
0112   /// This is either \c FS passed in the constructor (when performing canonical
0113   /// preprocessing), or \c DepFS (when performing dependency directives scan).
0114   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS;
0115   /// When performing dependency directives scan, this is the caching (and
0116   /// dependency-directives-extracting) filesystem overlaid on top of \c FS
0117   /// (passed in the constructor).
0118   llvm::IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS;
0119   ScanningOutputFormat Format;
0120   /// Whether to optimize the modules' command-line arguments.
0121   ScanningOptimizations OptimizeArgs;
0122   /// Whether to set up command-lines to load PCM files eagerly.
0123   bool EagerLoadModules;
0124 };
0125 
0126 } // end namespace dependencies
0127 } // end namespace tooling
0128 } // end namespace clang
0129 
0130 #endif // LLVM_CLANG_TOOLING_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H