clang 23.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, 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.
llvm::Expected< dependencies::TranslationUnitDepsgetModuleDependencies (StringRef ModuleName, ArrayRef< std::string > CommandLine, StringRef CWD, const llvm::DenseSet< dependencies::ModuleID > &AlreadySeen, dependencies::LookupModuleOutputCallback LookupModuleOutput)
 Given a compilation context specified via the Clang driver command-line, gather modular dependencies of module with the given name, and return the information needed for explicit build.
llvm::vfs::FileSystem & getWorkerVFS () const

Friends

class CompilerInstanceWithContext

Detailed Description

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

Definition at line 34 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 39 of file DependencyScanningTool.h.

Member Function Documentation

◆ getDependencyFile()

std::optional< std::string > DependencyScanningTool::getDependencyFile ( ArrayRef< std::string > CommandLine,
StringRef CWD,
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 189 of file DependencyScanningTool.cpp.

References clang::tooling::computeDependencies().

◆ getModuleDependencies()

llvm::Expected< TranslationUnitDeps > DependencyScanningTool::getModuleDependencies ( StringRef ModuleName,
ArrayRef< std::string > CommandLine,
StringRef CWD,
const llvm::DenseSet< dependencies::ModuleID > & AlreadySeen,
dependencies::LookupModuleOutputCallback LookupModuleOutput )

Given a compilation context specified via the Clang driver command-line, gather modular dependencies of module with the given name, and return the information needed for explicit build.

TODO: this method should be removed as soon as Swift and our C-APIs adopt CompilerInstanceWithContext. We are keeping it here so that it is easier to coordinate with Swift and C-API changes.

Definition at line 345 of file DependencyScanningTool.cpp.

References clang::Error, and clang::tooling::CompilerInstanceWithContext::initializeOrError().

◆ 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(), and clang::Make.

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

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

◆ getWorkerVFS()

llvm::vfs::FileSystem & clang::tooling::DependencyScanningTool::getWorkerVFS ( ) const
inline

Definition at line 114 of file DependencyScanningTool.h.

◆ CompilerInstanceWithContext

friend class CompilerInstanceWithContext
friend

Definition at line 119 of file DependencyScanningTool.h.

References CompilerInstanceWithContext.

Referenced by CompilerInstanceWithContext.


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