clang 24.0.0git
clang::tooling::DependencyScanningTool Class Reference

The high-level implementation of the dependency discovery tool that runs on an individual worker thread. More...

#include "clang/Tooling/DependencyScanningTool.h"

Public Member Functions

 DependencyScanningTool (dependencies::DependencyScanningService &Service, IntrusiveRefCntPtr< llvm::vfs::FileSystem > LocalFS=nullptr)
 Construct a dependency scanning tool.
std::optional< std::string > getDependencyFile (ArrayRef< std::string > CommandLine, StringRef CWD, dependencies::LookupModuleOutputCallback LookupModuleOutput, DiagnosticConsumer &DiagConsumer)
 Print out the dependency information into a string using the dependency file format that is specified in the options (-MD is the default) and return it.
std::optional< P1689Rule > getP1689ModuleDependencyFile (const CompileCommand &Command, StringRef CWD, std::string &MakeformatOutput, std::string &MakeformatOutputPath, DiagnosticConsumer &DiagConsumer)
 Collect the module dependency in P1689 format for C++20 named modules.
std::optional< P1689Rule > getP1689ModuleDependencyFile (const CompileCommand &Command, StringRef CWD, DiagnosticConsumer &DiagConsumer)
std::optional< dependencies::TranslationUnitDeps > getTranslationUnitDependencies (ArrayRef< std::string > CommandLine, StringRef CWD, DiagnosticConsumer &DiagConsumer, const llvm::DenseSet< dependencies::ModuleID > &AlreadySeen, dependencies::LookupModuleOutputCallback LookupModuleOutput, std::optional< llvm::MemoryBufferRef > TUBuffer=std::nullopt)
 Given a Clang driver command-line for a translation unit, gather the modular dependencies and return the information needed for explicit build.
bool getByNameDependencies (StringRef CWD, ArrayRef< std::string > CommandLine, DiagnosticConsumer &DiagConsumer, dependencies::DependencyActionController &Controller, llvm::function_ref< std::optional< std::string >()> getNextName, dependencies::DependencyConsumer &DepConsumer)
 By-name scanning given a Clang command-line.
std::optional< llvm::StringMap< std::string > > getModuleMapsForModules (StringRef CWD, ArrayRef< std::string > CommandLine, DiagnosticConsumer &DiagConsumer, dependencies::DependencyActionController &Controller, ArrayRef< StringRef > ModuleNames)
 Find the module maps that define each module in ModuleNames, without loading or reporting diagnostics about the modules.
llvm::vfs::TracingFileSystem * getWorkerTracingVFS () const
 Returns the worker tracing VFS, if it was requested via the service.

Detailed Description

The high-level implementation of the dependency discovery tool that runs on an individual worker thread.

Definition at line 33 of file DependencyScanningTool.h.

Constructor & Destructor Documentation

◆ DependencyScanningTool()

clang::tooling::DependencyScanningTool::DependencyScanningTool ( dependencies::DependencyScanningService & Service,
IntrusiveRefCntPtr< llvm::vfs::FileSystem > LocalFS = nullptr )
inline

Construct a dependency scanning tool.

Parameters
ServiceThe parent service. Must outlive the tool.

Definition at line 38 of file DependencyScanningTool.h.

Member Function Documentation

◆ getByNameDependencies()

bool DependencyScanningTool::getByNameDependencies ( StringRef CWD,
ArrayRef< std::string > CommandLine,
DiagnosticConsumer & DiagConsumer,
dependencies::DependencyActionController & Controller,
llvm::function_ref< std::optional< std::string >()> getNextName,
dependencies::DependencyConsumer & DepConsumer )

By-name scanning given a Clang command-line.

The scanning context is initialized once and reused for each name pulled from getNextName until it returns std::nullopt. Results flow to DepConsumer (with per-name status via finishQuery); diagnostics flow to DiagConsumer.

Returns
true if the scanning context initialized successfully and all scans succeeded. Query the DepConsumer for the state of each individual scan.

Definition at line 402 of file DependencyScanningTool.cpp.

References clang::Init, and initByNameScanning().

◆ getDependencyFile()

std::optional< std::string > DependencyScanningTool::getDependencyFile ( ArrayRef< std::string > CommandLine,
StringRef CWD,
dependencies::LookupModuleOutputCallback LookupModuleOutput,
DiagnosticConsumer & DiagConsumer )

