lsteamclient: Parse all include files at once.

This commit is contained in:
Rémi Bernon 2022-01-06 15:52:49 +01:00 committed by Arkadiusz Hiler
parent db7e0e7a14
commit 57ea5353ee
3 changed files with 70 additions and 51 deletions

View File

@ -932,7 +932,7 @@ def get_iface_version(classname):
class_versions[classname].append(ver)
return (ver, False)
def handle_class(sdkver, classnode):
def handle_class(sdkver, classnode, file):
children = list(classnode.get_children())
if len(children) == 0:
return
@ -971,8 +971,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(steamclient);
cpp.write(f"#include \"steamworks_sdk_{sdkver}/steam_api.h\"\n")
if os.path.isfile(f"steamworks_sdk_{sdkver}/steamnetworkingtypes.h"):
cpp.write(f"#include \"steamworks_sdk_{sdkver}/steamnetworkingtypes.h\"\n")
if not fname == "steam_api.h":
cpp.write(f"#include \"steamworks_sdk_{sdkver}/{fname}\"\n")
if not file == "steam_api.h":
cpp.write(f"#include \"steamworks_sdk_{sdkver}/{file}\"\n")
cpp.write("#pragma pop_macro(\"__cdecl\")\n")
cpp.write("#include \"steamclient_private.h\"\n")
cpp.write("#ifdef __cplusplus\nextern \"C\" {\n#endif\n")
@ -1267,55 +1267,74 @@ def handle_struct(sdkver, struct):
prog = re.compile("^#define\s*(\w*)\s*\"(.*)\"")
for sdkver in sdk_versions:
print(f"parsing SDK version {sdkver}...")
sdkdir = f"steamworks_sdk_{sdkver}"
sources = {}
iface_versions = {}
for f in os.listdir(f"steamworks_sdk_{sdkver}"):
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
# encoding errors
x = open(f"steamworks_sdk_{sdkver}/{f}", "r", errors='replace')
for l in x:
if "define STEAM" in l and "_VERSION" in l:
result = prog.match(l)
lines = open(f"{sdkdir}/{file}", "r", errors="replace").readlines()
if file == "isteammasterserverupdater.h":
if """#error "This file isn't used any more"\n""" in lines:
sources[f"{sdkdir}/isteammasterserverupdater.h"] = ""
for line in lines:
if "define STEAM" in line and "_VERSION" in line:
result = prog.match(line)
if result:
iface, version = result.group(1, 2)
iface_versions[iface] = version
for fname, classes in files:
input_name = f"steamworks_sdk_{sdkver}/{fname}"
sys.stdout.write(f"about to parse {input_name}\n")
if not os.path.isfile(input_name):
continue
index = Index.create()
linux_build = index.parse(input_name, args=['-x', 'c++', '-m32', '-I' + CLANG_PATH + '/include/'])
linux_build64 = index.parse(input_name, args=['-x', 'c++', '-I' + CLANG_PATH + '/include/'])
source = [f"""#if __has_include("{sdkdir}/{file}")
#include "{sdkdir}/{file}"
#endif""" for file, _ in files]
sources["source.cpp"] = "\n".join(source)
windows_args = ["-D_WIN32", "-fms-extensions", "-Wno-ignored-attributes",
"-mms-bitfields", "-U__linux__", "-Wno-incompatible-ms-struct"]
windows_args += ['-I' + CLANG_PATH + '/include/']
linux_args = ["-DGNUC"]
linux_args += ['-I' + CLANG_PATH + '/include/']
index = Index.create()
linux_build32 = index.parse("source.cpp", args=linux_args + ["-m32"], unsaved_files=sources.items())
diagnostics = list(linux_build32.diagnostics)
for diag in diagnostics: print(diag)
assert len(diagnostics) == 0
linux_build64 = index.parse("source.cpp", args=linux_args + ["-m64"], unsaved_files=sources.items())
diagnostics = list(linux_build64.diagnostics)
for diag in diagnostics: print(diag)
assert len(diagnostics) == 0
windows_build32 = index.parse("source.cpp", args=windows_args + ["-m32"], unsaved_files=sources.items())
diagnostics = list(windows_build32.diagnostics)
for diag in diagnostics: print(diag)
assert len(diagnostics) == 0
windows_build64 = index.parse("source.cpp", args=windows_args + ["-m64"], unsaved_files=sources.items())
diagnostics = list(windows_build64.diagnostics)
for diag in diagnostics: print(diag)
assert len(diagnostics) == 0
diagnostics = list(linux_build.diagnostics)
if len(diagnostics) > 0:
# Ignore known and harmless issues
if not(len(diagnostics) == 1 and "This file isn't used any more" in diagnostics[0].spelling):
print('There were parse errors')
pprint.pprint(diagnostics)
else:
windows_build = index.parse(input_name, args=['-x', 'c++', '-m32', '-I' + CLANG_PATH + '/include/', '-mms-bitfields', '-U__linux__', '-Wno-incompatible-ms-struct'])
windows_build64 = index.parse(input_name, args=['-x', 'c++', '-I' + CLANG_PATH + '/include/', '-mms-bitfields', '-U__linux__', '-Wno-incompatible-ms-struct'])
diagnostics = list(windows_build.diagnostics)
if len(diagnostics) > 0:
print('There were parse errors (windows build)')
pprint.pprint(diagnostics)
else:
linux_structs64 = dict(reversed([(child.spelling, child.type) for child
in linux_build64.cursor.get_children()]))
windows_structs32 = dict(reversed([(child.spelling, child.type) for child
in windows_build.cursor.get_children()]))
in windows_build32.cursor.get_children()]))
windows_structs64 = dict(reversed([(child.spelling, child.type) for child
in windows_build64.cursor.get_children()]))
for child in linux_build.cursor.get_children():
classes = dict([(klass, file) for file, classes in files for klass in classes])
for child in linux_build32.cursor.get_children():
if child.kind == CursorKind.CLASS_DECL and child.displayname in classes:
handle_class(sdkver, child)
handle_class(sdkver, child, classes[child.displayname])
if child.kind in [CursorKind.STRUCT_DECL, CursorKind.CLASS_DECL]:
handle_struct(sdkver, child)
if child.displayname in print_sizes:
sys.stdout.write(f"size of {child.displayname} is {child.type.get_size()}\n")
print("size of %s is %u" % (child.displayname, child.type.get_size()))
for f in cpp_files_need_close_brace:
m = open(f, "a")

