Bug 915642 - Allow simple variable references in includedeps files; r=gps

This commit is contained in:
Mike Hommey 2013-09-12 22:05:34 +09:00
parent b3541e24ab
commit 2347d58a74
3 changed files with 33 additions and 2 deletions

View File

@ -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 = []
@ -394,12 +397,29 @@ def parsedepfile(pathname):
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):

View File

@ -0,0 +1 @@
$(FILE)1: filemissing

View File

@ -0,0 +1,10 @@
#T gmake skip
FILE = includedeps-variables
all: $(FILE)1
includedeps $(TESTPATH)/includedeps-variables.deps
filemissing:
@echo TEST-PASS