From 2449472941530bbe82a80e734261e312a76df56a Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Sun, 19 Dec 2010 15:02:22 -0800 Subject: [PATCH] remove special builddir --- manual.asciidoc | 24 ------------------------ src/ninja.cc | 1 - src/parsers.cc | 28 ++-------------------------- src/parsers.h | 4 ---- src/parsers_test.cc | 34 +++------------------------------- 5 files changed, 5 insertions(+), 86 deletions(-) diff --git a/manual.asciidoc b/manual.asciidoc index 40bbdc1..28112b2 100644 --- a/manual.asciidoc +++ b/manual.asciidoc @@ -208,30 +208,6 @@ rule cc the full command or its description; if a command fails, the full command line will always be printed before the command's output. -Special variables -~~~~~~~~~~~~~~~~~ -`builddir` is a directory for intermediate build output. (The name -comes from autoconf.) It is special in a few ways: - -1. It gets a shorter alias: `@`. -2. It is implicitly a directory and has a `/` appended if needed. -3. It may be used in the filenames of a `build` line. - -You must still be explicit in your rules. In the following -example, the files prefixed with `@` will end up in the `out/` -subdirectory. - ----------------- -builddir = out -build @intermediate_file: combine @generated_file source_file - -# Equivalent rule: -# build out/intermediate_file: combine out/generated_file source_file ----------------- - -XXX I hacked in a special `$root` only understood in builddir -- fix -the semantics here, is this path relative or absolute? - Evaluation and scoping ~~~~~~~~~~~~~~~~~~~~~~ XXX talk about where variables live, nested scopes etc diff --git a/src/ninja.cc b/src/ninja.cc index 8376d9a..5392fb3 100644 --- a/src/ninja.cc +++ b/src/ninja.cc @@ -74,7 +74,6 @@ int main(int argc, char** argv) { State state; RealFileReader file_reader; ManifestParser parser(&state, &file_reader); - parser.set_root(cwd); string err; if (!parser.Load(input_file, &err)) { fprintf(stderr, "error loading '%s': %s\n", input_file, err.c_str()); diff --git a/src/parsers.cc b/src/parsers.cc index c66b91b..0fbbec7 100644 --- a/src/parsers.cc +++ b/src/parsers.cc @@ -82,7 +82,7 @@ static bool IsIdentChar(char c) { ('a' <= c && c <= 'z') || ('+' <= c && c <= '9') || // +,-./ and numbers ('A' <= c && c <= 'Z') || - (c == '_') || (c == '@') || (c == '$'); + (c == '_') || (c == '$'); } bool Tokenizer::ExpectToken(Token::Type expected, string* err) { @@ -255,16 +255,7 @@ bool ManifestParser::Parse(const string& input, string* err) { string name, value; if (!ParseLet(&name, &value, err)) return false; - env_->AddBinding(name, value); - if (name == "builddir") { - builddir_ = value; - if (builddir_.substr(0, 5) == "$root") { - builddir_ = root_ + builddir_.substr(5); - } - if (!builddir_.empty() && builddir_[builddir_.size() - 1] != '/') - builddir_.push_back('/'); - } break; } case Token::TEOF: @@ -341,13 +332,6 @@ bool ManifestParser::ParseLet(string* name, string* value, string* err) { if (!tokenizer_.ReadToNewline(value, err)) return false; - // Do @ -> builddir substitution. - size_t ofs; - while ((ofs = value->find('@')) != string::npos) { - value->replace(ofs, 1, builddir_); - ofs += builddir_.size(); - } - return true; } @@ -450,7 +434,7 @@ bool ManifestParser::ParseEdge(string* err) { string eval_err; if (!eval.Parse(*i, &eval_err)) return tokenizer_.Error(eval_err, err); - *i = ExpandFile(eval.Evaluate(env)); + *i = CanonicalizePath(eval.Evaluate(env)); } } @@ -489,11 +473,3 @@ bool ManifestParser::ParseSubNinja(string* err) { return true; } - -string ManifestParser::ExpandFile(const string& file) { - string out = file; - if (!file.empty() && file[0] == '@') - out = builddir_ + file.substr(1); - return CanonicalizePath(out); -} - diff --git a/src/parsers.h b/src/parsers.h index fc20436..e3505c9 100644 --- a/src/parsers.h +++ b/src/parsers.h @@ -78,7 +78,6 @@ struct ManifestParser { }; ManifestParser(State* state, FileReader* file_reader); - void set_root(const string& root) { root_ = root; } bool Load(const string& filename, string* err); bool Parse(const string& input, string* err); @@ -88,14 +87,11 @@ struct ManifestParser { bool ParseEdge(string* err); bool ParseSubNinja(string* err); - string ExpandFile(const string& file); - State* state_; BindingEnv* env_; FileReader* file_reader_; Tokenizer tokenizer_; string builddir_; - string root_; // Absolute path to root ninja file. }; #endif // NINJA_PARSERS_H_ diff --git a/src/parsers_test.cc b/src/parsers_test.cc index f38e6dc..b1f58b4 100644 --- a/src/parsers_test.cc +++ b/src/parsers_test.cc @@ -241,46 +241,18 @@ TEST_F(ParserTest, Errors) { } } -TEST_F(ParserTest, BuildDir) { - ASSERT_NO_FATAL_FAILURE(AssertParse( -"default_test = @foo\n" -"builddir = out\n" -"rule cat\n" -" command = cat @otherfile $in > $out\n" -"build @bin: cat @a.o\n" -"build @a.o: cat a.cc\n")); - EXPECT_EQ("foo", state.bindings_.LookupVariable("default_test")); - ASSERT_TRUE(state.LookupNode("out/a.o")); - const Rule* rule = state.LookupRule("cat"); - ASSERT_TRUE(rule); - EXPECT_EQ("cat out/otherfile $in > $out", rule->command_.unparsed()); -} - -TEST_F(ParserTest, BuildDirRoot) { - ManifestParser parser(&state, this); - parser.set_root("/root_test"); - string err; - ASSERT_TRUE(parser.Parse( -"builddir = $root/out\n" -"rule cat\n" -" command = cat @otherfile $in > $out\n" -"build @a.o: cat a.cc\n", &err)); - ASSERT_EQ("", err); - ASSERT_TRUE(state.LookupNode("/root_test/out/a.o")); -} - TEST_F(ParserTest, SubNinja) { files_["test.ninja"] = "var = inner\n" - "build @inner: varref\n"; + "build $builddir/inner: varref\n"; ASSERT_NO_FATAL_FAILURE(AssertParse( "builddir = some_dir/\n" "rule varref\n" " command = varref $var\n" "var = outer\n" -"build @outer: varref\n" +"build $builddir/outer: varref\n" "subninja test.ninja\n" -"build @outer2: varref\n")); +"build $builddir/outer2: varref\n")); ASSERT_EQ(1, files_read_.size()); EXPECT_EQ("test.ninja", files_read_[0]); -- 2.7.4