[llvm] r291414 - Define sys::path::convert_to_slash
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 8 17:47:16 PST 2017
Author: ruiu
Date: Sun Jan 8 19:47:15 2017
New Revision: 291414
URL: http://llvm.org/viewvc/llvm-project?rev=291414&view=rev
Log:
Define sys::path::convert_to_slash
This patch moves convertToUnixPathSeparator from LLD to LLVM.
Differential Revision: https://reviews.llvm.org/D28444
Modified:
llvm/trunk/include/llvm/Support/Path.h
llvm/trunk/lib/Support/Path.cpp
llvm/trunk/lib/Support/TarWriter.cpp
Modified: llvm/trunk/include/llvm/Support/Path.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Path.h?rev=291414&r1=291413&r2=291414&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Path.h (original)
+++ llvm/trunk/include/llvm/Support/Path.h Sun Jan 8 19:47:15 2017
@@ -207,6 +207,14 @@ void native(const Twine &path, SmallVect
/// @param path A path that is transformed to native format.
void native(SmallVectorImpl<char> &path);
+/// @brief Replaces backslashes with slashes if Windows.
+///
+/// @param path processed path
+/// @result The result of replacing backslashes with forward slashes if Windows.
+/// On Unix, this function is a no-op because backslashes are valid path
+/// chracters.
+std::string convert_to_slash(StringRef path);
+
/// @}
/// @name Lexical Observers
/// @{
Modified: llvm/trunk/lib/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=291414&r1=291413&r2=291414&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Path.cpp (original)
+++ llvm/trunk/lib/Support/Path.cpp Sun Jan 8 19:47:15 2017
@@ -571,6 +571,16 @@ void native(SmallVectorImpl<char> &Path)
#endif
}
+std::string convert_to_slash(StringRef path) {
+#ifdef LLVM_ON_WIN32
+ std::string s = path.str();
+ std::replace(s.begin(), s.end(), '\\', '/');
+ return s;
+#else
+ return path;
+#endif
+}
+
StringRef filename(StringRef path) {
return *rbegin(path);
}
Modified: llvm/trunk/lib/Support/TarWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TarWriter.cpp?rev=291414&r1=291413&r2=291414&view=diff
==============================================================================
--- llvm/trunk/lib/Support/TarWriter.cpp (original)
+++ llvm/trunk/lib/Support/TarWriter.cpp Sun Jan 8 19:47:15 2017
@@ -26,6 +26,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/Path.h"
using namespace llvm;
@@ -147,15 +148,6 @@ static void writeUstarHeader(raw_fd_ostr
OS << StringRef(reinterpret_cast<char *>(&Hdr), sizeof(Hdr));
}
-// We want to use '/' as a path separator even on Windows.
-// This function canonicalizes a given path.
-static std::string canonicalize(std::string S) {
-#ifdef LLVM_ON_WIN32
- std::replace(S.begin(), S.end(), '\\', '/');
-#endif
- return S;
-}
-
// Creates a TarWriter instance and returns it.
Expected<std::unique_ptr<TarWriter>> TarWriter::create(StringRef OutputPath,
StringRef BaseDir) {
@@ -171,7 +163,7 @@ TarWriter::TarWriter(int FD, StringRef B
// Append a given file to an archive.
void TarWriter::append(StringRef Path, StringRef Data) {
// Write Path and Data.
- std::string S = BaseDir + "/" + canonicalize(Path) + "\0";
+ std::string S = BaseDir + "/" + sys::path::convert_to_slash(Path) + "\0";
if (fitsInUstar(S)) {
writeUstarHeader(OS, S, Data.size());
} else {
More information about the llvm-commits
mailing list