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>
This commit is contained in:
committed by
Tao Huang
parent
0658b84702
commit
41c170c42f
@@ -30,6 +30,7 @@
|
|||||||
# Invoke gcc, looking for warnings, and causing a failure if there are
|
# Invoke gcc, looking for warnings, and causing a failure if there are
|
||||||
# non-whitelisted warnings.
|
# non-whitelisted warnings.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import errno
|
import errno
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@@ -58,13 +59,15 @@ allowed_warnings = set([
|
|||||||
# Capture the name of the object file, can find it.
|
# Capture the name of the object file, can find it.
|
||||||
ofile = None
|
ofile = None
|
||||||
|
|
||||||
|
do_exit = False;
|
||||||
|
|
||||||
warning_re = re.compile(r'''(.*/|)([^/]+\.[a-z]+:\d+):(\d+:)? warning:''')
|
warning_re = re.compile(r'''(.*/|)([^/]+\.[a-z]+:\d+):(\d+:)? warning:''')
|
||||||
def interpret_warning(line):
|
def interpret_warning(line):
|
||||||
"""Decode the message from gcc. The messages we care about have a filename, and a warning"""
|
"""Decode the message from gcc. The messages we care about have a filename, and a warning"""
|
||||||
line = line.rstrip('\n')
|
line = line.rstrip('\n')
|
||||||
m = warning_re.match(line)
|
m = warning_re.match(line)
|
||||||
if m and m.group(2) not in allowed_warnings:
|
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 there is a warning, remove any object if it exists.
|
||||||
if ofile:
|
if ofile:
|
||||||
@@ -72,7 +75,8 @@ def interpret_warning(line):
|
|||||||
os.remove(ofile)
|
os.remove(ofile)
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
sys.exit(1)
|
global do_exit
|
||||||
|
do_exit = True;
|
||||||
|
|
||||||
def run_gcc():
|
def run_gcc():
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
@@ -89,17 +93,19 @@ def run_gcc():
|
|||||||
try:
|
try:
|
||||||
proc = subprocess.Popen(args, stderr=subprocess.PIPE)
|
proc = subprocess.Popen(args, stderr=subprocess.PIPE)
|
||||||
for line in proc.stderr:
|
for line in proc.stderr:
|
||||||
print line,
|
print (line.decode("utf-8"), end="")
|
||||||
interpret_warning(line)
|
interpret_warning(line.decode("utf-8"))
|
||||||
|
if do_exit:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
result = proc.wait()
|
result = proc.wait()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
result = e.errno
|
result = e.errno
|
||||||
if result == errno.ENOENT:
|
if result == errno.ENOENT:
|
||||||
print args[0] + ':',e.strerror
|
print (args[0] + ':' + e.strerror)
|
||||||
print 'Is your PATH set correctly?'
|
print ('Is your PATH set correctly?')
|
||||||
else:
|
else:
|
||||||
print ' '.join(args), str(e)
|
print (' '.join(args) + str(e))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user