[lld] r267602 - Move utility functions to DriverUtils.cpp.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 13:41:32 PDT 2016


Author: ruiu
Date: Tue Apr 26 15:41:32 2016
New Revision: 267602

URL: http://llvm.org/viewvc/llvm-project?rev=267602&view=rev
Log:
Move utility functions to DriverUtils.cpp.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Driver.h
    lld/trunk/ELF/DriverUtils.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=267602&r1=267601&r2=267602&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Apr 26 15:41:32 2016
@@ -99,33 +99,6 @@ LinkerDriver::getArchiveMembers(MemoryBu
   return V;
 }
 
-// Concatenates S and T so that the resulting path becomes S/T.
-// There are a few exceptions:
-//
-//  1. The result will never escape from S. Therefore, all ".."
-//     are removed from T before concatenatig them.
-//  2. Windows drive letters are removed from T before concatenation.
-static std::string concat(StringRef S, StringRef T) {
-  // Remove leading '/' or a drive letter, and then remove "..".
-  SmallString<128> T2(path::relative_path(T));
-  path::remove_dots(T2, /*remove_dot_dot=*/true);
-
-  SmallString<128> Res;
-  path::append(Res, S, T2);
-  return Res.str();
-}
-
-static void copyFile(StringRef Src, StringRef Dest) {
-  SmallString<128> Dir(Dest);
-  path::remove_filename(Dir);
-  if (std::error_code EC = sys::fs::create_directories(Dir)) {
-    error(EC, Dir + ": can't create directory");
-    return;
-  }
-  if (std::error_code EC = sys::fs::copy_file(Src, Dest))
-    error(EC, "failed to copy file: " + Dest);
-}
-
 // Opens and parses a file. Path has to be resolved already.
 // Newly created memory buffers are owned by this driver.
 void LinkerDriver::addFile(StringRef Path) {
@@ -133,7 +106,7 @@ void LinkerDriver::addFile(StringRef Pat
   if (Config->Verbose)
     llvm::outs() << Path << "\n";
   if (!Config->Reproduce.empty())
-    copyFile(Path, concat(Config->Reproduce, Path));
+    copyFile(Path, concat_paths(Config->Reproduce, Path));
 
   Optional<MemoryBufferRef> Buffer = readFile(Path);
   if (!Buffer.hasValue())

Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=267602&r1=267601&r2=267602&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Tue Apr 26 15:41:32 2016
@@ -67,6 +67,9 @@ enum {
 void printHelp(const char *Argv0);
 void printVersion();
 
+std::string concat_paths(StringRef S, StringRef T);
+void copyFile(StringRef Src, StringRef Dest);
+
 std::string findFromSearchPaths(StringRef Path);
 std::string searchLibrary(StringRef Path);
 std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=267602&r1=267601&r2=267602&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Tue Apr 26 15:41:32 2016
@@ -23,6 +23,7 @@
 #include "llvm/Support/StringSaver.h"
 
 using namespace llvm;
+using namespace llvm::sys;
 
 using namespace lld;
 using namespace lld::elf;
@@ -86,6 +87,33 @@ void elf::printVersion() {
   outs() << "\n";
 }
 
+// Concatenates S and T so that the resulting path becomes S/T.
+// There are a few exceptions:
+//
+//  1. The result will never escape from S. Therefore, all ".."
+//     are removed from T before concatenatig them.
+//  2. Windows drive letters are removed from T before concatenation.
+std::string elf::concat_paths(StringRef S, StringRef T) {
+  // Remove leading '/' or a drive letter, and then remove "..".
+  SmallString<128> T2(path::relative_path(T));
+  path::remove_dots(T2, /*remove_dot_dot=*/true);
+
+  SmallString<128> Res;
+  path::append(Res, S, T2);
+  return Res.str();
+}
+
+void elf::copyFile(StringRef Src, StringRef Dest) {
+  SmallString<128> Dir(Dest);
+  path::remove_filename(Dir);
+  if (std::error_code EC = sys::fs::create_directories(Dir)) {
+    error(EC, Dir + ": can't create directory");
+    return;
+  }
+  if (std::error_code EC = sys::fs::copy_file(Src, Dest))
+    error(EC, "failed to copy file: " + Dest);
+}
+
 std::string elf::findFromSearchPaths(StringRef Path) {
   for (StringRef Dir : Config->SearchPaths) {
     std::string FullPath = buildSysrootedPath(Dir, Path);




More information about the llvm-commits mailing list