-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][DependencyScanning] Move driver-command logic for by-name scanning into DependencyScanningTool #171238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
436c999
c3a23a4
9983824
9d02352
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| #include "clang/Driver/Driver.h" | ||
| #include "clang/Frontend/FrontendActions.h" | ||
| #include "llvm/ADT/ScopeExit.h" | ||
| #include "llvm/Support/VirtualFileSystem.h" | ||
| #include "llvm/TargetParser/Host.h" | ||
|
|
||
| using namespace clang; | ||
|
|
@@ -713,38 +714,31 @@ bool DependencyScanningAction::runInvocation( | |
| return Result; | ||
| } | ||
|
|
||
| bool CompilerInstanceWithContext::initialize(DiagnosticConsumer *DC) { | ||
| if (DC) { | ||
| DiagConsumer = DC; | ||
| } else { | ||
| DiagPrinterWithOS = | ||
| std::make_unique<TextDiagnosticsPrinterWithOutput>(CommandLine); | ||
| DiagConsumer = &DiagPrinterWithOS->DiagPrinter; | ||
| bool CompilerInstanceWithContext::initialize( | ||
| std::unique_ptr<DiagnosticsEngineWithDiagOpts> DiagEngineWithDiagOpts, | ||
| IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS) { | ||
| assert(DiagEngineWithDiagOpts && "Valid diagnostics engine required!"); | ||
| DiagEngineWithCmdAndOpts = std::move(DiagEngineWithDiagOpts); | ||
| DiagConsumer = DiagEngineWithCmdAndOpts->DiagEngine->getClient(); | ||
|
|
||
| IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = Worker.DepFS; | ||
| if (OverlayFS) { | ||
| #ifndef NDEBUG | ||
| bool SawDepFS = false; | ||
| OverlayFS->visit([&](llvm::vfs::FileSystem &VFS) { | ||
| SawDepFS |= &VFS == Worker.DepFS.get(); | ||
| }); | ||
| assert(SawDepFS && "OverlayFS not based on DepFS"); | ||
| #endif | ||
| FS = std::move(OverlayFS); | ||
| } | ||
|
|
||
| std::tie(OverlayFS, CommandLine) = initVFSForByNameScanning( | ||
| Worker.DepFS, CommandLine, CWD, "ScanningByName"); | ||
|
|
||
| DiagEngineWithCmdAndOpts = std::make_unique<DiagnosticsEngineWithDiagOpts>( | ||
| CommandLine, OverlayFS, *DiagConsumer); | ||
|
|
||
| std::tie(Driver, Compilation) = buildCompilation( | ||
| CommandLine, *DiagEngineWithCmdAndOpts->DiagEngine, OverlayFS, Alloc); | ||
|
|
||
| if (!Compilation) | ||
| return false; | ||
| // Reset what might have been modified in the previous worker invocation. | ||
| FS->setCurrentWorkingDirectory(CWD); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm maybe I am missing something. Could you help me understand why we need to reset the working directory here? Is it because at this point, we don't know if there will be an OverlayFS and hence we re not sure? If I understand the code correctly, the earlier call to |
||
|
|
||
| assert(Compilation->getJobs().size() && | ||
| "Must have a job list of non-zero size"); | ||
| const driver::Command &Command = *(Compilation->getJobs().begin()); | ||
| const auto &CommandArgs = Command.getArguments(); | ||
| assert(!CommandArgs.empty() && "Cannot have a command with 0 args"); | ||
| assert(StringRef(CommandArgs[0]) == "-cc1" && "Requires a cc1 job."); | ||
| OriginalInvocation = std::make_unique<CompilerInvocation>(); | ||
|
|
||
| if (!CompilerInvocation::CreateFromArgs(*OriginalInvocation, CommandArgs, | ||
| *DiagEngineWithCmdAndOpts->DiagEngine, | ||
| Command.getExecutable())) { | ||
| OriginalInvocation = createCompilerInvocation( | ||
| CommandLine, *DiagEngineWithCmdAndOpts->DiagEngine); | ||
| if (!OriginalInvocation) { | ||
| DiagEngineWithCmdAndOpts->DiagEngine->Report( | ||
| diag::err_fe_expected_compiler_job) | ||
| << llvm::join(CommandLine, " "); | ||
|
|
@@ -763,7 +757,7 @@ bool CompilerInstanceWithContext::initialize(DiagnosticConsumer *DC) { | |
| auto &CI = *CIPtr; | ||
|
|
||
| if (!initializeScanCompilerInstance( | ||
| CI, OverlayFS, DiagEngineWithCmdAndOpts->DiagEngine->getClient(), | ||
| CI, FS, DiagEngineWithCmdAndOpts->DiagEngine->getClient(), | ||
| Worker.Service, Worker.DepFS)) | ||
| return false; | ||
|
|
||
|
|
@@ -876,11 +870,3 @@ bool CompilerInstanceWithContext::finalize() { | |
| DiagConsumer->finish(); | ||
| return true; | ||
| } | ||
|
|
||
| llvm::Error CompilerInstanceWithContext::handleReturnStatus(bool Success) { | ||
| assert(DiagPrinterWithOS && "Must use the default DiagnosticConsumer."); | ||
| return Success ? llvm::Error::success() | ||
| : llvm::make_error<llvm::StringError>( | ||
| DiagPrinterWithOS->DiagnosticsOS.str(), | ||
| llvm::inconvertibleErrorCode()); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: do we still need this? I see that we already included
"llvm/Support/VirtualFileSystem.h"inclang/include/clang/DependencyScanning/DependencyScannerImpl.h.