Nicer parsing of dependencies file

This commit is contained in:
Kovid Goyal
2017-09-30 12:25:03 +05:30
parent af99c172fe
commit a783325464

View File

@@ -212,22 +212,21 @@ def newer(dest, *sources):
def dependecies_for(src, obj, all_headers): def dependecies_for(src, obj, all_headers):
dep_file = obj.rpartition('.')[0] + '.d' dep_file = obj.rpartition('.')[0] + '.d'
try: try:
deps = open(dep_file).read().splitlines() deps = open(dep_file).read()
except FileNotFoundError: except FileNotFoundError:
yield src yield src
yield from iter(all_headers) yield from iter(all_headers)
else: else:
for line in deps: RE_INC = re.compile(r'^(?P<target>.+?):\s+(?P<deps>.+?)$', re.MULTILINE)
if ':' in line: SPACE_TOK = '\x1B'
continue
line = line.rstrip('\\') text = deps.replace('\\\n', ' ').replace('\\ ', SPACE_TOK)
parts = line.split(' ') for match in RE_INC.finditer(text):
for part in parts: files = (f.replace(SPACE_TOK, ' ') for f in match.group('deps').split())
part = part.strip() for path in files:
if part: path = os.path.abspath(path)
path = os.path.abspath(part.strip()) if path.startswith(base):
if path.startswith(base): yield path
yield path
def compile_c_extension(module, incremental, sources, headers): def compile_c_extension(module, incremental, sources, headers):