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;
80 MakeDependencyPrinterConsumer Consumer;
83 Worker.computeDependencies(CWD, CommandLine, Consumer, Controller);
87 Consumer.printDependencies(Output);
93 std::string &MakeformatOutputPath) {
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 auto Result = Worker.computeDependencies(CWD,
Command.CommandLine, Consumer,
140 MakeformatOutputPath = Consumer.getMakeFormatDependencyOutputPath();
141 if (!MakeformatOutputPath.empty())
142 Consumer.printDependencies(MakeformatOutput);
149 const llvm::DenseSet<ModuleID> &AlreadySeen,
151 std::optional<llvm::MemoryBufferRef> TUBuffer) {
154 llvm::Error
Result = Worker.computeDependencies(CWD, CommandLine, Consumer,
155 Controller, TUBuffer);
165 const llvm::DenseSet<ModuleID> &AlreadySeen,
172 ModuleName, AlreadySeen, LookupModuleOutput);
182static std::vector<std::string>
185 std::vector<std::string> Out;
186 Out.reserve(Args.size() + 1);
188 llvm::append_range(Out, Args);
198 llvm::BumpPtrAllocator Alloc;
199 const auto [Driver, Compilation] =
205 return StringRef(Cmd.getCreator().getName()) ==
"clang";
208 const auto &Jobs = Compilation->getJobs();
209 if (
const auto It = llvm::find_if(Jobs, IsClangCmd); It != Jobs.end())
216 return llvm::make_error<llvm::StringError>(
217 DiagPrinterWithOS.
DiagnosticsOS.str(), llvm::inconvertibleErrorCode());
224 std::make_unique<TextDiagnosticsPrinterWithOutput>(CommandLine);
226 if (CommandLine.size() >= 2 && CommandLine[1] ==
"-cc1") {
229 if (Worker.initializeCompilerInstanceWithContext(
230 CWD, CommandLine, DiagPrinterWithOS->DiagPrinter))
231 return llvm::Error::success();
239 &Worker.getVFS(), CommandLine, CWD,
"ScanningByName");
240 auto &OverlayFS = OverlayFSAndArgs.first;
241 const auto &ModifiedCommandLine = OverlayFSAndArgs.second;
243 auto DiagEngineWithCmdAndOpts =
244 std::make_unique<DiagnosticsEngineWithDiagOpts>(
245 ModifiedCommandLine, OverlayFS, DiagPrinterWithOS->DiagPrinter);
248 ModifiedCommandLine, *DiagEngineWithCmdAndOpts->DiagEngine, OverlayFS);
252 if (Worker.initializeCompilerInstanceWithContext(
253 CWD, *MaybeFirstCC1, std::move(DiagEngineWithCmdAndOpts), OverlayFS))
254 return llvm::Error::success();
260 StringRef ModuleName,
const llvm::DenseSet<ModuleID> &AlreadySeen,
264 if (Worker.computeDependenciesByNameWithContext(ModuleName, Consumer,
272 if (Worker.finalizeCompilerInstanceWithContext())
273 return llvm::Error::success();
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
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...
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