I think I finally have intellisense mainly working.

This commit is contained in:
2025-06-18 18:39:25 -04:00
parent 761344bbd5
commit e8ec9c9707
2 changed files with 23 additions and 52 deletions

View File

@@ -238,50 +238,30 @@ def build_luprex_and_integration():
shell(INTEGRATION, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} -waitmutex IntegrationEditor {OS} DebugGame {INTEGRATION}/Integration.uproject")
def build_intellisense_database_for_clangd(force):
#
# Make a compile_commands.json file.
#
def build_intellisense_database_for_clangd():
"""
This builds compile_commands.json, which tells the intellisense system
based on clangd how to compile each source file. We automatically rebuild
if a C++ file has been added or removed. That probably isn't sufficient:
we should also rebuild if a Build.cs file has been edited. Coming Soon.
Until then, if your intellisense starts acting badly, do a 'build.py all',
which sets the 'force' argument above to true.
Rebuilding the intellisense database touches rsp files, which
unfortunately, causes the entire C++ build to be restarted the next
time you run 'build'. This is terrible behavior from Unreal's build
system. We have a hacky workaround: we save the RSP files before
running the intellisense build, then we restore them afterward.
based on clangd how to compile each source file.
This also installs a .clangd file in the UnrealEngine directory.
"""
Path(f"{INTEGRATION}/.vscode").mkdir(exist_ok = True)
Path(f"{UNREALENGINE}/.vscode").mkdir(exist_ok = True)
hash_file = Path(f"{INTEGRATION}/.vscode/cpp_hash")
new_hash = hash_json(find_cpp(f"{INTEGRATION}/Source"))
old_hash = read_if_exists(hash_file).strip()
if (new_hash != old_hash) or force:
hash_file.unlink(missing_ok=True)
create_tarfile(f"{INTEGRATION}/Intermediate", "*.rsp", f"{INTEGRATION}/rsp_files.tgz")
create_tarfile(f"{UNREALENGINE}/Engine", "*.rsp", f"{UNREALENGINE}/rsp_files.tgz")
try:
Path(f"{INTEGRATION}/.vscode/compile_commands.json").unlink(missing_ok=True)
shell(INTEGRATION, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} -waitmutex IntegrationEditor {OS} DebugGame {INTEGRATION}/Integration.uproject -mode=GenerateClangDatabase -OutputDir={INTEGRATION}/.vscode")
shell(UNREALENGINE, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} -waitmutex UnrealEditor {OS} DebugGame -mode=GenerateClangDatabase -OutputDir={UNREALENGINE}/.vscode")
cc1 = json.loads(Path(f"{INTEGRATION}/.vscode/compile_commands.json").read_text())
cc2 = json.loads(Path(f"{INTEGRATION}/luprex/build/{OS}/compile_commands.json").read_text())
cc3 = json.loads(Path(f"{UNREALENGINE}/.vscode/compile_commands.json").read_text())
cc = cc1 + cc2 + cc3
Path(f"{INTEGRATION}/.vscode/compile_commands.json").write_text(json.dumps(cc, indent=2))
except Exception as e:
error = e
else:
error = None
# finally:
# tarfile.open(f"{INTEGRATION}/rsp_files.tgz").extractall(path=f"{INTEGRATION}/Intermediate")
# tarfile.open(f"{UNREALENGINE}/rsp_files.tgz").extractall(path=f"{UNREALENGINE}/Engine")
# Path(f"{INTEGRATION}/rsp_files.tgz").unlink()
# Path(f"{UNREALENGINE}/rsp_files.tgz").unlink()
if error: raise error
hash_file.write_text(new_hash)
mods1 = Path(f"{INTEGRATION}/Intermediate/Build/{OS}").rglob("UnrealEditor/DebugGame/**/Module.*.o.rsp")
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++"))
if len(clangs) != 1: sys.exit("Couldn't identify correct clang++ compiler in UnrealEngine thirdparty directory")
clang = str(clangs[0])
ccjson = json.loads(Path(f"{INTEGRATION}/luprex/build/{OS}/compile_commands.json").read_text())
ccdir = f"{UNREALENGINE}/Engine/Source";
for mod in mods:
rsp = str(mod)
cpp = rsp.removesuffix(".o.rsp")
args = [clang, "@"+rsp]
ccjson.append({ "file" : cpp, "arguments":args, "directory":ccdir })
Path(f"{INTEGRATION}/.vscode/compile_commands.json").write_text(json.dumps(ccjson, indent=2))
def generate_integration_code_workspace():
@@ -320,7 +300,7 @@ store_system_config_in_globals(CONFIG)
os.chdir(f"{INTEGRATION}/EnginePatches")
if MODE == "experiment":
build_intellisense_database_for_clangd(True)
build_intellisense_database_for_clangd()
if MODE == "all":
checkout_correct_unreal_engine_branch_and_apply_patch()
@@ -333,7 +313,7 @@ if MODE == "all":
if MODE in ["all", "c++"]:
build_luprex_and_integration()
# build_intellisense_database_for_clangd(MODE == "all")
build_intellisense_database_for_clangd()
if MODE == "clean":
build_clean()