Bug 915642 - Allow simple variable references in includedeps files; r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 12 Sep 2013 22:05:34 +0900
changeset 353 5d83a8746631
parent 352 5809e5d90994
child 354 6410fa823a22
push id224
push usergszorc@mozilla.com
push dateThu, 12 Sep 2013 16:18:13 +0000
reviewersgps
bugs915642
Bug 915642 - Allow simple variable references in includedeps files; r=gps
pymake/parser.py
tests/includedeps-variables.deps
tests/includedeps-variables.mk
--- a/pymake/parser.py
+++ b/pymake/parser.py
@@ -369,42 +369,62 @@ def parsefile(pathname):
     makefiles that have already been parsed and have not changed.
     """
 
     pathname = os.path.realpath(pathname)
     return _parsecache.get(pathname)
 
 # colon followed by anything except a slash (Windows path detection)
 _depfilesplitter = re.compile(r':(?![\\/])')
+# simple variable references
+_vars = re.compile('\$\((\w+)\)')
 
 def parsedepfile(pathname):
     """
     Parse a filename listing only depencencies into a parserdata.StatementList.
+    Simple variable references are allowed in such files.
     """
     def continuation_iter(lines):
         current_line = []
         for line in lines:
             line = line.rstrip()
             if line.endswith("\\"):
                 current_line.append(line.rstrip("\\"))
                 continue
             if not len(line):
                 continue
             current_line.append(line)
             yield ''.join(current_line)
             current_line = []
         if current_line:
             yield ''.join(current_line)
 
+    def get_expansion(s):
+        if '$' in s:
+            expansion = data.Expansion()
+            # for an input like e.g. "foo $(bar) baz",
+            # _vars.split returns ["foo", "bar", "baz"]
+            # every other element is a variable name.
+            for i, element in enumerate(_vars.split(s)):
+                if i % 2:
+                    expansion.appendfunc(functions.VariableRef(None,
+                        data.StringExpansion(element, None)))
+                elif element:
+                    expansion.appendstr(element)
+
+            return expansion
+
+        return data.StringExpansion(s, None)
+
     pathname = os.path.realpath(pathname)
     stmts = parserdata.StatementList()
     for line in continuation_iter(open(pathname).readlines()):
         target, deps = _depfilesplitter.split(line, 1)
-        stmts.append(parserdata.Rule(data.StringExpansion(target, None),
-                                     data.StringExpansion(deps, None), False))
+        stmts.append(parserdata.Rule(get_expansion(target),
+                                     get_expansion(deps), False))
     return stmts
 
 def parsestring(s, filename):
     """
     Parse a string containing makefile data into a parserdata.StatementList.
     """
 
     currule = False
new file mode 100644
--- /dev/null
+++ b/tests/includedeps-variables.deps
@@ -0,0 +1,1 @@
+$(FILE)1: filemissing
new file mode 100644
--- /dev/null
+++ b/tests/includedeps-variables.mk
@@ -0,0 +1,10 @@
+#T gmake skip
+
+FILE = includedeps-variables
+
+all: $(FILE)1
+
+includedeps $(TESTPATH)/includedeps-variables.deps
+
+filemissing:
+	@echo TEST-PASS