[APISETS] Make update.py Python3-compatible

This commit is contained in:
Thomas Faber 2021-11-13 12:53:35 -05:00
parent 252a7530d0
commit 82efa2792f

View file

@ -29,9 +29,9 @@ FUNCTION_BLACKLIST = [
]
SPEC_HEADER = [
'\n',
'# This file is autogenerated by update.py\n',
'\n'
b'\n',
b'# This file is autogenerated by update.py\n',
b'\n'
]
ALIAS_DLL = {
@ -258,7 +258,7 @@ class SpecEntry(object):
assert self._ord != '@'
name = 'Ordinal' + self._ord
if not self._forwarder:
spec_file.write('{} stub{} {}{}'.format(self._ord, opts, name, NL_CHAR))
spec_file.write('{} stub{} {}{}'.format(self._ord, opts, name, NL_CHAR).encode('utf-8'))
estimate_size += 0x1000
else:
assert self.arch != Arch(), self.name
@ -279,7 +279,7 @@ class SpecEntry(object):
name=name,
args=args,
fwd=fwd,
nl=NL_CHAR))
nl=NL_CHAR).encode('utf-8'))
estimate_size += 0x100
return estimate_size
@ -298,7 +298,7 @@ class SpecFile(object):
for line in specfile.readlines():
if line:
try:
entry = SpecEntry(line, self)
entry = SpecEntry(line.decode('utf-8'), self)
self._entries.append(entry)
self._functions[entry.name].append(entry)
except InvalidSpecError:
@ -383,7 +383,7 @@ class SpecFile(object):
fwd_strings = ' '.join(fwd_strings)
name = self.name
baseaddress = '0x{:8x}'.format(baseaddress)
cmakelists.write('add_apiset({} {} {}){}'.format(name, baseaddress, fwd_strings, NL_CHAR))
cmakelists.write('add_apiset({} {} {}){}'.format(name, baseaddress, fwd_strings, NL_CHAR).encode('utf-8'))
return self._estimate_size
@ -416,7 +416,7 @@ def run(wineroot):
version = subprocess.check_output(["git", "describe"], cwd=wineroot).strip()
print 'Reading Wine apisets for', version
print('Reading Wine apisets for', version.decode('utf-8'))
wine_apiset_path = os.path.join(wineroot, 'dlls')
for dirname in os.listdir(wine_apiset_path):
if not dirname.startswith('api-'):
@ -427,78 +427,78 @@ def run(wineroot):
spec = SpecFile(fullpath, dirname)
wine_apisets.append(spec)
print 'Parsing Wine apisets,',
print('Parsing Wine apisets,',)
total = (0, 0)
for apiset in wine_apisets:
total = tuple(map(sum, zip(apiset.parse(), total)))
print 'found', total[0], '/', total[1], 'forwarders'
print('found', total[0], '/', total[1], 'forwarders')
print 'Reading ReactOS modules'
print('Reading ReactOS modules')
for fullpath, dllname in generate_specnames(os.path.dirname(SCRIPT_DIR)):
spec = SpecFile(fullpath, dllname)
ros_modules.append(spec)
print 'Parsing ReactOS modules'
print('Parsing ReactOS modules')
for module in ros_modules:
module.parse()
assert module.name not in module_lookup, module.name
module_lookup[module.name] = module
module.add_functions(function_lookup)
print 'First pass, resolving forwarders,',
print('First pass, resolving forwarders,',)
total = (0, 0)
for apiset in wine_apisets:
total = tuple(map(sum, zip(apiset.resolve_forwarders(module_lookup), total)))
print 'found', total[0], '/', total[1], 'forwarders'
print('found', total[0], '/', total[1], 'forwarders')
print 'Second pass, searching extra forwarders,',
print('Second pass, searching extra forwarders,',)
total = (0, 0)
for apiset in wine_apisets:
total = tuple(map(sum, zip(apiset.extra_forwarders(function_lookup, module_lookup), total)))
print 'found', total[0], '/', total[1], 'forwarders'
print('found', total[0], '/', total[1], 'forwarders')
with open(os.path.join(SCRIPT_DIR, 'CMakeLists.txt.in'), 'rb') as template:
cmake_template = template.read()
cmake_template = cmake_template.replace('%WINE_GIT_VERSION%', version)
cmake_template = cmake_template.replace(b'%WINE_GIT_VERSION%', version)
# Detect the checkout newline settings
if '\r\n' in cmake_template:
if b'\r\n' in cmake_template:
NL_CHAR = '\r\n'
manifest_files = []
print 'Writing apisets'
spec_header = [line.replace('\n', NL_CHAR) for line in SPEC_HEADER]
print('Writing apisets')
spec_header = [line.replace(b'\n', NL_CHAR.encode('utf-8')) for line in SPEC_HEADER]
for apiset in wine_apisets:
with open(os.path.join(SCRIPT_DIR, apiset.name + '.spec'), 'wb') as out_spec:
out_spec.writelines(spec_header)
apiset.write(out_spec)
manifest_files.append(' <file name="{}.dll"/>'.format(apiset.name))
manifest_files.append(' <file name="{}.dll"/>'.format(apiset.name).encode('utf-8'))
print 'Generating manifest'
print('Generating manifest')
manifest_name = 'x86_reactos.apisets_6595b64144ccf1df_1.0.0.0_none_deadbeef.manifest'
with open(os.path.join(SCRIPT_DIR, manifest_name + '.in'), 'rb') as template:
manifest_template = template.read()
manifest_template = manifest_template.replace('%WINE_GIT_VERSION%', version)
file_list = '\r\n'.join(manifest_files)
manifest_template = manifest_template.replace('%MANIFEST_FILE_LIST%', file_list)
manifest_template = manifest_template.replace(b'%WINE_GIT_VERSION%', version)
file_list = b'\r\n'.join(manifest_files)
manifest_template = manifest_template.replace(b'%MANIFEST_FILE_LIST%', file_list)
with open(os.path.join(SCRIPT_DIR, manifest_name), 'wb') as manifest:
manifest.write(manifest_template)
print 'Writing CMakeLists.txt'
print('Writing CMakeLists.txt')
baseaddress = 0x60000000
with open(os.path.join(SCRIPT_DIR, 'CMakeLists.txt'), 'wb') as cmakelists:
cmakelists.write(cmake_template)
for apiset in wine_apisets:
baseaddress += apiset.write_cmake(cmakelists, baseaddress)
baseaddress += (0x10000 - baseaddress) % 0x10000
print 'Done'
print('Done')
def main(paths):
for path in paths:
if path:
run(path)
return
print 'No path specified,'
print 'either pass it as argument, or set the environment variable "WINE_SRC_ROOT"'
print('No path specified,')
print('either pass it as argument, or set the environment variable "WINE_SRC_ROOT"')
if __name__ == '__main__':
main(sys.argv[1:] + [os.environ.get('WINE_SRC_ROOT')])