Fix compile_commands.json again

This commit is contained in:
2025-07-02 17:01:49 -04:00
parent fd453e6b30
commit 689b80044c

View File

@@ -130,7 +130,7 @@ def get_build_mode_from_command_line():
""" """
mode = sys.argv[1].lower() if len(sys.argv) > 1 else 'all' mode = sys.argv[1].lower() if len(sys.argv) > 1 else 'all'
if mode in ["cpp", "cxx"]: mode = "c++" if mode in ["cpp", "cxx"]: mode = "c++"
if not mode in ["all", "c++", "clean", "experiment"]: if not mode in ["all", "c++", "clean", "ccjson"]:
sys.exit(f"Invalid build mode: {mode}") sys.exit(f"Invalid build mode: {mode}")
return mode return mode
@@ -294,22 +294,29 @@ def build_intellisense_database_for_clangd():
based on clangd how to compile each source file. based on clangd how to compile each source file.
This also installs a .clangd file in the UnrealEngine directory. This also installs a .clangd file in the UnrealEngine directory.
""" """
mods1 = Path(f"{INTEGRATION}/Intermediate/Build/{OS}").rglob("UnrealEditor/{DEBUG}/**/Module.*.o.rsp") # Find clang compiler.
mods2 = Path(f"{UNREALENGINE}/Engine/Intermediate/Build/{OS}").rglob("UnrealEditor/Development/**/Module.*.o.rsp")
mods = list(mods1) + list(mods2)
clangs = list(Path(f"{UNREALENGINE}/Engine/Extras/ThirdPartyNotUE/SDKs").rglob("*-linux-gnu/bin/clang++")) clangs = list(Path(f"{UNREALENGINE}/Engine/Extras/ThirdPartyNotUE/SDKs").rglob("*-linux-gnu/bin/clang++"))
if len(clangs) != 1: sys.exit("Couldn't identify correct clang++ compiler in UnrealEngine thirdparty directory") if len(clangs) != 1: sys.exit("Couldn't identify correct clang++ compiler in UnrealEngine thirdparty directory")
clang = str(clangs[0]) clang = str(clangs[0])
ccjson = json.loads(Path(f"{INTEGRATION}/luprex/build/{OS}/compile_commands.json").read_text()) # Build the table of source files and RSP files.
ccdir = f"{UNREALENGINE}/Engine/Source"; mods1 = Path(f"{INTEGRATION}/Intermediate/Build/{OS}").rglob(f"UnrealEditor/{DEBUG}/**/Module.*.o.rsp")
for mod in mods: mods2 = Path(f"{UNREALENGINE}/Engine/Intermediate/Build/{OS}").rglob("UnrealEditor/Development/**/Module.*.o.rsp")
cpp_to_rsp = {}
for mod in itertools.chain(mods1, mods2):
rsp = str(mod) rsp = str(mod)
cpp = rsp.removesuffix(".o.rsp") cpp = os.path.abspath(rsp.removesuffix(".o.rsp"))
cpp_to_rsp[cpp] = rsp
for subfile in cpp_files_included_by(cpp):
abs = os.path.abspath(os.path.join(f"{UNREALENGINE}/Engine/Source", subfile))
cpp_to_rsp[abs] = rsp
# Read the luprex compile commands database.
ccjson = json.loads(Path(f"{INTEGRATION}/luprex/build/{OS}/compile_commands.json").read_text())
# Generate the new commands
ccdir = f"{UNREALENGINE}/Engine/Source";
for cpp in sorted(cpp_to_rsp.keys()):
rsp = cpp_to_rsp[cpp]
args = [clang, "@"+rsp] args = [clang, "@"+rsp]
ccjson.append({ "file" : cpp, "arguments":args, "directory":ccdir }) ccjson.append({ "file" : cpp, "arguments":args, "directory":ccdir })
for subfile in cpp_files_included_by(cpp):
abs = os.path.join(f"{UNREALENGINE}/Engine", subfile)
ccjson.append({ "file" : abs, "arguments":args, "directory":ccdir })
Path(f"{INTEGRATION}/.vscode/compile_commands.json").write_text(json.dumps(ccjson, indent=2)) Path(f"{INTEGRATION}/.vscode/compile_commands.json").write_text(json.dumps(ccjson, indent=2))
@@ -348,6 +355,9 @@ CONFIG = autodetect_system_config()
store_system_config_in_globals(CONFIG) store_system_config_in_globals(CONFIG)
os.chdir(f"{INTEGRATION}/EnginePatches") os.chdir(f"{INTEGRATION}/EnginePatches")
if MODE == "ccjson":
build_intellisense_database_for_clangd()
if MODE == "all": if MODE == "all":
unzip_unreal_engine_and_apply_patch() unzip_unreal_engine_and_apply_patch()
generate_buildconfiguration_xml() generate_buildconfiguration_xml()