[PATCH] D113272: [Support] [VirtualFileSystem] Detect the windows_slash path style
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 8 12:22:13 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG46ec93a457b0: [Support] [VirtualFileSystem] Detect the windows_slash path style (authored by mstorsjo).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113272/new/
https://reviews.llvm.org/D113272
Files:
llvm/lib/Support/VirtualFileSystem.cpp
Index: llvm/lib/Support/VirtualFileSystem.cpp
===================================================================
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -1041,9 +1041,10 @@
// Detect the path style in use by checking the first separator.
llvm::sys::path::Style style = llvm::sys::path::Style::native;
const size_t n = Path.find_first_of("/\\");
+ // Can't distinguish between posix and windows_slash here.
if (n != static_cast<size_t>(-1))
style = (Path[n] == '/') ? llvm::sys::path::Style::posix
- : llvm::sys::path::Style::windows;
+ : llvm::sys::path::Style::windows_backslash;
return style;
}
@@ -1189,8 +1190,10 @@
}
std::error_code RedirectingFileSystem::makeAbsolute(SmallVectorImpl<char> &Path) const {
+ // is_absolute(..., Style::windows_*) accepts paths with both slash types.
if (llvm::sys::path::is_absolute(Path, llvm::sys::path::Style::posix) ||
- llvm::sys::path::is_absolute(Path, llvm::sys::path::Style::windows))
+ llvm::sys::path::is_absolute(Path,
+ llvm::sys::path::Style::windows_backslash))
return {};
auto WorkingDir = getCurrentWorkingDirectory();
@@ -1201,9 +1204,15 @@
// is native and there is no way to override that. Since we know WorkingDir
// is absolute, we can use it to determine which style we actually have and
// append Path ourselves.
- sys::path::Style style = sys::path::Style::windows;
+ sys::path::Style style = sys::path::Style::windows_backslash;
if (sys::path::is_absolute(WorkingDir.get(), sys::path::Style::posix)) {
style = sys::path::Style::posix;
+ } else {
+ // Distinguish between windows_backslash and windows_slash; getExistingStyle
+ // returns posix for a path with windows_slash.
+ if (getExistingStyle(WorkingDir.get()) !=
+ sys::path::Style::windows_backslash)
+ style = sys::path::Style::windows_slash;
}
std::string Result = WorkingDir.get();
@@ -1621,8 +1630,9 @@
// which style we have, and use it consistently.
if (sys::path::is_absolute(Name, sys::path::Style::posix)) {
path_style = sys::path::Style::posix;
- } else if (sys::path::is_absolute(Name, sys::path::Style::windows)) {
- path_style = sys::path::Style::windows;
+ } else if (sys::path::is_absolute(Name,
+ sys::path::Style::windows_backslash)) {
+ path_style = sys::path::Style::windows_backslash;
} else {
assert(NameValueNode && "Name presence should be checked earlier");
error(NameValueNode,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113272.385590.patch
Type: text/x-patch
Size: 2677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211108/9b0b898d/attachment.bin>
More information about the llvm-commits
mailing list