From a783325464ca9a525e2b3b120487571ef2d69c9b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 30 Sep 2017 12:25:03 +0530 Subject: [PATCH] Nicer parsing of dependencies file --- setup.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 4fa204dee..8e00a47f7 100755 --- a/setup.py +++ b/setup.py @@ -212,22 +212,21 @@ def newer(dest, *sources): def dependecies_for(src, obj, all_headers): dep_file = obj.rpartition('.')[0] + '.d' try: - deps = open(dep_file).read().splitlines() + deps = open(dep_file).read() except FileNotFoundError: yield src yield from iter(all_headers) else: - for line in deps: - if ':' in line: - continue - line = line.rstrip('\\') - parts = line.split(' ') - for part in parts: - part = part.strip() - if part: - path = os.path.abspath(part.strip()) - if path.startswith(base): - yield path + RE_INC = re.compile(r'^(?P.+?):\s+(?P.+?)$', re.MULTILINE) + SPACE_TOK = '\x1B' + + text = deps.replace('\\\n', ' ').replace('\\ ', SPACE_TOK) + for match in RE_INC.finditer(text): + files = (f.replace(SPACE_TOK, ' ') for f in match.group('deps').split()) + for path in files: + path = os.path.abspath(path) + if path.startswith(base): + yield path def compile_c_extension(module, incremental, sources, headers):