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

This commit is contained in:
Tangyuxin 2022-04-17 23:42:32 +08:00 committed by GitHub
parent 9fa8c78c9a
commit fcc4899b60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -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():
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'):

View File

@ -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):
# 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} = {{
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