diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2021-10-21 18:33:24 -0700 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2021-10-29 12:09:41 -0700 |
commit | 99023627010bbfefb71e25a2b4d056de1cbd354e (patch) | |
tree | a7ad434f3071922aac052bf9eb23c29c577cb885 /clang/unittests/Basic/FileManagerTest.cpp | |
parent | 51ce567b38ec92163ec05c9bef0bd0e2bd53c667 (diff) | |
download | llvm-99023627010bbfefb71e25a2b4d056de1cbd354e.zip llvm-99023627010bbfefb71e25a2b4d056de1cbd354e.tar.gz llvm-99023627010bbfefb71e25a2b4d056de1cbd354e.tar.bz2 |
Support: Use sys::path::is_style_{posix,windows}() in a few places
Use the new sys::path::is_style_posix() and is_style_windows() in a few
places that need to detect the system's native path style.
In llvm/lib/Support/Path.cpp, this patch removes most uses of the
private `real_style()`, where is_style_posix() and is_style_windows()
are just a little tidier.
Elsewhere, this removes `_WIN32` macro checks. Added a FIXME to a
FileManagerTest that seemed fishy, but maintained the existing
behaviour.
Differential Revision: https://reviews.llvm.org/D112289
Diffstat (limited to 'clang/unittests/Basic/FileManagerTest.cpp')
-rw-r--r-- | clang/unittests/Basic/FileManagerTest.cpp | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index a122747..3c058a0 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -31,18 +31,18 @@ private: void InjectFileOrDirectory(const char *Path, ino_t INode, bool IsFile, const char *StatPath) { -#ifndef _WIN32 SmallString<128> NormalizedPath(Path); - llvm::sys::path::native(NormalizedPath); - Path = NormalizedPath.c_str(); - SmallString<128> NormalizedStatPath; - if (StatPath) { - NormalizedStatPath = StatPath; - llvm::sys::path::native(NormalizedStatPath); - StatPath = NormalizedStatPath.c_str(); + if (is_style_posix(llvm::sys::path::Style::native)) { + llvm::sys::path::native(NormalizedPath); + Path = NormalizedPath.c_str(); + + if (StatPath) { + NormalizedStatPath = StatPath; + llvm::sys::path::native(NormalizedStatPath); + StatPath = NormalizedStatPath.c_str(); + } } -#endif if (!StatPath) StatPath = Path; @@ -74,11 +74,11 @@ public: bool isFile, std::unique_ptr<llvm::vfs::File> *F, llvm::vfs::FileSystem &FS) override { -#ifndef _WIN32 SmallString<128> NormalizedPath(Path); - llvm::sys::path::native(NormalizedPath); - Path = NormalizedPath.c_str(); -#endif + if (is_style_posix(llvm::sys::path::Style::native)) { + llvm::sys::path::native(NormalizedPath); + Path = NormalizedPath.c_str(); + } if (StatCalls.count(Path) != 0) { Status = StatCalls[Path]; @@ -436,13 +436,16 @@ TEST_F(FileManagerTest, getVirtualFileWithDifferentName) { #endif // !_WIN32 +static StringRef getSystemRoot() { + return is_style_windows(llvm::sys::path::Style::native) ? "C:/" : "/"; +} + TEST_F(FileManagerTest, makeAbsoluteUsesVFS) { - SmallString<64> CustomWorkingDir; -#ifdef _WIN32 - CustomWorkingDir = "C:"; -#else - CustomWorkingDir = "/"; -#endif + // FIXME: Should this be using a root path / call getSystemRoot()? For now, + // avoiding that and leaving the test as-is. + SmallString<64> CustomWorkingDir = + is_style_windows(llvm::sys::path::Style::native) ? StringRef("C:") + : StringRef("/"); llvm::sys::path::append(CustomWorkingDir, "some", "weird", "path"); auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( @@ -464,12 +467,7 @@ TEST_F(FileManagerTest, makeAbsoluteUsesVFS) { // getVirtualFile should always fill the real path. TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) { - SmallString<64> CustomWorkingDir; -#ifdef _WIN32 - CustomWorkingDir = "C:/"; -#else - CustomWorkingDir = "/"; -#endif + SmallString<64> CustomWorkingDir = getSystemRoot(); auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( new llvm::vfs::InMemoryFileSystem); @@ -497,12 +495,7 @@ TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) { } TEST_F(FileManagerTest, getFileDontOpenRealPath) { - SmallString<64> CustomWorkingDir; -#ifdef _WIN32 - CustomWorkingDir = "C:/"; -#else - CustomWorkingDir = "/"; -#endif + SmallString<64> CustomWorkingDir = getSystemRoot(); auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>( new llvm::vfs::InMemoryFileSystem); |