scripts: make gcc-wrapper.py compatible with python 2.7 and 3
Python 3 requires parentheses in call to 'print', meanwhile
the 'line' could be bytes-like, let's decoding to str as utf-8.
This makes the gcc-wrapper.py compatible with both 2.7 and 3.
For example, a bytes-like string as below,
b'kernel/reboot.c:47:13: error: function declaration isn\xe2\x80\x99t a
prototype [-Werror=strict-prototypes]\n'
b' static void no_use()\n'
b' ^~~~~~\n'
After decoding, it looks like,
kernel/reboot.c:47:13: error: function declaration isn’t a prototype
[-Werror=strict-prototypes]
static void no_use()
^~~~~~
Change-Id: Icacdbe2ca7b7ab674ab90e54b79d3176e0061ac6
Signed-off-by: Shunqian Zheng <zhengsq@rock-chips.com>
Signed-off-by: Tao Huang <huangtao@rock-chips.com>
diff --git a/scripts/gcc-wrapper.py b/scripts/gcc-wrapper.py
index 672b504..3a4b766 100755
--- a/scripts/gcc-wrapper.py
+++ b/scripts/gcc-wrapper.py
@@ -30,6 +30,7 @@
# Invoke gcc, looking for warnings, and causing a failure if there are
# non-whitelisted warnings.
+from __future__ import print_function
import errno
import re
import os
@@ -58,13 +59,15 @@
# Capture the name of the object file, can find it.
ofile = None
+do_exit = False;
+
warning_re = re.compile(r'''(.*/|)([^/]+\.[a-z]+:\d+):(\d+:)? warning:''')
def interpret_warning(line):
"""Decode the message from gcc. The messages we care about have a filename, and a warning"""
line = line.rstrip('\n')
m = warning_re.match(line)
if m and m.group(2) not in allowed_warnings:
- print "error, forbidden warning:", m.group(2)
+ print ("error, forbidden warning:" + m.group(2))
# If there is a warning, remove any object if it exists.
if ofile:
@@ -72,7 +75,8 @@
os.remove(ofile)
except OSError:
pass
- sys.exit(1)
+ global do_exit
+ do_exit = True;
def run_gcc():
args = sys.argv[1:]
@@ -89,17 +93,19 @@
try:
proc = subprocess.Popen(args, stderr=subprocess.PIPE)
for line in proc.stderr:
- print line,
- interpret_warning(line)
+ print (line.decode("utf-8"), end="")
+ interpret_warning(line.decode("utf-8"))
+ if do_exit:
+ sys.exit(1)
result = proc.wait()
except OSError as e:
result = e.errno
if result == errno.ENOENT:
- print args[0] + ':',e.strerror
- print 'Is your PATH set correctly?'
+ print (args[0] + ':' + e.strerror)
+ print ('Is your PATH set correctly?')
else:
- print ' '.join(args), str(e)
+ print (' '.join(args) + str(e))
return result