-
Couldn't load subscription status.
- Fork 15k
[llvm][clang] Use the VFS in FileCollector
#160788
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
Conversation
|
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) ChangesThis PR changes Full diff: https://github.com/llvm/llvm-project/pull/160788.diff 5 Files Affected:
diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h
index f86c2f5074de0..49fd920d1ec43 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -143,8 +143,9 @@ class ModuleDependencyCollector : public DependencyCollector {
std::error_code copyToRoot(StringRef Src, StringRef Dst = {});
public:
- ModuleDependencyCollector(std::string DestDir)
- : DestDir(std::move(DestDir)) {}
+ ModuleDependencyCollector(std::string DestDir,
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
+ : DestDir(std::move(DestDir)), Canonicalizer(std::move(VFS)) {}
~ModuleDependencyCollector() override { writeFileMap(); }
StringRef getDest() { return DestDir; }
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index d6f3aec981336..c989ad2e5155c 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -503,7 +503,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
// then we're the top level compiler instance and need to create one.
if (!ModuleDepCollector && !DepOpts.ModuleDependencyOutputDir.empty()) {
ModuleDepCollector = std::make_shared<ModuleDependencyCollector>(
- DepOpts.ModuleDependencyOutputDir);
+ DepOpts.ModuleDependencyOutputDir, getVirtualFileSystemPtr());
}
// If there is a module dep collector, register with other dep collectors
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h b/lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
index 4fe727460fdb9..dcba0d9c34962 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ModuleDependencyCollector.h
@@ -19,8 +19,8 @@ class ModuleDependencyCollectorAdaptor
public:
ModuleDependencyCollectorAdaptor(
std::shared_ptr<llvm::FileCollectorBase> file_collector)
- : clang::ModuleDependencyCollector(""), m_file_collector(file_collector) {
- }
+ : clang::ModuleDependencyCollector("", llvm::vfs::getRealFileSystem()),
+ m_file_collector(file_collector) {}
void addFile(llvm::StringRef Filename,
llvm::StringRef FileDst = {}) override {
diff --git a/llvm/include/llvm/Support/FileCollector.h b/llvm/include/llvm/Support/FileCollector.h
index b00bf3174e654..9cc6776b948ba 100644
--- a/llvm/include/llvm/Support/FileCollector.h
+++ b/llvm/include/llvm/Support/FileCollector.h
@@ -81,19 +81,25 @@ class LLVM_ABI FileCollector : public FileCollectorBase {
/// Canonicalize a pair of virtual and real paths.
LLVM_ABI PathStorage canonicalize(StringRef SrcPath);
+ explicit PathCanonicalizer(IntrusiveRefCntPtr<vfs::FileSystem> VFS)
+ : VFS(std::move(VFS)) {}
+
private:
/// Replace with a (mostly) real path, or don't modify. Resolves symlinks
/// in the directory, using \a CachedDirs to avoid redundant lookups, but
/// leaves the filename as a possible symlink.
void updateWithRealPath(SmallVectorImpl<char> &Path);
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
+
StringMap<std::string> CachedDirs;
};
/// \p Root is the directory where collected files are will be stored.
/// \p OverlayRoot is VFS mapping root.
/// \p Root directory gets created in copyFiles unless it already exists.
- FileCollector(std::string Root, std::string OverlayRoot);
+ FileCollector(std::string Root, std::string OverlayRoot,
+ IntrusiveRefCntPtr<vfs::FileSystem> VFS);
/// Write the yaml mapping (for the VFS) to the given file.
std::error_code writeMapping(StringRef MappingFile);
diff --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp
index edb5313d43eec..5dc224a6d427b 100644
--- a/llvm/lib/Support/FileCollector.cpp
+++ b/llvm/lib/Support/FileCollector.cpp
@@ -49,8 +49,9 @@ static bool isCaseSensitivePath(StringRef Path) {
return true;
}
-FileCollector::FileCollector(std::string Root, std::string OverlayRoot)
- : Root(Root), OverlayRoot(OverlayRoot) {
+FileCollector::FileCollector(std::string Root, std::string OverlayRoot,
+ IntrusiveRefCntPtr<vfs::FileSystem> VFS)
+ : Root(Root), OverlayRoot(OverlayRoot), Canonicalizer(std::move(VFS)) {
assert(sys::path::is_absolute(Root) && "Root not absolute");
assert(sys::path::is_absolute(OverlayRoot) && "OverlayRoot not absolute");
}
@@ -88,9 +89,9 @@ void FileCollector::PathCanonicalizer::updateWithRealPath(
}
/// Make Path absolute.
-static void makeAbsolute(SmallVectorImpl<char> &Path) {
+static void makeAbsolute(vfs::FileSystem &VFS, SmallVectorImpl<char> &Path) {
// We need an absolute src path to append to the root.
- sys::fs::make_absolute(Path);
+ VFS.makeAbsolute(Path);
// Canonicalize src to a native path to avoid mixed separator styles.
sys::path::native(Path);
@@ -105,7 +106,7 @@ FileCollector::PathCanonicalizer::PathStorage
FileCollector::PathCanonicalizer::canonicalize(StringRef SrcPath) {
PathStorage Paths;
Paths.VirtualPath = SrcPath;
- makeAbsolute(Paths.VirtualPath);
+ makeAbsolute(*VFS, Paths.VirtualPath);
// If a ".." component is present after a symlink component, remove_dots may
// lead to the wrong real destination path. Let the source be canonicalized
|
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.
Makes sense. LGTM
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/16650 Here is the relevant piece of the build log for the reference |
This PR changes `llvm::FileCollector` to use the `llvm::vfs::FileSystem` API for making file paths absolute instead of using `llvm::sys::fs::make_absolute()` directly. This matches the behavior of the compiler on most other input files.
This PR changes `llvm::FileCollector` to use the `llvm::vfs::FileSystem` API for making file paths absolute instead of using `llvm::sys::fs::make_absolute()` directly. This matches the behavior of the compiler on most other input files.
This PR changes `llvm::FileCollector` to use the `llvm::vfs::FileSystem` API for making file paths absolute instead of using `llvm::sys::fs::make_absolute()` directly. This matches the behavior of the compiler on most other input files.
This PR changes
llvm::FileCollectorto use thellvm::vfs::FileSystemAPI for making file paths absolute instead of usingllvm::sys::fs::make_absolute()directly. This matches the behavior of the compiler on most other input files.