23 : Worker(Service,
std::move(FS)) {}
29 void handleBuildCommand(
Command)
override {}
33 this->Opts = std::make_unique<DependencyOutputOptions>(Opts);
36 void handleFileDependency(StringRef
File)
override {
37 Dependencies.push_back(std::string(
File));
43 void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD)
override {}
44 void handleModuleDependency(ModuleDeps MD)
override {}
45 void handleDirectModuleDependency(ModuleID ID)
override {}
46 void handleVisibleModule(std::string ModuleName)
override {}
47 void handleContextHash(std::string Hash)
override {}
49 void printDependencies(std::string &S) {
50 assert(Opts &&
"Handled dependency output options.");
52 class DependencyPrinter :
public DependencyFileGenerator {
54 DependencyPrinter(DependencyOutputOptions &Opts,
55 ArrayRef<std::string> Dependencies)
56 : DependencyFileGenerator(Opts) {
57 for (
const auto &Dep : Dependencies)
61 void printDependencies(std::string &S) {
62 llvm::raw_string_ostream
OS(S);
63 outputDependencyFile(OS);
67 DependencyPrinter
Generator(*Opts, Dependencies);
72 std::unique_ptr<DependencyOutputOptions> Opts;
73 std::vector<std::string> Dependencies;
77std::optional<std::string>
81 MakeDependencyPrinterConsumer DepConsumer;
83 if (!Worker.computeDependencies(CWD, CommandLine, DepConsumer, Controller,
87 DepConsumer.printDependencies(Output);
94 class P1689ModuleDependencyPrinterConsumer
95 :
public MakeDependencyPrinterConsumer {
97 P1689ModuleDependencyPrinterConsumer(
P1689Rule &Rule,
99 : Filename(
Command.Filename), Rule(Rule) {
100 Rule.PrimaryOutput =
Command.Output;
103 void handleProvidedAndRequiredStdCXXModules(
104 std::optional<P1689ModuleInfo> Provided,
105 std::vector<P1689ModuleInfo> Requires)
override {
106 Rule.Provides = Provided;
108 Rule.Provides->SourcePath = Filename.str();
109 Rule.Requires = Requires;
112 StringRef getMakeFormatDependencyOutputPath() {
115 return Opts->OutputFile;
126 std::string lookupModuleOutput(
const ModuleDeps &,
133 P1689ModuleDependencyPrinterConsumer Consumer(Rule,
Command);
134 P1689ActionController Controller;
135 if (!Worker.computeDependencies(CWD,
Command.CommandLine, Consumer,
136 Controller, DiagConsumer))
139 MakeformatOutputPath = Consumer.getMakeFormatDependencyOutputPath();
140 if (!MakeformatOutputPath.empty())
141 Consumer.printDependencies(MakeformatOutput);
145std::optional<TranslationUnitDeps>
149 const llvm::DenseSet<ModuleID> &AlreadySeen,
151 std::optional<llvm::MemoryBufferRef> TUBuffer) {
155 if (!Worker.computeDependencies(CWD, CommandLine, Consumer, Controller,
156 DiagConsumer, TUBuffer))
164 const llvm::DenseSet<ModuleID> &AlreadySeen,
171 ModuleName, AlreadySeen, LookupModuleOutput);
181static std::vector<std::string>
184 std::vector<std::string> Out;
185 Out.reserve(Args.size() + 1);
187 llvm::append_range(Out, Args);
197 llvm::BumpPtrAllocator Alloc;
198 const auto [Driver, Compilation] =
204 return StringRef(Cmd.getCreator().getName()) ==
"clang";
207 const auto &Jobs = Compilation->getJobs();
208 if (
const auto It = llvm::find_if(Jobs, IsClangCmd); It != Jobs.end())
215 return llvm::make_error<llvm::StringError>(
216 DiagPrinterWithOS.
DiagnosticsOS.str(), llvm::inconvertibleErrorCode());
222 if (CommandLine.size() >= 2 && CommandLine[1] ==
"-cc1") {
225 return Worker.initializeCompilerInstanceWithContext(CWD, CommandLine, DC);
232 &Worker.getVFS(), CommandLine, CWD,
"ScanningByName");
233 auto DiagEngineWithCmdAndOpts =
234 std::make_unique<DiagnosticsEngineWithDiagOpts>(ModifiedCommandLine,
238 ModifiedCommandLine, *DiagEngineWithCmdAndOpts->DiagEngine, OverlayFS);
242 return Worker.initializeCompilerInstanceWithContext(
243 CWD, *MaybeFirstCC1, std::move(DiagEngineWithCmdAndOpts), OverlayFS);
250 std::make_unique<TextDiagnosticsPrinterWithOutput>(CommandLine);
253 Worker, CWD, CommandLine, DiagPrinterWithOS->DiagPrinter);
256 return llvm::Error::success();
262 StringRef ModuleName,
const llvm::DenseSet<ModuleID> &AlreadySeen,
266 if (Worker.computeDependenciesByNameWithContext(ModuleName, Consumer,
274 if (Worker.finalizeCompilerInstanceWithContext())
275 return llvm::Error::success();
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Concrete class used by the front-end to report problems and issues.
A simple dependency action controller that uses a callback.
Dependency scanner callbacks that are used during scanning to influence the behaviour of the scan - f...
The dependency scanning service contains shared configuration and state that is used by the individua...
An individual dependency scanning worker that is able to run on its own thread.
TranslationUnitDeps takeTranslationUnitDeps()
Command - An executable path/name and argument vector to execute.
const llvm::opt::ArgStringList & getArguments() const
const char * getExecutable() const
llvm::function_ref< std::string(const ModuleDeps &, ModuleOutputKind)> LookupModuleOutputCallback
A callback to lookup module outputs for "-fmodule-file=", "-o" etc.
ModuleOutputKind
An output from a module compilation, such as the path of the module file.
std::pair< IntrusiveRefCntPtr< llvm::vfs::OverlayFileSystem >, std::vector< std::string > > initVFSForByNameScanning(IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS, ArrayRef< std::string > CommandLine, StringRef WorkingDirectory, StringRef ModuleName)
std::pair< std::unique_ptr< driver::Driver >, std::unique_ptr< driver::Compilation > > buildCompilation(ArrayRef< std::string > ArgStrs, DiagnosticsEngine &Diags, IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS, llvm::BumpPtrAllocator &Alloc)
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
A command-line tool invocation that is part of building a TU.
llvm::raw_string_ostream DiagnosticsOS