diff options
author | Philip Craig <philip@pobox.com> | 2011-05-29 18:24:46 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-06-02 22:54:20 (GMT) |
commit | 2048bb4ad953fada2c8f9a35c62bad86286d2c08 (patch) | |
tree | ef7dc64f9e4374d1e90c212cfbc686e44870c281 | |
parent | 9f55f1c3a82543273739a6f57bd3965895dd892f (diff) | |
download | Ninja-2048bb4ad953fada2c8f9a35c62bad86286d2c08.zip Ninja-2048bb4ad953fada2c8f9a35c62bad86286d2c08.tar.gz Ninja-2048bb4ad953fada2c8f9a35c62bad86286d2c08.tar.bz2 |
On Windows, ninja didn't create needed paths first
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
-rwxr-xr-x[-rw-r--r--] | src/build_test.cc | 13 | ||||
-rwxr-xr-x[-rw-r--r--] | src/ninja_jumble.cc | 11 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/build_test.cc b/src/build_test.cc index 5610d47..813521c 100644..100755 --- a/src/build_test.cc +++ b/src/build_test.cc @@ -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) { diff --git a/src/ninja_jumble.cc b/src/ninja_jumble.cc index 34fcc6d..c4399d1 100644..100755 --- a/src/ninja_jumble.cc +++ b/src/ninja_jumble.cc @@ -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); } |