================
@@ -160,43 +333,92 @@ DependencyScanningTool::getModuleDependencies(
StringRef ModuleName, const std::vector<std::string> &CommandLine,
StringRef CWD, const llvm::DenseSet<ModuleID> &AlreadySeen,
LookupModuleOutputCallback LookupModuleOutput) {
- FullDependencyConsumer Consumer(AlreadySeen);
- CallbackActionController Controller(LookupModuleOutput);
if (auto Error =
- Worker.initializeCompilerInstanceWithContextOrError(CWD,
CommandLine))
- return std::move(Error);
+ initializeCompilerInstanceWithContextOrError(CWD, CommandLine))
+ return Error;
- auto Result = Worker.computeDependenciesByNameWithContextOrError(
- ModuleName, Consumer, Controller);
+ auto Result = computeDependenciesByNameWithContextOrError(
+ ModuleName, AlreadySeen, LookupModuleOutput);
- if (auto Error = Worker.finalizeCompilerInstanceWithContextOrError())
- return std::move(Error);
+ if (auto Error = finalizeCompilerInstanceWithContextOrError())
+ return Error;
- if (Result)
- return std::move(Result);
+ return Result;
+}
- return Consumer.takeTranslationUnitDeps();
+static std::optional<std::vector<std::string>> getFirstCC1CommandLine(
+ ArrayRef<std::string> CommandLine, DiagnosticsEngine &Diags,
+ llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> ScanFS) {
+ // Compilation holds a non-owning a reference to the Driver, hence we need to
+ // keep the Driver alive when we use Compilation. Arguments to commands may
be
+ // owned by Alloc when expanded from response files.
+ llvm::BumpPtrAllocator Alloc;
+ const auto [Driver, Compilation] =
+ buildCompilation(CommandLine, Diags, ScanFS, Alloc);
+ if (!Compilation)
+ return std::nullopt;
+
+ const auto IsClangCmd = [](const driver::Command &Cmd) {
+ return StringRef(Cmd.getCreator().getName()) == "clang";
+ };
+ const auto CC1CommandLineRange = llvm::map_range(
+ llvm::make_filter_range(Compilation->getJobs(), IsClangCmd),
+ buildCC1CommandLine);
+
+ if (CC1CommandLineRange.empty())
+ return std::nullopt;
+ return *CC1CommandLineRange.begin();
}
-llvm::Error DependencyScanningTool::initializeCompilerInstanceWithContext(
- StringRef CWD, const std::vector<std::string> &CommandLine) {
- return Worker.initializeCompilerInstanceWithContextOrError(CWD, CommandLine);
+llvm::Error
+DependencyScanningTool::initializeCompilerInstanceWithContextOrError(
+ StringRef CWD, ArrayRef<std::string> CommandLine) {
+ // For by name scanning, we allow command lines without an actual input file
+ // by adding an in-memory placeholder input.
+ auto OverlayFSAndArgs = initVFSForByNameScanning(
----------------
jansvoboda11 wrote:
You should be able to replace this with structured bindings for clarity.
https://github.com/llvm/llvm-project/pull/169964
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits