From d4cb359f4bcd339f89d58c87b58777025622ed6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Wed, 20 Sep 2023 22:21:42 +0200 Subject: [PATCH] lsteamclient: Split loading, parsing, and generating steps. CW-Bug-Id: #22729 --- lsteamclient/gen_wrapper.py | 55 +++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/lsteamclient/gen_wrapper.py b/lsteamclient/gen_wrapper.py index 4e7257b6..433812a9 100755 --- a/lsteamclient/gen_wrapper.py +++ b/lsteamclient/gen_wrapper.py @@ -289,7 +289,12 @@ WRAPPED_CLASSES = [ "ISteamNetworkingFakeUDPPort", ] +all_records = {} +all_sources = {} +all_versions = {} + class_versions = {} +iface_versions = {} PATH_CONV = [ { @@ -1284,13 +1289,12 @@ def parse(sources, abi): return build, structs -prog = re.compile("^#define\s*(\w*)\s*\"(.*)\"") -for sdkver in SDK_VERSIONS: - print(f"parsing SDK version {sdkver}...") +def load(sdkver): + prog = re.compile("^#define\s*(\w*)\s*\"(.*)\"") sdkdir = f"steamworks_sdk_{sdkver}" sources = {} - iface_versions = {} + versions = {} for file in os.listdir(sdkdir): # Some files from Valve have non-UTF-8 stuff in the comments # (typically the copyright symbol); therefore we ignore UTF-8 @@ -1305,7 +1309,7 @@ for sdkver in SDK_VERSIONS: result = prog.match(line) if result: iface, version = result.group(1, 2) - iface_versions[iface] = version + versions[iface] = version source = [f'#if __has_include("{sdkdir}/{file}")\n' f'#include "{sdkdir}/{file}"\n' @@ -1313,10 +1317,22 @@ for sdkver in SDK_VERSIONS: for file in SDK_SOURCES.keys()] sources["source.cpp"] = "\n".join(source) - linux_build32, linux_structs32 = parse(sources, 'u32') - linux_build64, linux_structs64 = parse(sources, 'u64') - windows_build32, windows_structs32 = parse(sources, 'w32') - windows_build64, windows_structs64 = parse(sources, 'w64') + return versions, sources + + +def generate(sdkver, records): + global linux_structs32 + global linux_structs64 + global windows_structs32 + global windows_structs64 + global iface_versions + + print(f'generating SDK version {sdkver}...') + linux_build32, linux_structs32 = records['u32'] + linux_build64, linux_structs64 = records['u64'] + windows_build32, windows_structs32 = records['w32'] + windows_build64, windows_structs64 = records['w64'] + iface_versions = all_versions[sdkver] for child in linux_build32.cursor.get_children(): if child.kind == CursorKind.CLASS_DECL and child.displayname in SDK_CLASSES: @@ -1324,6 +1340,27 @@ for sdkver in SDK_VERSIONS: if child.kind in [CursorKind.STRUCT_DECL, CursorKind.CLASS_DECL]: handle_struct(sdkver, child) + +for i, sdkver in enumerate(SDK_VERSIONS): + print(f'loading SDKs... {i * 100 // len(SDK_VERSIONS)}%', end='\r') + all_versions[sdkver], all_sources[sdkver] = load(sdkver) +print(u'loading SDKs... 100%') + +for i, sdkver in enumerate(SDK_VERSIONS): + print(f'parsing SDKs... {i * 100 // len(SDK_VERSIONS)}%', end='\r') + sources = all_sources[sdkver] + records = {} + records['u32'] = parse(sources, 'u32') + records['u64'] = parse(sources, 'u64') + records['w32'] = parse(sources, 'w32') + records['w64'] = parse(sources, 'w64') + all_records[sdkver] = records +print(u'parsing SDKs... 100%') + +for sdkver, records in all_records.items(): + generate(sdkver, records) + + for f in cpp_files_need_close_brace: m = open(f, "a") m.write("\n}\n")