Print out the dependency information into a string using the dependency file format that is specified in the options (-MD is the default) and return it.

Returns
std::nullopt if errors occurred (reported to the DiagConsumer), dependency file contents otherwise.

Definition at line 208 of file DependencyScanningTool.cpp.

References clang::tooling::computeDependencies().

◆ getModuleMapsForModules()

std::optional< llvm::StringMap< std::string > > DependencyScanningTool::getModuleMapsForModules ( StringRef CWD,
ArrayRef< std::string > CommandLine,
DiagnosticConsumer & DiagConsumer,
dependencies::DependencyActionController & Controller,
ArrayRef< StringRef > ModuleNames )

Find the module maps that define each module in ModuleNames, without loading or reporting diagnostics about the modules.

Returns
a map from each module name that is found to the path of the module map that defines it, or std::nullopt if the compiler invocation could not be set up. Names provided by a prebuilt module file, or with no module map found, are omitted.

Definition at line 417 of file DependencyScanningTool.cpp.

References clang::Init, and initByNameScanning().

◆ getP1689ModuleDependencyFile() [1/2]

std::optional< P1689Rule > clang::tooling::DependencyScanningTool::getP1689ModuleDependencyFile ( const CompileCommand & Command,
StringRef CWD,
DiagnosticConsumer & DiagConsumer )
inline

Definition at line 71 of file DependencyScanningTool.h.

References getP1689ModuleDependencyFile().

◆ getP1689ModuleDependencyFile() [2/2]

std::optional< P1689Rule > DependencyScanningTool::getP1689ModuleDependencyFile ( const CompileCommand & Command,
StringRef CWD,
std::string & MakeformatOutput,
std::string & MakeformatOutputPath,
DiagnosticConsumer & DiagConsumer )

Collect the module dependency in P1689 format for C++20 named modules.

Parameters
MakeformatOutputThe output parameter for dependency information in make format if the command line requires to generate make-format dependency information by -MD -MF <dep_file>.
MakeformatOutputPathThe output parameter for the path to MakeformatOutput.
Returns
std::nullopt if errors occurred (reported to the DiagConsumer), P1689 dependency format rules otherwise.

Definition at line 222 of file DependencyScanningTool.cpp.

References clang::tooling::computeDependencies(), clang::PreprocessorOptions::DependencyScanningModuleMapImports, clang::CompilerInvocation::getPreprocessorOpts(), clang::Make, clang::DependencyOutputOptions::OutputFile, and clang::DependencyOutputOptions::OutputFormat.

Referenced by getP1689ModuleDependencyFile().

◆ getTranslationUnitDependencies()

std::optional< TranslationUnitDeps > DependencyScanningTool::getTranslationUnitDependencies ( ArrayRef< std::string > CommandLine,
StringRef CWD,
DiagnosticConsumer & DiagConsumer,
const llvm::DenseSet< dependencies::ModuleID > & AlreadySeen,
dependencies::LookupModuleOutputCallback LookupModuleOutput,
std::optional< llvm::MemoryBufferRef > TUBuffer = std::nullopt )

Given a Clang driver command-line for a translation unit, gather the modular dependencies and return the information needed for explicit build.

Parameters
AlreadySeenThis stores modules which have previously been reported. Use the same instance for all calls to this function for a single DependencyScanningTool in a single build. Use a different one for different tools, and clear it between builds.
LookupModuleOutputThis function is called to fill in "-fmodule-file=", "-o" and other output arguments for dependencies.
TUBufferOptional memory buffer for translation unit input. If std::nullopt, the input should be included in the CommandLine already.
Returns
std::nullopt if errors occurred (reported to the DiagConsumer), translation unit dependencies otherwise.

Definition at line 326 of file DependencyScanningTool.cpp.

References clang::tooling::computeDependencies(), initVFSForTUBufferScanning(), and clang::dependencies::FullDependencyConsumer::takeTranslationUnitDeps().

◆ getWorkerTracingVFS()

llvm::vfs::TracingFileSystem * clang::tooling::DependencyScanningTool::getWorkerTracingVFS ( ) const
inline

Returns the worker tracing VFS, if it was requested via the service.

Definition at line 135 of file DependencyScanningTool.h.


The documentation for this class was generated from the following files: