aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Becker <stefanb@gpartner-nvidia.com>2016-04-07 13:29:23 +0300
committerStefan Becker <stefanb@gpartner-nvidia.com>2016-04-12 12:31:46 +0300
commit29b9b7470cc33c2b7c4264f254335d788ef04c26 (patch)
tree021c5e8704caa412e83558a91b1bf8f6cc3a039e
parent167e1f750dfed276d50ad93ebf0ce0a1f6e6f9ac (diff)
downloadandroid_build_kati-29b9b7470cc33c2b7c4264f254335d788ef04c26.tar.gz
android_build_kati-29b9b7470cc33c2b7c4264f254335d788ef04c26.tar.bz2
android_build_kati-29b9b7470cc33c2b7c4264f254335d788ef04c26.zip
[C++] Honor "override" when setting global variable
Regression when compared to GNU make behaviour. Test case: $ cat Makefile.override-failure $(info VAR: '$(VAR)') override VAR := test $(info VAR: '$(VAR)') override VAR := test-new $(info VAR: '$(VAR)') VAR := test-should-not-work $(info VAR: '$(VAR)') $ make -f Makefile.override-failure VAR: '' VAR: 'test' VAR: 'test-new' VAR: 'test-new' make: *** No targets. Stop. $ ckati -c --warn -f Makefile.override-failure VAR: '' VAR: 'test' VAR: 'test' VAR: 'test' *** No targets. Fixes https://github.com/google/kati/issues/50 Change-Id: I9c4185c30cfcf5602da7e0ac98b7e9c420788005
-rw-r--r--eval.cc3
-rw-r--r--symtab.cc9
-rw-r--r--symtab.h2
3 files changed, 9 insertions, 5 deletions
diff --git a/eval.cc b/eval.cc
index 6322fc1..bc27af9 100644
--- a/eval.cc
+++ b/eval.cc
@@ -101,7 +101,8 @@ void Evaluator::EvalAssign(const AssignStmt* stmt) {
Var* rhs = EvalRHS(lhs, stmt->rhs, stmt->orig_rhs, stmt->op,
stmt->directive == AssignDirective::OVERRIDE);
if (rhs)
- lhs.SetGlobalVar(rhs);
+ lhs.SetGlobalVar(rhs,
+ stmt->directive == AssignDirective::OVERRIDE);
}
void Evaluator::EvalRule(const RuleStmt* stmt) {
diff --git a/symtab.cc b/symtab.cc
index fb81bfe..edb6752 100644
--- a/symtab.cc
+++ b/symtab.cc
@@ -18,6 +18,8 @@
#include "symtab.h"
+#include <iostream>
+
#ifdef ENABLE_TID_CHECK
#include <pthread.h>
#endif
@@ -59,13 +61,14 @@ Var* Symbol::GetGlobalVar() const {
return v;
}
-void Symbol::SetGlobalVar(Var* v) const {
+void Symbol::SetGlobalVar(Var* v, bool is_override) const {
if (static_cast<size_t>(v_) >= g_symbol_data.size()) {
g_symbol_data.resize(v_ + 1);
}
Var* orig = g_symbol_data[v_].gv;
- if (orig->Origin() == VarOrigin::OVERRIDE ||
- orig->Origin() == VarOrigin::ENVIRONMENT_OVERRIDE) {
+ if (!is_override &&
+ (orig->Origin() == VarOrigin::OVERRIDE ||
+ orig->Origin() == VarOrigin::ENVIRONMENT_OVERRIDE)) {
return;
}
if (orig->Origin() == VarOrigin::AUTOMATIC) {
diff --git a/symtab.h b/symtab.h
index d1de4e1..e7e71d5 100644
--- a/symtab.h
+++ b/symtab.h
@@ -56,7 +56,7 @@ class Symbol {
bool IsValid() const { return v_ >= 0; }
Var* GetGlobalVar() const;
- void SetGlobalVar(Var* v) const;
+ void SetGlobalVar(Var* v, bool is_override = false) const;
private:
explicit Symbol(int v);