Add support for commands specified on the same line as the rule.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Thu, 05 Feb 2009 22:38:27 -0500
changeset 47 23711d02d7b002a6058095530390f6d8070ce3e7
parent 46 2b81cff1aa0a0670f0a890b1e0b4b8e330571843
child 48 f1e67b0fcf5dd5153ecaf04c986382010a0af3f3
push id27
push userbsmedberg@mozilla.com
push dateFri, 06 Feb 2009 03:38:33 +0000
Add support for commands specified on the same line as the rule.
pymake/parser.py
tests/line-continuations.mk
--- a/pymake/parser.py
+++ b/pymake/parser.py
@@ -272,26 +272,32 @@ def parsestream(fd, filename, makefile):
 
                 ispatterns = set((t.ispattern() for t in targets))
                 if len(ispatterns) == 2:
                     raise SyntaxError("Mixed implicit and normal rule", d.getloc(0))
                 ispattern, = ispatterns
 
                 stoppedat += 1
                 e, stoppedat = parsemakesyntax(d, stoppedat, ':=|;', iscommand=False)
-                if stoppedat == -1:
+                if stoppedat == -1 or d[stoppedat] == ';':
                     prereqs = data.splitwords(e.resolve(makefile.variables, None))
                     if ispattern:
                         currule = data.PatternRule(targets, map(data.Pattern, prereqs), doublecolon)
                         makefile.appendimplicitrule(currule)
                     else:
                         currule = data.Rule(prereqs, doublecolon)
                         for t in targets:
                             makefile.gettarget(t.gettarget()).addrule(currule)
                         makefile.foundtarget(targets[0].gettarget())
+
+                    if stoppedat != -1:
+                        e, stoppedat = parsemakesyntax(d, stoppedat + 1, '', iscommand=True)
+                        assert stoppedat == -1
+                        e.lstrip()
+                        currule.addcommand(e)
                 elif d[stoppedat] == '=' or d[stoppedat:stoppedat+2] == ':=':
                     isrecursive = d[stoppedat] == '='
                     e.lstrip()
                     e.rstrip()
                     vname = e.resolve(makefile.variables, None)
                     value, stoppedat = parsemakesyntax(d, stoppedat + (isrecursive and 1 or 2), '', iscommand=False)
                     assert stoppedat == -1
                     value.lstrip()
@@ -299,18 +305,16 @@ def parsestream(fd, filename, makefile):
                     if ispattern:
                         for target in targets:
                             setvariable(makefile.getpatternvariables(target), vname, isrecursive, value)
                     else:
                         for target in targets:
                             setvariable(makefile.gettarget(target.gettarget()).variables, vname, isrecursive, value)
                 elif d[stoppedat] == '|':
                     raise NotImplementedError('order-only prerequisites not implemented')
-                elif d[stoppedat] == ';':
-                    raise NotImplementedError('rule after command not implemented')
                 else:
                     assert d[stoppedat] == ':'
 
                     # static pattern rule
                     if ispattern:
                         raise SyntaxError("static pattern rules must have static targets")
 
                     patstr = e.resolve(makefile.variables, None)
@@ -324,18 +328,20 @@ def parsestream(fd, filename, makefile):
                     prereqs = map(data.Pattern, data.splitwords(e.resolve(makefile.variables, None)))
                     currule = data.PatternRule([pattern], prereqs, doublecolon)
                     for t in targets:
                         makefile.gettarget(t.gettarget()).addrule(currule)
 
                     makefile.foundtarget(targets[0].gettarget())
 
                     if stoppedat != -1:
-                        assert d[stoppedat] == ';'
-                        raise NotImplementedError('rule after command not implemented')
+                        e, stoppedat = parsemakesyntax(d, stoppedat + 1, '', iscommand=True)
+                        assert stoppedat == -1
+                        e.lstrip()
+                        currule.addcommand(e)
 
 PARSESTATE_TOPLEVEL = 0    # at the top level
 PARSESTATE_FUNCTION = 1    # expanding a function call. data is function
 
 # For the following three, data is a tuple of Expansions: (varname, substfrom, substto)
 PARSESTATE_VARNAME = 2     # expanding a variable expansion.
 PARSESTATE_SUBSTFROM = 3   # expanding a variable expansion substitution "from" value
 PARSESTATE_SUBSTTO = 4     # expanding a variable expansion substitution "to" value
--- a/tests/line-continuations.mk
+++ b/tests/line-continuations.mk
@@ -1,14 +1,20 @@
 VAR = val1 	 \
   	  val2  
 
 VAR2 = val1space\
 val2
 
-all:
+all: otarget test.target
 	test "$(VAR)" = "val1 val2  "
 	test "$(VAR2)" = "val1space val2"
 	test "hello \
 	  world" = "hello   world"
 	test "hello" = \
 "hello"
 	@echo TEST-PASS
+
+otarget: ; test "hello\
+	world" = "helloworld"
+
+test.target: %.target: ; test "hello\
+	world" = "helloworld"