diff --git a/build.py b/build.py index b85af31a..82f86674 100755 --- a/build.py +++ b/build.py @@ -130,7 +130,7 @@ def get_build_mode_from_command_line(): """ mode = sys.argv[1].lower() if len(sys.argv) > 1 else 'all' 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}") return mode @@ -294,22 +294,29 @@ def build_intellisense_database_for_clangd(): based on clangd how to compile each source file. This also installs a .clangd file in the UnrealEngine directory. """ - mods1 = Path(f"{INTEGRATION}/Intermediate/Build/{OS}").rglob("UnrealEditor/{DEBUG}/**/Module.*.o.rsp") - mods2 = Path(f"{UNREALENGINE}/Engine/Intermediate/Build/{OS}").rglob("UnrealEditor/Development/**/Module.*.o.rsp") - mods = list(mods1) + list(mods2) + # Find clang compiler. 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: + # Build the table of source files and RSP files. + mods1 = Path(f"{INTEGRATION}/Intermediate/Build/{OS}").rglob(f"UnrealEditor/{DEBUG}/**/Module.*.o.rsp") + 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) - 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] 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)) @@ -348,6 +355,9 @@ CONFIG = autodetect_system_config() store_system_config_in_globals(CONFIG) os.chdir(f"{INTEGRATION}/EnginePatches") +if MODE == "ccjson": + build_intellisense_database_for_clangd() + if MODE == "all": unzip_unreal_engine_and_apply_patch() generate_buildconfiguration_xml()