Don't evaluate conditionals if they are initialized in an inactive conditional context.
authorBenjamin Smedberg <benjamin@smedbergs.us>
Tue, 17 Feb 2009 15:02:41 -0500
changeset 124 2545f3385285f5c19aec1cb0aae72658c8970229
parent 123 17169ca68e03996bb02d6707789659d1fae7df23
child 125 c8a5d22af41742f79b2df1f56503e60a0d51829c
push id69
push userbsmedberg@mozilla.com
push dateTue, 17 Feb 2009 20:06:47 +0000
Don't evaluate conditionals if they are initialized in an inactive conditional context.
pymake/parser.py
tests/ifdefs-nesting.mk
--- a/pymake/parser.py
+++ b/pymake/parser.py
@@ -632,18 +632,23 @@ def parsestream(fd, filename, makefile):
                         raise SyntaxError("Unexpected condition after 'else' directive.",
                                           d.getloc(offset))
                         
                     m = conditionkeywords[kword](d, offset, makefile)
                     condstack[-1].makeactive(m)
                 continue
 
             if kword in conditionkeywords:
-                m = conditionkeywords[kword](d, offset, makefile)
-                condstack.append(Condition(m, d.getloc(offset)))
+                if any((not c.active for c in condstack)):
+                    # If any conditions are currently false, we don't evaluate anything: just stick a dummy
+                    # condition on the stack
+                    condstack.append(Condition(True, d.getloc(offset)))
+                else:
+                    m = conditionkeywords[kword](d, offset, makefile)
+                    condstack.append(Condition(m, d.getloc(offset)))
                 continue
 
             if any((not c.active for c in condstack)):
                 log.debug('%s: skipping line because of active conditions' % (d.getloc(0),))
                 for c in itermakefilechars(d, offset, emptytokenlist):
                     pass
                 continue
 
new file mode 100644
--- /dev/null
+++ b/tests/ifdefs-nesting.mk
@@ -0,0 +1,8 @@
+ifdef RANDOM
+ifeq (,$(error Not evaluated!))
+VAR = val
+endif
+endif
+
+all:
+	@echo TEST-PASS