Fix test/override.mk
diff --git a/ast.go b/ast.go
index f623c39..f4dd83f 100644
--- a/ast.go
+++ b/ast.go
@@ -43,6 +43,7 @@
lhs string
rhs string
cmds []string
+ cmdLineno int
}
func (ast *RuleAST) eval(ev *Evaluator) {
diff --git a/eval.go b/eval.go
index acaf588..23b4a83 100644
--- a/eval.go
+++ b/eval.go
@@ -10,6 +10,9 @@
output string
inputs []string
cmds []string
+ filename string
+ lineno int
+ cmdLineno int
}
type EvalResult struct {
@@ -125,7 +128,11 @@
ev.filename = ast.filename
ev.lineno = ast.lineno
- ev.curRule = &Rule{}
+ ev.curRule = &Rule{
+ filename: ast.filename,
+ lineno: ast.lineno,
+ cmdLineno: ast.cmdLineno,
+ }
lhs := ev.evalExpr(ast.lhs)
ev.curRule.output = lhs
rhs := ev.evalExpr(ast.rhs)
diff --git a/exec.go b/exec.go
index 43920de..f5a1053 100644
--- a/exec.go
+++ b/exec.go
@@ -98,10 +98,18 @@
}
for _, rule := range er.rules {
- if _, present := ex.rules[rule.output]; present {
- Warn("overiding recipie for target %q", rule.output)
+ if oldRule, present := ex.rules[rule.output]; present {
+ if len(oldRule.cmds) > 0 && len(rule.cmds) > 0 {
+ Warn(rule.filename, rule.cmdLineno, "overriding recipe for target '%s'", rule.output)
+ Warn(oldRule.filename, oldRule.cmdLineno, "ignoring old recipe for target '%s'", oldRule.output)
+ }
+ r := &Rule{}
+ *r = *rule
+ r.inputs = append(r.inputs, oldRule.inputs...)
+ ex.rules[rule.output] = r
+ } else {
+ ex.rules[rule.output] = rule
}
- ex.rules[rule.output] = rule
}
if len(targets) == 0 {
diff --git a/log.go b/log.go
index be5b681..6d931e8 100644
--- a/log.go
+++ b/log.go
@@ -13,12 +13,9 @@
fmt.Printf(buf.String(), a...)
}
-func Warn(f string, a ...interface{}) {
- var buf bytes.Buffer
- buf.WriteString("warning: ")
- buf.WriteString(f)
- buf.WriteByte('\n')
- fmt.Printf(buf.String(), a...)
+func Warn(filename string, lineno int, f string, a ...interface{}) {
+ f = fmt.Sprintf("%s:%d: warning: %s\n", filename, lineno, f)
+ fmt.Printf(f, a...)
}
func Error(f string, a ...interface{}) {
diff --git a/parser.go b/parser.go
index 5fff8aa..3f9c5a2 100644
--- a/parser.go
+++ b/parser.go
@@ -106,6 +106,7 @@
}
ast.filename = p.filename
ast.lineno = p.lineno
+ ast.cmdLineno = p.elineno + 1
for {
line := p.readLine()
if len(line) == 0 {
diff --git a/test/override.mk b/test/override.mk
index e988c37..91b2054 100644
--- a/test/override.mk
+++ b/test/override.mk
@@ -1,5 +1,3 @@
-# TODO: fix
-
test: foo
echo FAIL