summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2018-05-17 16:12:38 +0000
committerGreg Clayton <gclayton@apple.com>2018-05-17 16:12:38 +0000
commit39d50b72ea3c8db416ba9087a06eedf5d5a0dcb5 (patch)
treebefeefc70863d5c0b10cdf1a9d56c81d629f57e6 /lldb
parent6a53023b4e1230609691377c33263de6667522c8 (diff)
downloadbcm5719-llvm-39d50b72ea3c8db416ba9087a06eedf5d5a0dcb5.tar.gz
bcm5719-llvm-39d50b72ea3c8db416ba9087a06eedf5d5a0dcb5.zip
FileSpec objects that resolve to "." should have "." in m_filename and m_directory empty.
After switching to LLVM normalization, if we init FileSpec with "." we would end up with m_directory being NULL and m_filename being "". This patch fixes this by allowing the path to be normalized and if it normalized to nothing, set it to m_filename. Differential Revision: https://reviews.llvm.org/D46783 llvm-svn: 332618
Diffstat (limited to 'lldb')
-rw-r--r--lldb/source/Utility/FileSpec.cpp8
-rw-r--r--lldb/unittests/Utility/FileSpecTest.cpp10
2 files changed, 14 insertions, 4 deletions
diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp
index 02fd82cc54d..944f01d9000 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -258,6 +258,14 @@ void FileSpec::SetFile(llvm::StringRef pathname, bool resolve, Style style) {
if (m_style == Style::windows)
std::replace(resolved.begin(), resolved.end(), '\\', '/');
+ if (resolved.empty()) {
+ // If we have no path after normalization set the path to the current
+ // directory. This matches what python does and also a few other path
+ // utilities.
+ m_filename.SetString(".");
+ return;
+ }
+
m_filename.SetString(llvm::sys::path::filename(resolved, m_style));
llvm::StringRef dir = llvm::sys::path::parent_path(resolved, m_style);
if (!dir.empty())
diff --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp
index 08c47df4e5c..63afdc90be4 100644
--- a/lldb/unittests/Utility/FileSpecTest.cpp
+++ b/lldb/unittests/Utility/FileSpecTest.cpp
@@ -199,9 +199,10 @@ TEST(FileSpecTest, GetNormalizedPath) {
{"/..", "/"},
{"/.", "/"},
{"..", ".."},
- {".", ""},
+ {".", "."},
+ {"", "."},
{"../..", "../.."},
- {"foo/..", ""},
+ {"foo/..", "."},
{"foo/../bar", "bar"},
{"../foo/..", ".."},
{"./foo", "foo"},
@@ -230,17 +231,18 @@ TEST(FileSpecTest, GetNormalizedPath) {
{R"(\..)", R"(\..)"},
// {R"(c:..)", R"(c:..)"},
{R"(..)", R"(..)"},
- {R"(.)", R"()"},
+ {R"(.)", R"(.)"},
// TODO: fix llvm::sys::path::remove_dots() to return "c:\" below.
{R"(c:..\..)", R"(c:\..\..)"},
{R"(..\..)", R"(..\..)"},
- {R"(foo\..)", R"()"},
+ {R"(foo\..)", R"(.)"},
{R"(foo\..\bar)", R"(bar)"},
{R"(..\foo\..)", R"(..)"},
{R"(.\foo)", R"(foo)"},
{R"(.\.\foo)", R"(foo)"},
{R"(..\foo)", R"(..\foo)"},
{R"(..\..\foo)", R"(..\..\foo)"},
+ {"", "."},
};
for (auto test : windows_tests) {
EXPECT_EQ(test.second,
OpenPOWER on IntegriCloud