[llvm] 190df4a - Revert "[FileCollector] Add a method to add a whole directory and it contents."

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 27 19:21:57 PDT 2020


Author: Jonas Devlieghere
Date: 2020-03-27T19:21:48-07:00
New Revision: 190df4a5bc241b379bbc38f6eda1c777939235d6

URL: https://github.com/llvm/llvm-project/commit/190df4a5bc241b379bbc38f6eda1c777939235d6
DIFF: https://github.com/llvm/llvm-project/commit/190df4a5bc241b379bbc38f6eda1c777939235d6.diff

LOG: Revert "[FileCollector] Add a method to add a whole directory and it contents."

This reverts commit 8913769e353a171ba01fa8ce9d598e979b620be9 because the
unit test is failing on the Windows bot.

Added: 
    

Modified: 
    llvm/include/llvm/Support/FileCollector.h
    llvm/lib/Support/FileCollector.cpp
    llvm/unittests/Support/FileCollectorTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/FileCollector.h b/llvm/include/llvm/Support/FileCollector.h
index 1b6383ef8cc2..079fe3efab9d 100644
--- a/llvm/include/llvm/Support/FileCollector.h
+++ b/llvm/include/llvm/Support/FileCollector.h
@@ -18,7 +18,7 @@
 #include <mutex>
 
 namespace llvm {
-class FileCollectorFileSystem;
+
 /// Collects files into a directory and generates a mapping that can be used by
 /// the VFS.
 class FileCollector {
@@ -26,10 +26,9 @@ class FileCollector {
   FileCollector(std::string Root, std::string OverlayRoot);
 
   void addFile(const Twine &file);
-  void addDirectory(const Twine &Dir);
 
   /// Write the yaml mapping (for the VFS) to the given file.
-  std::error_code writeMapping(StringRef MappingFile);
+  std::error_code writeMapping(StringRef mapping_file);
 
   /// Copy the files into the root directory.
   ///
@@ -45,7 +44,7 @@ class FileCollector {
                      std::shared_ptr<FileCollector> Collector);
 
 private:
-  friend FileCollectorFileSystem;
+  void addFileImpl(StringRef SrcPath);
 
   bool markAsSeen(StringRef Path) {
     if (Path.empty())
@@ -56,19 +55,10 @@ class FileCollector {
   bool getRealPath(StringRef SrcPath, SmallVectorImpl<char> &Result);
 
   void addFileToMapping(StringRef VirtualPath, StringRef RealPath) {
-    if (sys::fs::is_directory(VirtualPath))
-      VFSWriter.addDirectoryMapping(VirtualPath, RealPath);
-    else
-      VFSWriter.addFileMapping(VirtualPath, RealPath);
+    VFSWriter.addFileMapping(VirtualPath, RealPath);
   }
 
 protected:
-  void addFileImpl(StringRef SrcPath);
-
-  llvm::vfs::directory_iterator
-  addDirectoryImpl(const llvm::Twine &Dir,
-                   IntrusiveRefCntPtr<vfs::FileSystem> FS, std::error_code &EC);
-
   /// Synchronizes adding files.
   std::mutex Mutex;
 

diff  --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp
index f6d72685a8c3..3a8bc99327bc 100644
--- a/llvm/lib/Support/FileCollector.cpp
+++ b/llvm/lib/Support/FileCollector.cpp
@@ -61,19 +61,13 @@ bool FileCollector::getRealPath(StringRef SrcPath,
   return true;
 }
 
-void FileCollector::addFile(const Twine &File) {
+void FileCollector::addFile(const Twine &file) {
   std::lock_guard<std::mutex> lock(Mutex);
-  std::string FileStr = File.str();
+  std::string FileStr = file.str();
   if (markAsSeen(FileStr))
     addFileImpl(FileStr);
 }
 
-void FileCollector::addDirectory(const Twine &Dir) {
-  assert(sys::fs::is_directory(Dir));
-  std::error_code EC;
-  addDirectoryImpl(Dir, vfs::getRealFileSystem(), EC);
-}
-
 void FileCollector::addFileImpl(StringRef SrcPath) {
   // We need an absolute src path to append to the root.
   SmallString<256> AbsoluteSrc = SrcPath;
@@ -107,27 +101,6 @@ void FileCollector::addFileImpl(StringRef SrcPath) {
   addFileToMapping(VirtualPath, DstPath);
 }
 
-llvm::vfs::directory_iterator
-FileCollector::addDirectoryImpl(const llvm::Twine &Dir,
-                                IntrusiveRefCntPtr<vfs::FileSystem> FS,
-                                std::error_code &EC) {
-  auto It = FS->dir_begin(Dir, EC);
-  if (EC)
-    return It;
-  addFile(Dir);
-  for (; !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) {
-    if (It->type() == sys::fs::file_type::regular_file ||
-        It->type() == sys::fs::file_type::directory_file ||
-        It->type() == sys::fs::file_type::symlink_file) {
-      addFile(It->path());
-    }
-  }
-  if (EC)
-    return It;
-  // Return a new iterator.
-  return FS->dir_begin(Dir, EC);
-}
-
 /// Set the access and modification time for the given file from the given
 /// status object.
 static std::error_code
@@ -198,7 +171,7 @@ std::error_code FileCollector::copyFiles(bool StopOnError) {
   return {};
 }
 
-std::error_code FileCollector::writeMapping(StringRef MappingFile) {
+std::error_code FileCollector::writeMapping(StringRef mapping_file) {
   std::lock_guard<std::mutex> lock(Mutex);
 
   VFSWriter.setOverlayDir(OverlayRoot);
@@ -206,7 +179,7 @@ std::error_code FileCollector::writeMapping(StringRef MappingFile) {
   VFSWriter.setUseExternalNames(false);
 
   std::error_code EC;
-  raw_fd_ostream os(MappingFile, EC, sys::fs::OF_Text);
+  raw_fd_ostream os(mapping_file, EC, sys::fs::OF_Text);
   if (EC)
     return EC;
 
@@ -215,7 +188,7 @@ std::error_code FileCollector::writeMapping(StringRef MappingFile) {
   return {};
 }
 
-namespace llvm {
+namespace {
 
 class FileCollectorFileSystem : public vfs::FileSystem {
 public:
@@ -240,7 +213,22 @@ class FileCollectorFileSystem : public vfs::FileSystem {
 
   llvm::vfs::directory_iterator dir_begin(const llvm::Twine &Dir,
                                           std::error_code &EC) override {
-    return Collector->addDirectoryImpl(Dir, FS, EC);
+    auto It = FS->dir_begin(Dir, EC);
+    if (EC)
+      return It;
+    // Collect everything that's listed in case the user needs it.
+    Collector->addFile(Dir);
+    for (; !EC && It != llvm::vfs::directory_iterator(); It.increment(EC)) {
+      if (It->type() == sys::fs::file_type::regular_file ||
+          It->type() == sys::fs::file_type::directory_file ||
+          It->type() == sys::fs::file_type::symlink_file) {
+        Collector->addFile(It->path());
+      }
+    }
+    if (EC)
+      return It;
+    // Return a new iterator.
+    return FS->dir_begin(Dir, EC);
   }
 
   std::error_code getRealPath(const Twine &Path,
@@ -271,7 +259,7 @@ class FileCollectorFileSystem : public vfs::FileSystem {
   std::shared_ptr<FileCollector> Collector;
 };
 
-} // namespace llvm
+} // end anonymous namespace
 
 IntrusiveRefCntPtr<vfs::FileSystem>
 FileCollector::createCollectorVFS(IntrusiveRefCntPtr<vfs::FileSystem> BaseFS,

diff  --git a/llvm/unittests/Support/FileCollectorTest.cpp b/llvm/unittests/Support/FileCollectorTest.cpp
index 7b8e1c5f95a5..42a4877dba39 100644
--- a/llvm/unittests/Support/FileCollectorTest.cpp
+++ b/llvm/unittests/Support/FileCollectorTest.cpp
@@ -120,29 +120,6 @@ TEST(FileCollectorTest, addFile) {
   EXPECT_FALSE(FileCollector.hasSeen("/path/to/d"));
 }
 
-TEST(FileCollectorTest, addDirectory) {
-  ScopedDir file_root("file_root", true);
-  ScopedFile a(file_root + "/aaa");
-  ScopedFile b(file_root + "/bbb");
-  ScopedFile c(file_root + "/ccc");
-
-  std::string root_fs = std::string(file_root.Path.str());
-  TestingFileCollector FileCollector(root_fs, root_fs);
-
-  FileCollector.addDirectory(file_root.Path);
-
-  // Make sure the root is correct.
-  EXPECT_EQ(FileCollector.Root, root_fs);
-
-  // Make sure we've seen all the added files.
-  EXPECT_TRUE(FileCollector.hasSeen(a.Path));
-  EXPECT_TRUE(FileCollector.hasSeen(b.Path));
-  EXPECT_TRUE(FileCollector.hasSeen(c.Path));
-
-  // Make sure we've only seen the added files.
-  EXPECT_FALSE(FileCollector.hasSeen("/file_root/ddd"));
-}
-
 TEST(FileCollectorTest, copyFiles) {
   ScopedDir file_root("file_root", true);
   ScopedFile a(file_root + "/aaa");


        


More information about the llvm-commits mailing list