google / kati

An experimental GNU make clone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[PATCH] "override VAR := <value>" only works once

stefanb2 opened this issue · comments

Regression 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-no-override
$(info VAR: '$(VAR)')
VAR := test-no-override-new
$(info VAR: '$(VAR)')

$ make VAR=old -f Makefile.override-failure
VAR: 'old'
VAR: 'test'
VAR: 'test-new'
VAR: 'test-new'
VAR: 'test-new'
make: *** No targets.  Stop.

$ ckati -c --warn VAR=old -f Makefile.override-failure
VAR: 'old'
VAR: 'test'
VAR: 'test'
VAR: 'test'
VAR: 'test'
*** No targets.

It doesn't matter if the variable is set on the command line or not:

$ ckati -c --warn -f Makefile.override-failure
VAR: ''
VAR: 'test'
VAR: 'test'

With this hack I can work around the issue for my test case:

--- a/symtab.cc
+++ b/symtab.cc
@@ -64,7 +64,7 @@ void Symbol::SetGlobalVar(Var* v) const {
     g_symbol_data.resize(v_ + 1);
   }
   Var* orig = g_symbol_data[v_].gv;
-  if (orig->Origin() == VarOrigin::OVERRIDE ||
+  if (// orig->Origin() == VarOrigin::OVERRIDE ||
       orig->Origin() == VarOrigin::ENVIRONMENT_OVERRIDE) {
     return;
   }

but that solution is definitely not correct:

$ 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-new'
VAR: 'test-should-not-work'
*** No targets.

If I understand the code correctly then "override" handling is implemented incorrectly, at least for assignements. The override is only applied to the RHS, but not the LHS. IMHO "override" should only apply to the LHS.

I think I found the solution. It passes the test case correctly.
0001-Fix-https-github.com-google-kati-issues-50.txt