On Windows, ninja didn't create needed paths first
authorPhilip Craig <philip@pobox.com>
Sun, 29 May 2011 18:24:46 +0000 (19:24 +0100)
committerEvan Martin <martine@danga.com>
Thu, 2 Jun 2011 22:54:20 +0000 (15:54 -0700)
Now it does. Still works as it should on linux too.

The canonical example that now works on Windows is:

builddir = build

rule copy
command = copy $in $out

build $builddir\fred\test.out: copy test.in

src/build_test.cc [changed mode: 0644->0755]
src/ninja_jumble.cc [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 5610d47..813521c
@@ -390,17 +390,26 @@ TEST_F(BuildTest, MissingTarget) {
 
 TEST_F(BuildTest, MakeDirs) {
   string err;
-  ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
-"build subdir/dir2/file: cat in1\n"));
 
+#ifdef WIN32
+  ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, "build subdir\\dir2\\file: cat in1\n"));
+  EXPECT_TRUE(builder_.AddTarget("subdir\\dir2\\file", &err));
+#else
+  ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, "build subdir/dir2/file: cat in1\n"));
   EXPECT_TRUE(builder_.AddTarget("subdir/dir2/file", &err));
+#endif
+
   EXPECT_EQ("", err);
   now_ = 0;  // Make all stat()s return file not found.
   EXPECT_TRUE(builder_.Build(&err));
   ASSERT_EQ("", err);
   ASSERT_EQ(2u, fs_.directories_made_.size());
   EXPECT_EQ("subdir", fs_.directories_made_[0]);
+#ifdef WIN32
+  EXPECT_EQ("subdir\\dir2", fs_.directories_made_[1]);
+#else
   EXPECT_EQ("subdir/dir2", fs_.directories_made_[1]);
+#endif
 }
 
 TEST_F(BuildTest, DepFileMissing) {
old mode 100644 (file)
new mode 100755 (executable)
index 34fcc6d..c4399d1
@@ -42,10 +42,17 @@ int RealDiskInterface::Stat(const string& path) {
 }
 
 string DirName(const string& path) {
-  string::size_type slash_pos = path.rfind('/');
+
+#ifdef WIN32
+  const char kPathSeparator = '\\';
+#else
+  const char kPathSeparator = '/';
+#endif
+    
+  string::size_type slash_pos = path.rfind(kPathSeparator);
   if (slash_pos == string::npos)
     return "";  // Nothing to do.
-  while (slash_pos > 0 && path[slash_pos - 1] == '/')
+  while (slash_pos > 0 && path[slash_pos - 1] == kPathSeparator)
     --slash_pos;
   return path.substr(0, slash_pos);
 }