View File

@ -21,15 +21,15 @@ extern void *create_winISteamAppList_STEAMAPPLIST_INTERFACE_VERSION001(void *);
extern void *create_winISteamHTMLSurface_STEAMHTMLSURFACE_INTERFACE_VERSION_005(void *);
extern void *create_winISteamInventory_STEAMINVENTORY_INTERFACE_V003(void *);
extern void *create_winISteamVideo_STEAMVIDEO_INTERFACE_V002(void *);
extern void *create_winISteamParentalSettings_STEAMPARENTALSETTINGS_INTERFACE_VERSION001(void *);
extern void *create_winISteamRemotePlay_STEAMREMOTEPLAY_INTERFACE_VERSION001(void *);
extern void *create_winISteamNetworkingMessages_SteamNetworkingMessages002(void *);
extern void *create_winISteamNetworkingSockets_SteamNetworkingSockets012(void *);
extern void *create_winISteamNetworkingUtils_SteamNetworkingUtils004(void *);
extern void *create_winISteamAppTicket_STEAMAPPTICKET_INTERFACE_VERSION001(void *);
extern void *create_winISteamGameServer_SteamGameServer014(void *);
extern void *create_winISteamGameServerStats_SteamGameServerStats001(void *);
extern void *create_winISteamGameCoordinator_SteamGameCoordinator001(void *);
extern void *create_winISteamParentalSettings_STEAMPARENTALSETTINGS_INTERFACE_VERSION001(void *);
extern void *create_winISteamNetworkingMessages_SteamNetworkingMessages002(void *);
extern void *create_winISteamNetworkingSockets_SteamNetworkingSockets012(void *);
extern void *create_winISteamNetworkingUtils_SteamNetworkingUtils004(void *);
extern void *create_winISteamNetworkingFakeUDPPort_SteamNetworkingFakeUDPPort001(void *);
extern void *create_winISteamInput_SteamInput005(void *);
extern void *create_winISteamUGC_STEAMUGC_INTERFACE_VERSION015(void *);

View File

@ -21,15 +21,15 @@
{"STEAMHTMLSURFACE_INTERFACE_VERSION_005", &create_winISteamHTMLSurface_STEAMHTMLSURFACE_INTERFACE_VERSION_005},
{"STEAMINVENTORY_INTERFACE_V003", &create_winISteamInventory_STEAMINVENTORY_INTERFACE_V003},
{"STEAMVIDEO_INTERFACE_V002", &create_winISteamVideo_STEAMVIDEO_INTERFACE_V002},
{"STEAMPARENTALSETTINGS_INTERFACE_VERSION001", &create_winISteamParentalSettings_STEAMPARENTALSETTINGS_INTERFACE_VERSION001},
{"STEAMREMOTEPLAY_INTERFACE_VERSION001", &create_winISteamRemotePlay_STEAMREMOTEPLAY_INTERFACE_VERSION001},
{"SteamNetworkingMessages002", &create_winISteamNetworkingMessages_SteamNetworkingMessages002},
{"SteamNetworkingSockets012", &create_winISteamNetworkingSockets_SteamNetworkingSockets012},
{"SteamNetworkingUtils004", &create_winISteamNetworkingUtils_SteamNetworkingUtils004},
{"STEAMAPPTICKET_INTERFACE_VERSION001", &create_winISteamAppTicket_STEAMAPPTICKET_INTERFACE_VERSION001},
{"SteamGameServer014", &create_winISteamGameServer_SteamGameServer014},
{"SteamGameServerStats001", &create_winISteamGameServerStats_SteamGameServerStats001},
{"SteamGameCoordinator001", &create_winISteamGameCoordinator_SteamGameCoordinator001},
{"STEAMPARENTALSETTINGS_INTERFACE_VERSION001", &create_winISteamParentalSettings_STEAMPARENTALSETTINGS_INTERFACE_VERSION001},
{"SteamNetworkingMessages002", &create_winISteamNetworkingMessages_SteamNetworkingMessages002},
{"SteamNetworkingSockets012", &create_winISteamNetworkingSockets_SteamNetworkingSockets012},
{"SteamNetworkingUtils004", &create_winISteamNetworkingUtils_SteamNetworkingUtils004},
{"SteamNetworkingFakeUDPPort001", &create_winISteamNetworkingFakeUDPPort_SteamNetworkingFakeUDPPort001},
{"SteamInput005", &create_winISteamInput_SteamInput005},
{"STEAMUGC_INTERFACE_VERSION015", &create_winISteamUGC_STEAMUGC_INTERFACE_VERSION015},