Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/include/clang/Frontend/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion llvm/include/llvm/Support/FileCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions llvm/lib/Support/FileCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions llvm/tools/dsymutil/Reproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ ReproducerGenerate::ReproducerGenerate(std::error_code &EC, int Argc,
char **Argv, bool GenerateOnExit)
: Root(createReproducerDir(EC)), GenerateOnExit(GenerateOnExit) {
llvm::append_range(Args, ArrayRef(Argv, Argc));
auto RealFS = vfs::getRealFileSystem();
if (!Root.empty())
FC = std::make_shared<FileCollector>(Root, Root);
VFS = FileCollector::createCollectorVFS(vfs::getRealFileSystem(), FC);
FC = std::make_shared<FileCollector>(Root, Root, RealFS);
VFS = FileCollector::createCollectorVFS(std::move(RealFS), FC);
}

ReproducerGenerate::~ReproducerGenerate() {
Expand Down
Loading