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)
 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< P1689RulegetP1689ModuleDependencyFile (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< P1689RulegetP1689ModuleDependencyFile (const CompileCommand &Command, StringRef CWD, DiagnosticConsumer &DiagConsumer)
std::optional< dependencies::TranslationUnitDepsgetTranslationUnitDependencies (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.
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)
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 349 of file DependencyScanningTool.cpp.

References clang::CompilerInstance::createDiagnostics(), clang::dependencies::createScanningDiagOptions(), getFirstCC1CommandLine(), and initVFSForByNameScanning().

◆ 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 188 of file DependencyScanningTool.cpp.

References clang::tooling::computeDependencies().

◆ getP1689ModuleDependencyFile() [1/2]

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

Definition at line 69 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 202 of file DependencyScanningTool.cpp.

References clang::tooling::computeDependencies(), 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 TUBuffer is 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 301 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 120 of file DependencyScanningTool.h.


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