From 2e619cea453933f8ffda3984abfc650bf5815c32 Mon Sep 17 00:00:00 2001 From: Per Rosengren Date: Wed, 14 Sep 2016 22:12:23 +0200 Subject: [PATCH] Windows fix: normalizes extra_incdir, universal_newlines on preprocessor output. When input is a filename without directory, the dirname is empty, which inserts `-I `, instead of ` -I .`, which breaks the command. Remedied with os.path.normpath On Windows with MinGW gcc, preprocessor output has Windows newlines, which pycparser can't handle. Remedied by universal_newlines=True for subprocess. --- autopxd/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/autopxd/__init__.py b/autopxd/__init__.py index 20709bf..79e502d 100644 --- a/autopxd/__init__.py +++ b/autopxd/__init__.py @@ -303,9 +303,11 @@ def lines(self): def preprocess(code, extra_cpp_args=[]): - proc = subprocess.Popen([ - 'cpp', '-nostdinc', '-D__attribute__(x)=', '-I', BUILTIN_HEADERS_DIR, - ] + extra_cpp_args + ['-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + proc = subprocess.Popen( + ['cpp', '-nostdinc', '-D__attribute__(x)=', + '-I', BUILTIN_HEADERS_DIR] + + extra_cpp_args + ['-'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True) result = [] result.append(proc.communicate(input=code.encode('utf-8'))[0]) while proc.poll() is None: @@ -328,7 +330,7 @@ def parse(code, extra_cpp_args=[]): def translate(code, hdrname, extra_cpp_args=[]): - extra_incdir = os.path.dirname(hdrname) + extra_incdir = os.path.normpath(os.path.dirname(hdrname)) p = AutoPxd(hdrname) p.visit(parse(code, extra_cpp_args=['-I', extra_incdir])) return str(p)