Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Bug 915642 - Allow simple variable references in includedeps files; r…
Browse files Browse the repository at this point in the history
…=gps
  • Loading branch information
glandium committed Sep 12, 2013
1 parent 8dcb47b commit 9e68e1d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pymake/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,13 @@ def parsefile(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 = []
Expand All @@ -394,12 +397,29 @@ def continuation_iter(lines):
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):
Expand Down
1 change: 1 addition & 0 deletions tests/includedeps-variables.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$(FILE)1: filemissing
10 changes: 10 additions & 0 deletions tests/includedeps-variables.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#T gmake skip

FILE = includedeps-variables

all: $(FILE)1

includedeps $(TESTPATH)/includedeps-variables.deps

filemissing:
@echo TEST-PASS

0 comments on commit 9e68e1d

Please sign in to comment.