Fix luprex Makefile so it emits full paths, and replace add-compile-commands.py with a better way to build compile_commands.json for luprex
This commit is contained in:
49
build.py
49
build.py
@@ -287,7 +287,7 @@ def build_luprex_and_integration():
|
||||
"""
|
||||
This builds our C++ code, and also UnrealEngine's C++ code.
|
||||
"""
|
||||
shell(f"{INTEGRATION}/luprex", "make all 2>&1 | sed 's|^cpp/|luprex/cpp/|; s|^ext/|luprex/ext/|'")
|
||||
shell(INTEGRATION, "make -f luprex/Makefile all")
|
||||
shell(INTEGRATION, f"{UNREALENGINE}/Engine/Build/BatchFiles/{BUILD_BAT} -waitmutex IntegrationEditor {OS} {DEBUG} {INTEGRATION}/Integration.uproject")
|
||||
|
||||
|
||||
@@ -295,11 +295,28 @@ def build_luprex_and_integration():
|
||||
# Make a compile_commands.json file.
|
||||
#
|
||||
|
||||
def build_intellisense_database_for_clangd():
|
||||
def build_compile_commands_from_luprex():
|
||||
"""
|
||||
This builds compile_commands.json, which tells the intellisense system
|
||||
based on clangd how to compile each source file.
|
||||
This also installs a .clangd file in the UnrealEngine directory.
|
||||
Generate compile commands for luprex by parsing make dry-run output.
|
||||
Returns a list of compile_commands.json entries.
|
||||
"""
|
||||
result = subprocess.run(
|
||||
["make", "-n", "-B", "-f", "luprex/Makefile", "all"],
|
||||
capture_output=True, text=True, check=True, cwd=INTEGRATION
|
||||
)
|
||||
entries = []
|
||||
for line in result.stdout.splitlines():
|
||||
parts = line.split()
|
||||
if (parts[0] == "g++") and ("-c" in parts):
|
||||
source = os.path.abspath(os.path.join(INTEGRATION, parts[-1]))
|
||||
entries.append({ "file": source, "command": line, "directory": INTEGRATION })
|
||||
return entries
|
||||
|
||||
|
||||
def build_compile_commands_from_integration():
|
||||
"""
|
||||
Generate compile commands for Unreal/Integration by scanning RSP files
|
||||
generated by UnrealBuildTool. Returns a list of compile_commands.json entries.
|
||||
"""
|
||||
# Find clang compiler.
|
||||
clangs = list(Path(f"{UNREALENGINE}/Engine/Extras/ThirdPartyNotUE/SDKs").rglob("*-linux-gnu/bin/clang++"))
|
||||
@@ -316,14 +333,22 @@ def build_intellisense_database_for_clangd():
|
||||
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";
|
||||
# Generate compile commands.
|
||||
entries = []
|
||||
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 })
|
||||
entries.append({ "file": cpp, "arguments": args, "directory": ccdir })
|
||||
return entries
|
||||
|
||||
|
||||
def build_compile_commands_json():
|
||||
"""
|
||||
Build .vscode/compile_commands.json by combining compile commands
|
||||
from luprex and from the Unreal/Integration build.
|
||||
"""
|
||||
ccjson = build_compile_commands_from_luprex() + build_compile_commands_from_integration()
|
||||
Path(f"{INTEGRATION}/.vscode").mkdir(exist_ok=True)
|
||||
Path(f"{INTEGRATION}/.vscode/compile_commands.json").write_text(json.dumps(ccjson, indent=2))
|
||||
|
||||
@@ -385,7 +410,7 @@ store_system_config_in_globals(CONFIG)
|
||||
os.chdir(f"{INTEGRATION}/EnginePatches")
|
||||
|
||||
if MODE == "ccjson":
|
||||
build_intellisense_database_for_clangd()
|
||||
build_compile_commands_json()
|
||||
|
||||
if MODE == "code-workspace":
|
||||
generate_integration_code_workspace()
|
||||
@@ -401,7 +426,7 @@ if MODE == "all":
|
||||
|
||||
if MODE in ["all", "c++"]:
|
||||
build_luprex_and_integration()
|
||||
build_intellisense_database_for_clangd()
|
||||
build_compile_commands_json()
|
||||
|
||||
if MODE == "clean":
|
||||
build_clean()
|
||||
|
||||
Reference in New Issue
Block a user