未验证 提交 fcc4899b 编写于 作者: 还_没_想_好's avatar 还_没_想_好 提交者: GitHub

[tools] Add Python 3 compatibility patch (#5825)

上级 9fa8c78c
...@@ -190,7 +190,7 @@ def IARVersion(): ...@@ -190,7 +190,7 @@ def IARVersion():
return path return path
path = IARPath(); path = IARPath()
if os.path.exists(path): if os.path.exists(path):
cmd = os.path.join(path, 'iccarm.exe') cmd = os.path.join(path, 'iccarm.exe')
...@@ -200,7 +200,8 @@ def IARVersion(): ...@@ -200,7 +200,8 @@ def IARVersion():
child = subprocess.Popen([cmd, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) child = subprocess.Popen([cmd, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = child.communicate() stdout, stderr = child.communicate()
if not isinstance(stdout, str):
stdout = str(stdout, 'utf8') # Patch for Python 3
# example stdout: IAR ANSI C/C++ Compiler V8.20.1.14183/W32 for ARM # example stdout: IAR ANSI C/C++ Compiler V8.20.1.14183/W32 for ARM
iar_version = re.search('[\d\.]+', stdout).group(0) iar_version = re.search('[\d\.]+', stdout).group(0)
if GetOption('verbose'): if GetOption('verbose'):
......
...@@ -191,7 +191,7 @@ class Folder(object): ...@@ -191,7 +191,7 @@ class Folder(object):
else: else:
assert False, 'Unkown instance:%s' % str(c) assert False, 'Unkown instance:%s' % str(c)
name = bytes(c.bin_name) name = bytes(c.bin_name.encode('utf-8'))
name_addr = v_len name_addr = v_len
v_len += len(name) v_len += len(name)
...@@ -200,7 +200,7 @@ class Folder(object): ...@@ -200,7 +200,7 @@ class Folder(object):
# pad the data to 4 bytes boundary # pad the data to 4 bytes boundary
pad_len = 4 pad_len = 4
if len(data) % pad_len != 0: if len(data) % pad_len != 0:
data += '\0' * (pad_len - len(data) % pad_len) data += ('\0' * (pad_len - len(data) % pad_len)).encode('utf-8')
v_len += len(data) v_len += len(data)
d_li.append(self.bin_fmt.pack(*self.bin_item( d_li.append(self.bin_fmt.pack(*self.bin_item(
...@@ -232,7 +232,7 @@ const struct romfs_dirent {name} = {{ ...@@ -232,7 +232,7 @@ const struct romfs_dirent {name} = {{
def get_bin_data(tree, base_addr): def get_bin_data(tree, base_addr):
v_len = base_addr + Folder.bin_fmt.size v_len = base_addr + Folder.bin_fmt.size
name = bytes('/\0\0\0') name = bytes('/\0\0\0'.encode("utf-8"))
name_addr = v_len name_addr = v_len
v_len += len(name) v_len += len(name)
data_addr = v_len data_addr = v_len
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册