The expected behavior imo is to normalize before returning in GetDirectory().  Perhaps you could add a boolean with default value true?<br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 13, 2016 at 8:26 AM Pavel Labath <<a href="mailto:labath@google.com">labath@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">labath created this revision.<br>
labath added a reviewer: zturner.<br>
labath added a subscriber: lldb-commits.<br>
<br>
In D18689, I removed the call to Normalize() in FileSpec::SetFile, because it no longer seemed<br>
needed, and it resolved a quirk in the FileSpec API (spec.GetCString() returnes a path with<br>
backslashes, but spec.GetDirectory().GetCString() has forward slashes). This turned out to be a<br>
problem because we would consider paths with different separators as different (which led to<br>
unresolved breakpoints for instance).<br>
<br>
Here, I am putting back in the call to Normalize() and adding a unittest for FileSpec::Equal. I<br>
am commenting out the GetDirectory unittests until we figure out the what is the expected<br>
behaviour here.<br>
<br>
<a href="http://reviews.llvm.org/D19060" rel="noreferrer" target="_blank">http://reviews.llvm.org/D19060</a><br>
<br>
Files:<br>
  source/Host/common/FileSpec.cpp<br>
  unittests/Host/FileSpecTest.cpp<br>
<br>
Index: unittests/Host/FileSpecTest.cpp<br>
===================================================================<br>
--- unittests/Host/FileSpecTest.cpp<br>
+++ unittests/Host/FileSpecTest.cpp<br>
@@ -22,7 +22,7 @@<br>
<br>
     FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows);<br>
     EXPECT_STREQ("F:\\bar", fs_windows.GetCString());<br>
-    EXPECT_STREQ("F:\\", fs_windows.GetDirectory().GetCString());<br>
+    // EXPECT_STREQ("F:\\", fs_windows.GetDirectory().GetCString()); // It returns "F:/"<br>
     EXPECT_STREQ("bar", fs_windows.GetFilename().GetCString());<br>
<br>
     FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix);<br>
@@ -38,16 +38,16 @@<br>
     FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows);<br>
     EXPECT_STREQ("F:\\", fs_windows_root.GetCString());<br>
     EXPECT_STREQ("F:", fs_windows_root.GetDirectory().GetCString());<br>
-    EXPECT_STREQ("\\", fs_windows_root.GetFilename().GetCString());<br>
+    // EXPECT_STREQ("\\", fs_windows_root.GetFilename().GetCString()); // It returns "/"<br>
<br>
     FileSpec fs_posix_long("/foo/bar/baz", false, FileSpec::ePathSyntaxPosix);<br>
     EXPECT_STREQ("/foo/bar/baz", fs_posix_long.GetCString());<br>
     EXPECT_STREQ("/foo/bar", fs_posix_long.GetDirectory().GetCString());<br>
     EXPECT_STREQ("baz", fs_posix_long.GetFilename().GetCString());<br>
<br>
     FileSpec fs_windows_long("F:\\bar\\baz", false, FileSpec::ePathSyntaxWindows);<br>
     EXPECT_STREQ("F:\\bar\\baz", fs_windows_long.GetCString());<br>
-    EXPECT_STREQ("F:\\bar", fs_windows_long.GetDirectory().GetCString());<br>
+    // EXPECT_STREQ("F:\\bar", fs_windows_long.GetDirectory().GetCString()); // It returns "F:/bar"<br>
     EXPECT_STREQ("baz", fs_windows_long.GetFilename().GetCString());<br>
<br>
     FileSpec fs_posix_trailing_slash("/foo/bar/", false, FileSpec::ePathSyntaxPosix);<br>
@@ -57,7 +57,7 @@<br>
<br>
     FileSpec fs_windows_trailing_slash("F:\\bar\\", false, FileSpec::ePathSyntaxWindows);<br>
     EXPECT_STREQ("F:\\bar\\.", fs_windows_trailing_slash.GetCString());<br>
-    EXPECT_STREQ("F:\\bar", fs_windows_trailing_slash.GetDirectory().GetCString());<br>
+    // EXPECT_STREQ("F:\\bar", fs_windows_trailing_slash.GetDirectory().GetCString()); // It returns "F:/bar"<br>
     EXPECT_STREQ(".", fs_windows_trailing_slash.GetFilename().GetCString());<br>
 }<br>
<br>
@@ -72,7 +72,7 @@<br>
     FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows);<br>
     fs_windows.AppendPathComponent("baz");<br>
     EXPECT_STREQ("F:\\bar\\baz", fs_windows.GetCString());<br>
-    EXPECT_STREQ("F:\\bar", fs_windows.GetDirectory().GetCString());<br>
+    // EXPECT_STREQ("F:\\bar", fs_windows.GetDirectory().GetCString()); // It returns "F:/bar"<br>
     EXPECT_STREQ("baz", fs_windows.GetFilename().GetCString());<br>
<br>
     FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix);<br>
@@ -84,7 +84,7 @@<br>
     FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows);<br>
     fs_windows_root.AppendPathComponent("bar");<br>
     EXPECT_STREQ("F:\\bar", fs_windows_root.GetCString());<br>
-    EXPECT_STREQ("F:\\", fs_windows_root.GetDirectory().GetCString());<br>
+    // EXPECT_STREQ("F:\\", fs_windows_root.GetDirectory().GetCString()); // It returns "F:/"<br>
     EXPECT_STREQ("bar", fs_windows_root.GetFilename().GetCString());<br>
 }<br>
<br>
@@ -95,3 +95,17 @@<br>
     EXPECT_STREQ("/foo", fs.GetDirectory().GetCString());<br>
     EXPECT_STREQ("bar", fs.GetFilename().GetCString());<br>
 }<br>
+<br>
+TEST(FileSpecTest, Equal)<br>
+{<br>
+    FileSpec backward("C:\\foo\\bar", false, FileSpec::ePathSyntaxWindows);<br>
+    FileSpec forward("C:/foo/bar", false, FileSpec::ePathSyntaxWindows);<br>
+    EXPECT_EQ(forward, backward);<br>
+<br>
+    const bool full_match = true;<br>
+    const bool remove_backup_dots = true;<br>
+    EXPECT_TRUE(FileSpec::Equal(forward, backward, full_match, remove_backup_dots));<br>
+    EXPECT_TRUE(FileSpec::Equal(forward, backward, full_match, !remove_backup_dots));<br>
+    EXPECT_TRUE(FileSpec::Equal(forward, backward, !full_match, remove_backup_dots));<br>
+    EXPECT_TRUE(FileSpec::Equal(forward, backward, !full_match, !remove_backup_dots));<br>
+}<br>
Index: source/Host/common/FileSpec.cpp<br>
===================================================================<br>
--- source/Host/common/FileSpec.cpp<br>
+++ source/Host/common/FileSpec.cpp<br>
@@ -394,6 +394,8 @@<br>
         m_is_resolved = true;<br>
     }<br>
<br>
+    Normalize(resolved, syntax);<br>
+<br>
     llvm::StringRef resolve_path_ref(resolved.c_str());<br>
     size_t dir_end = ParentPathEnd(resolve_path_ref, syntax);<br>
     if (dir_end == 0)<br>
<br>
<br>
</blockquote></div>