From dfbe5b0bf13768c89006aeb1c63972d27a8d559f Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Sat, 23 Oct 2010 19:28:42 -0700 Subject: [PATCH] builddir --- manifest_parser.h | 20 +++++++++++++++++--- ninja_test.cc | 13 +++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/manifest_parser.h b/manifest_parser.h index 6b65437..4fb872d 100644 --- a/manifest_parser.h +++ b/manifest_parser.h @@ -84,7 +84,7 @@ static bool IsIdentChar(char c) { ('a' <= c && c <= 'z') || ('+' <= c && c <= '9') || // +,-./ and numbers ('A' <= c && c <= 'Z') || - (c == '_'); + (c == '_') || (c == '@'); } bool Parser::Token(const string& expected, string* err) { @@ -161,8 +161,11 @@ struct ManifestParser { bool ParseLet(string* err); bool ParseEdge(string* err); + string ExpandFile(const string& file); + State* state_; Parser parser_; + string builddir_; }; bool ManifestParser::Load(const string& filename, string* err) { @@ -246,6 +249,11 @@ bool ManifestParser::ParseLet(string* err) { return false; state_->AddBinding(name, value); + if (name == "builddir") { + builddir_ = value; + if (!builddir_.empty() && builddir_[builddir_.size() - 1] != '/') + builddir_.push_back('/'); + } return true; } @@ -262,7 +270,7 @@ bool ManifestParser::ParseEdge(string* err) { return parser_.Error("expected output file list", err); if (out == ":") break; - outs.push_back(out); + outs.push_back(ExpandFile(out)); } string rule_name; @@ -277,7 +285,7 @@ bool ManifestParser::ParseEdge(string* err) { string in; if (!parser_.ReadToken(&in)) break; - ins.push_back(in); + ins.push_back(ExpandFile(in)); } if (!parser_.Newline(err)) @@ -292,3 +300,9 @@ bool ManifestParser::ParseEdge(string* err) { return true; } +string ManifestParser::ExpandFile(const string& file) { + if (!file.empty() && file[0] == '@') + return builddir_ + file.substr(1); + return file; +} + diff --git a/ninja_test.cc b/ninja_test.cc index a00cfd9..949be66 100644 --- a/ninja_test.cc +++ b/ninja_test.cc @@ -105,6 +105,19 @@ TEST(Parser, Errors) { } } +TEST(Parser, BuildDir) { + State state; + ASSERT_NO_FATAL_FAILURE(AssertParse(&state, +"builddir = out\n" +"rule cat\n" +"command cat @in > $out\n" +"build @bin: cat @a.o\n" +"build @a.o: cat a.cc\n")); + state.stat_cache()->Dump(); + ASSERT_TRUE(state.LookupNode("out/a.o")); +} + + TEST(State, Basic) { State state; Rule* rule = state.AddRule("cat", "cat @in > $out"); -- 2.7.4