[PATCH] D28444: Define sys::path::convert_to_slash.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 8 07:51:32 PST 2017


LGTM with the comment nit.

Rui Ueyama via Phabricator <reviews at reviews.llvm.org> writes:

> ruiu created this revision.
> ruiu added a reviewer: rafael.
> ruiu added a subscriber: llvm-commits.
>
> This patch moves convertToUnixPathSeparator from LLD to LLVM.
>
>
> https://reviews.llvm.org/D28444
>
> Files:
>   lld/include/lld/Core/Reproduce.h
>   lld/lib/Core/Reproduce.cpp
>   llvm/include/llvm/Support/Path.h
>   llvm/lib/Support/Path.cpp
>   llvm/lib/Support/TarWriter.cpp
>
> Index: llvm/lib/Support/TarWriter.cpp
> ===================================================================
> --- llvm/lib/Support/TarWriter.cpp
> +++ llvm/lib/Support/TarWriter.cpp
> @@ -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;
>  
> @@ -121,15 +122,6 @@
>    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) {
> @@ -145,7 +137,7 @@
>  // 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 (S.size() <= sizeof(UstarHeader::Name)) {
>      writeUstarHeader(OS, S, Data.size());
>    } else {
> Index: llvm/lib/Support/Path.cpp
> ===================================================================
> --- llvm/lib/Support/Path.cpp
> +++ llvm/lib/Support/Path.cpp
> @@ -736,6 +736,16 @@
>    return true;
>  }
>  
> +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
> +}
> +
>  } // end namespace path
>  
>  namespace fs {
> Index: llvm/include/llvm/Support/Path.h
> ===================================================================
> --- llvm/include/llvm/Support/Path.h
> +++ llvm/include/llvm/Support/Path.h
> @@ -450,6 +450,13 @@
>  /// @result True if path was changed
>  bool remove_dots(SmallVectorImpl<char> &path, bool remove_dot_dot = false);
>  
> +/// @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.
> +std::string convert_to_slash(StringRef path);
> +
>  } // end namespace path
>  } // end namespace sys
>  } // end namespace llvm
> Index: lld/lib/Core/Reproduce.cpp
> ===================================================================
> --- lld/lib/Core/Reproduce.cpp
> +++ lld/lib/Core/Reproduce.cpp
> @@ -39,7 +39,7 @@
>      Res = Root.substr(2);
>  
>    path::append(Res, path::relative_path(Abs));
> -  return convertToUnixPathSeparator(Res);
> +  return path::convert_to_slash(Res);
>  }
>  
>  // Quote a given string if it contains a space character.
> @@ -64,13 +64,3 @@
>      return K + V;
>    return K + " " + V;
>  }
> -
> -std::string lld::convertToUnixPathSeparator(StringRef S) {
> -#ifdef LLVM_ON_WIN32
> -  std::string Ret = S.str();
> -  std::replace(Ret.begin(), Ret.end(), '\\', '/');
> -  return Ret;
> -#else
> -  return S;
> -#endif
> -}
> Index: lld/include/lld/Core/Reproduce.h
> ===================================================================
> --- lld/include/lld/Core/Reproduce.h
> +++ lld/include/lld/Core/Reproduce.h
> @@ -34,9 +34,6 @@
>  
>  // Returns the string form of the given argument.
>  std::string toString(llvm::opt::Arg *Arg);
> -
> -// Replaces backslashes with slashes if Windows.
> -std::string convertToUnixPathSeparator(StringRef S);
>  }
>  
>  #endif


More information about the llvm-commits mailing list