Bug 751076 - fix $< and $^ for pymake; r=bsmedberg
authorMike Shal <mshal@mozilla.com>
Tue, 09 Jul 2013 10:14:16 -0400
changeset 345 4502b185d064c231b3d2d13f11a18317dd3f3055
parent 344 211b0c4298e397526bd87af4fc080d2ca819f921
child 346 1cf15f6116e805227b1ff50e794408f67055e700
push id218
push usermshal@mozilla.com
push dateWed, 10 Jul 2013 23:55:05 +0000
reviewersbsmedberg
bugs751076
Bug 751076 - fix $< and $^ for pymake; r=bsmedberg
pymake/data.py
tests/multiple-rules-prerequisite-merge.mk
--- a/pymake/data.py
+++ b/pymake/data.py
@@ -1469,18 +1469,30 @@ class Rule(object):
         self.weakdeps = weakdeps
 
     def addcommand(self, c):
         assert isinstance(c, (Expansion, StringExpansion))
         self.commands.append(c)
 
     def getcommands(self, target, makefile):
         assert isinstance(target, Target)
+        # Prerequisites are merged if the target contains multiple rules and is
+        # not a terminal (double colon) rule. See
+        # https://www.gnu.org/software/make/manual/make.html#Multiple-Targets.
+        prereqs = []
+        prereqs.extend(self.prerequisites)
 
-        return getcommandsforrule(self, target, makefile, self.prerequisites, stem=None)
+        if not self.doublecolon:
+            for rule in target.rules:
+                # The current rule comes first, which is already in prereqs so
+                # we don't need to add it again.
+                if rule != self:
+                    prereqs.extend(rule.prerequisites)
+
+        return getcommandsforrule(self, target, makefile, prereqs, stem=None)
         # TODO: $* in non-pattern rules?
 
 class PatternRuleInstance(object):
     weakdeps = False
 
     """
     A pattern rule instantiated for a particular target. It has the same API as Rule, but
     different internals, forwarding most information on to the PatternRule.
new file mode 100644
--- /dev/null
+++ b/tests/multiple-rules-prerequisite-merge.mk
@@ -0,0 +1,25 @@
+# When a target is defined multiple times, the prerequisites should get
+# merged.
+
+default: foo bar baz
+
+foo:
+	test "$<" = "foo.in1"
+	@echo TEST-PASS
+
+foo: foo.in1
+
+bar: bar.in1
+	test "$<" = "bar.in1"
+	test "$^" = "bar.in1 bar.in2"
+	@echo TEST-PASS
+
+bar: bar.in2
+
+baz: baz.in2
+baz: baz.in1
+	test "$<" = "baz.in1"
+	test "$^" = "baz.in1 baz.in2"
+	@echo TEST-PASS
+
+foo.in1 bar.in1 bar.in2 baz.in1 baz.in2: