diff options
| author | Dan Willemsen <dwillemsen@google.com> | 2017-11-22 22:42:40 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2017-11-22 22:42:40 +0000 |
| commit | 824a4f395debd92cb8ff93056eb890a4a1af5516 (patch) | |
| tree | f93b9088085aa04a23bd10bf0502dccbafebea18 | |
| parent | 4ef2ff2ff61c3df090e18613f8d4ec10bba3f916 (diff) | |
| parent | 4d0441d470dbef8b6d31dbe6e3c785865c6dd8b4 (diff) | |
| download | platform_build_kati-824a4f395debd92cb8ff93056eb890a4a1af5516.tar.gz platform_build_kati-824a4f395debd92cb8ff93056eb890a4a1af5516.tar.bz2 platform_build_kati-824a4f395debd92cb8ff93056eb890a4a1af5516.zip | |
Merge remote-tracking branch 'aosp/upstream'
am: 4d0441d470
Change-Id: Iee69cf9aa8ad6a08d5832a46cc244626760b2262
| -rw-r--r-- | eval.cc | 23 | ||||
| -rw-r--r-- | eval.h | 3 | ||||
| -rw-r--r-- | regen_dump.cc | 51 | ||||
| -rw-r--r-- | symtab.cc | 7 | ||||
| -rw-r--r-- | symtab.h | 1 | ||||
| -rwxr-xr-x | testcase/ninja_regen.sh | 20 | ||||
| -rw-r--r-- | var.cc | 7 | ||||
| -rw-r--r-- | var.h | 1 |
8 files changed, 105 insertions, 8 deletions
@@ -72,20 +72,23 @@ Var* Evaluator::EvalRHS(Symbol lhs, : VarOrigin::FILE)); Var* rhs = NULL; - Var* prev = LookupVarInCurrentScope(lhs); + Var* prev = NULL; bool needs_assign = true; switch (op) { case AssignOp::COLON_EQ: { + prev = PeekVarInCurrentScope(lhs); SimpleVar* sv = new SimpleVar(origin); rhs_v->Eval(this, sv->mutable_value()); rhs = sv; break; } case AssignOp::EQ: + prev = PeekVarInCurrentScope(lhs); rhs = new RecursiveVar(rhs_v, origin, orig_rhs); break; case AssignOp::PLUS_EQ: { + prev = LookupVarInCurrentScope(lhs); if (!prev->IsDefined()) { rhs = new RecursiveVar(rhs_v, origin, orig_rhs); } else if (prev->ReadOnly()) { @@ -99,6 +102,7 @@ Var* Evaluator::EvalRHS(Symbol lhs, break; } case AssignOp::QUESTION_EQ: { + prev = LookupVarInCurrentScope(lhs); if (!prev->IsDefined()) { rhs = new RecursiveVar(rhs_v, origin, orig_rhs); } else { @@ -109,10 +113,12 @@ Var* Evaluator::EvalRHS(Symbol lhs, } } - prev->Used(this, lhs); - if (prev->Deprecated()) { - if (needs_assign) { - rhs->SetDeprecated(prev->DeprecatedMessage()); + if (prev != NULL) { + prev->Used(this, lhs); + if (prev->Deprecated()) { + if (needs_assign) { + rhs->SetDeprecated(prev->DeprecatedMessage()); + } } } @@ -392,6 +398,13 @@ Var* Evaluator::LookupVarInCurrentScope(Symbol name) { return LookupVarGlobal(name); } +Var* Evaluator::PeekVarInCurrentScope(Symbol name) { + if (current_scope_) { + return current_scope_->Peek(name); + } + return name.PeekGlobalVar(); +} + string Evaluator::EvalVar(Symbol name) { return LookupVar(name)->Eval(this); } @@ -105,6 +105,9 @@ class Evaluator { Var* LookupVarGlobal(Symbol name); + // Equivalent to LookupVarInCurrentScope, but doesn't mark as used. + Var* PeekVarInCurrentScope(Symbol name); + unordered_map<Symbol, Vars*> rule_vars_; vector<const Rule*> rules_; unordered_map<Symbol, bool> exports_; diff --git a/regen_dump.cc b/regen_dump.cc index f596f90..255add1 100644 --- a/regen_dump.cc +++ b/regen_dump.cc @@ -28,12 +28,31 @@ #include "strutil.h" int main(int argc, char* argv[]) { + bool dump_files = false; + bool dump_env = false; + if (argc == 1) { - fprintf(stderr, "Usage: ckati_stamp_dump <stamp>\n"); + fprintf(stderr, "Usage: ckati_stamp_dump [--env] [--files] <stamp>\n"); return 1; } - FILE* fp = fopen(argv[1], "rb"); + for (int i = 1; i < argc - 1; i++) { + const char* arg = argv[i]; + if (!strcmp(arg, "--env")) { + dump_env = true; + } else if (!strcmp(arg, "--files")) { + dump_files = true; + } else { + fprintf(stderr, "Unknown option: %s", arg); + return 1; + } + } + + if (!dump_files && !dump_env) { + dump_files = true; + } + + FILE* fp = fopen(argv[argc - 1], "rb"); if (!fp) PERROR("fopen"); @@ -50,7 +69,33 @@ int main(int argc, char* argv[]) { string s; if (!LoadString(fp, &s)) ERROR("Incomplete stamp file"); - printf("%s\n", s.c_str()); + if (dump_files) + printf("%s\n", s.c_str()); + } + + int num_undefineds = LoadInt(fp); + if (num_undefineds < 0) + ERROR("Incomplete stamp file"); + for (int i = 0; i < num_undefineds; i++) { + string s; + if (!LoadString(fp, &s)) + ERROR("Incomplete stamp file"); + if (dump_env) + printf("undefined: %s\n", s.c_str()); + } + + int num_envs = LoadInt(fp); + if (num_envs < 0) + ERROR("Incomplete stamp file"); + for (int i = 0; i < num_envs; i++) { + string name; + string val; + if (!LoadString(fp, &name)) + ERROR("Incomplete stamp file"); + if (!LoadString(fp, &val)) + ERROR("Incomplete stamp file"); + if (dump_env) + printf("%s: %s\n", name.c_str(), val.c_str()); } return 0; @@ -43,6 +43,13 @@ Symbol kShellSym = Symbol(Symbol::IsUninitialized()); Symbol::Symbol(int v) : v_(v) {} +Var* Symbol::PeekGlobalVar() const { + if (static_cast<size_t>(v_) >= g_symbol_data.size()) { + return kUndefined; + } + return g_symbol_data[v_].gv; +} + Var* Symbol::GetGlobalVar() const { if (static_cast<size_t>(v_) >= g_symbol_data.size()) { g_symbol_data.resize(v_ + 1); @@ -49,6 +49,7 @@ class Symbol { bool IsValid() const { return v_ >= 0; } + Var* PeekGlobalVar() const; Var* GetGlobalVar() const; void SetGlobalVar(Var* v, bool is_override = false, diff --git a/testcase/ninja_regen.sh b/testcase/ninja_regen.sh index 7f9b35e..5a1c0ff 100755 --- a/testcase/ninja_regen.sh +++ b/testcase/ninja_regen.sh @@ -39,10 +39,12 @@ fi sleep_if_necessary 1 cat <<EOF > Makefile +VAR3 := unused all: echo bar echo VAR=\$(VAR) echo VAR2=\$(VAR2) + echo VAR3=\$(VAR3) echo wildcard=\$(wildcard *.mk) other: echo foo @@ -74,6 +76,24 @@ if [ -e ninja.sh ]; then ./ninja.sh fi +export VAR3=testing +${mk} 2> ${log} +if [ -e ninja.sh ]; then + if grep regenerating ${log} >/dev/null; then + echo 'Should not regenerate (unused env added)' + fi + ./ninja.sh +fi + +export VAR3=test2 +${mk} 2> ${log} +if [ -e ninja.sh ]; then + if grep regenerating ${log} >/dev/null; then + echo 'Should not regenerate (unused env changed)' + fi + ./ninja.sh +fi + export PATH=/random_path:$PATH ${mk} 2> ${log} if [ -e ninja.sh ]; then @@ -136,6 +136,13 @@ Var* Vars::Lookup(Symbol name) const { return v; } +Var* Vars::Peek(Symbol name) const { + auto found = find(name); + if (found == end()) + return kUndefined; + return found->second; +} + void Vars::Assign(Symbol name, Var* v, bool* readonly) { *readonly = false; auto p = emplace(name, v); @@ -190,6 +190,7 @@ class Vars : public unordered_map<Symbol, Var*> { ~Vars(); Var* Lookup(Symbol name) const; + Var* Peek(Symbol name) const; void Assign(Symbol name, Var* v, bool* readonly); |
