aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2023-02-01 13:42:19 -0800
committerJan Svoboda <jan_svoboda@apple.com>2023-02-01 13:46:26 -0800
commit8e9f62e5f833cb89b57bf4c9e80e850bcac7e15e (patch)
tree478b5bae88a98077a0efe3704dc85b112678548d /clang/lib
parentba556660fe52a558c34556866aba4a0bb8bbbd23 (diff)
downloadllvm-8e9f62e5f833cb89b57bf4c9e80e850bcac7e15e.zip
llvm-8e9f62e5f833cb89b57bf4c9e80e850bcac7e15e.tar.gz
llvm-8e9f62e5f833cb89b57bf4c9e80e850bcac7e15e.tar.bz2
[clang][deps] Give the fake file a unique name in by-module-name scans
When scanning dependencies of a module, the command line we're given doesn't have an input file, which the driver needs to be happy. We've been creating a fake in-memory input file named after the module. However, this can hide files/directories on the actual filesystem, leading to errors. This patch works around that issue by generating a unique file name, which won't collide with the actual file system. We could also change the driver APIs so that we're able to specify an "assumed" input file. This would be more work, though, since the driver assumes the input name comes from the actual command-line. Depends on D140176. Reviewed By: artemcm Differential Revision: https://reviews.llvm.org/D140177
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index b54b8de..f14de94 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -393,30 +393,40 @@ bool DependencyScanningWorker::computeDependencies(
std::optional<std::vector<std::string>> ModifiedCommandLine;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> ModifiedFS;
- if (ModuleName) {
- ModifiedCommandLine = CommandLine;
- ModifiedCommandLine->emplace_back(*ModuleName);
+ // If we're scanning based on a module name alone, we don't expect the client
+ // to provide us with an input file. However, the driver really wants to have
+ // one. Let's just make it up to make the driver happy.
+ if (ModuleName) {
auto OverlayFS =
llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(BaseFS);
auto InMemoryFS =
llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
InMemoryFS->setCurrentWorkingDirectory(WorkingDirectory);
- InMemoryFS->addFile(*ModuleName, 0, llvm::MemoryBuffer::getMemBuffer(""));
OverlayFS->pushOverlay(InMemoryFS);
ModifiedFS = OverlayFS;
+
+ SmallString<128> FakeInputPath;
+ // TODO: We should retry the creation if the path already exists.
+ llvm::sys::fs::createUniquePath(*ModuleName + "-%%%%%%%%.input",
+ FakeInputPath,
+ /*MakeAbsolute=*/false);
+ InMemoryFS->addFile(FakeInputPath, 0, llvm::MemoryBuffer::getMemBuffer(""));
+
+ ModifiedCommandLine = CommandLine;
+ ModifiedCommandLine->emplace_back(FakeInputPath);
}
const std::vector<std::string> &FinalCommandLine =
ModifiedCommandLine ? *ModifiedCommandLine : CommandLine;
+ auto &FinalFS = ModifiedFS ? ModifiedFS : BaseFS;
FileSystemOptions FSOpts;
FSOpts.WorkingDir = WorkingDirectory.str();
- auto FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(
- FSOpts, ModifiedFS ? ModifiedFS : BaseFS);
+ auto FileMgr = llvm::makeIntrusiveRefCnt<FileManager>(FSOpts, FinalFS);
- std::vector<const char *> FinalCCommandLine(CommandLine.size(), nullptr);
- llvm::transform(CommandLine, FinalCCommandLine.begin(),
+ std::vector<const char *> FinalCCommandLine(FinalCommandLine.size(), nullptr);
+ llvm::transform(FinalCommandLine, FinalCCommandLine.begin(),
[](const std::string &Str) { return Str.c_str(); });
auto DiagOpts = CreateAndPopulateDiagOpts(FinalCCommandLine);