28 : state_(state), file_reader_(file_reader) {
37 *err =
"loading '" + filename +
"': " + read_err;
39 parent->
Error(
string(*err), err);
48 contents.resize(contents.size() + 1);
50 return Parse(filename, contents, err);
80 if (!
ParseLet(&name, &let_value, err))
85 if (name ==
"ninja_required_version")
123 return lexer_.
Error(
"duplicate pool '" + name +
"'", err);
133 if (key ==
"depth") {
135 depth = atol(depth_string.c_str());
139 return lexer_.
Error(
"unexpected variable '" + key +
"'", err);
144 return lexer_.
Error(
"expected 'depth =' line", err);
160 return lexer_.
Error(
"duplicate rule '" + name +
"'", err);
175 return lexer_.
Error(
"unexpected variable '" + key +
"'", err);
179 if (rule->
bindings_[
"rspfile"].empty() !=
180 rule->
bindings_[
"rspfile_content"].empty()) {
181 return lexer_.
Error(
"rspfile and rspfile_content need to be "
182 "both specified", err);
186 return lexer_.
Error(
"expected 'command =' line", err);
220 }
while (!eval.
empty());
229 vector<EvalString> ins, outs;
244 }
while (!out.
empty());
252 return lexer_.
Error(
"expected build command name", err);
256 return lexer_.
Error(
"unknown build rule '" + rule_name +
"'", err);
316 if (!pool_name.empty()) {
319 return lexer_.
Error(
"unknown pool name '" + pool_name +
"'", err);
323 for (vector<EvalString>::iterator i = ins.begin(); i != ins.end(); ++i) {
324 string path = i->Evaluate(env);
330 for (vector<EvalString>::iterator i = outs.begin(); i != outs.end(); ++i) {
331 string path = i->Evaluate(env);
342 if (!deps_type.empty() && edge->
outputs_.size() > 1) {
343 return lexer_.
Error(
"multiple outputs aren't (yet?) supported by depslog; "
344 "bring this up on the mailing list if it affects you",
375 if (token != expected) {
void AddIn(Edge *edge, StringPiece path)
static bool IsReservedBinding(const string &var)
bool Load(const string &filename, string *err, Lexer *parent=NULL)
Load and parse a file.
virtual bool ReadFile(const string &path, string *content, string *err)=0
bool ParsePool(string *err)
Parse various statement types.
Pool * LookupPool(const string &pool_name)
void UnreadToken()
Rewind to the last read Token.
static const char * TokenErrorHint(Token expected)
Return a human-readable token hint, used in error messages.
bool PeekToken(Token token)
If the next token is token, read it and return true.
An edge in the dependency graph; links between Nodes using Rules.
bool Error(const string &message, string *err)
Construct an error message with context.
void CheckNinjaVersion(const string &version)
Check whether version is compatible with the current Ninja version, aborting if not.
bool CanonicalizePath(string *path, string *err)
Canonicalize a path like "foo/../bar.h" into just "bar.h".
Token ReadToken()
Read a Token from the Token enum.
bool ReadPath(EvalString *path, string *err)
Read a path (complete with $escapes).
Edge * AddEdge(const Rule *rule)
An Env which contains a mapping of variables to values as well as a pointer to a parent scope...
void AddOut(Edge *edge, StringPiece path)
bool ParseEdge(string *err)
void AddRule(const Rule *rule)
An invokable build command and associated metadata (description, etc.).
string DescribeLastError()
If the last token read was an ERROR token, provide more info or the empty string. ...
A pool for delayed edges.
bool ParseLet(string *key, EvalString *val, string *err)
#define METRIC_RECORD(name)
The primary interface to metrics.
bool ReadIdent(string *out)
Read a simple identifier (a rule or variable name).
void AddBinding(const string &key, const EvalString &val)
bool ExpectToken(Lexer::Token expected, string *err)
If the next token is not expected, produce an error string saying "expectd foo, got bar"...
bool ReadVarValue(EvalString *value, string *err)
Read the value side of a var = value line (complete with $escapes).
bool AddDefault(StringPiece path, string *error)
string GetBinding(const string &key)
Returns the shell-escaped value of |key|.
bool ParseRule(string *err)
void AddBinding(const string &key, const string &val)
static const char * TokenName(Token t)
Return a human-readable form of a token, used in error messages.
Global state (file status, loaded rules) for a single run.
map< string, EvalString > bindings_
FileReader * file_reader_
string Evaluate(Env *env) const
bool ParseFileInclude(bool new_scope, string *err)
Parse either a 'subninja' or 'include' line.
A tokenized string that contains variable references.
bool Parse(const string &filename, const string &input, string *err)
Parse a file, given its contents as a string.
bool ParseDefault(string *err)
const Rule * LookupRule(const string &rule_name)
void Start(StringPiece filename, StringPiece input)
Start parsing some input.
ManifestParser(State *state, FileReader *file_reader)
vector< Node * > outputs_