From 30757a88c5e931b63076dc6bcbcd7520086808db Mon Sep 17 00:00:00 2001 From: jyelon Date: Mon, 23 Jun 2025 17:46:56 -0400 Subject: [PATCH] More thorough compile_commands.json generation --- build.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/build.py b/build.py index f256c5a0..71ea3401 100755 --- a/build.py +++ b/build.py @@ -86,6 +86,25 @@ def expand_json_file(sourcefile, outputfile, config): expanded = expand_json(data, vars(config)) Path(outputfile).write_text(json.dumps(expanded, indent=4)) +# +# Extracting a generated module file. +# + +def cpp_files_included_by(module): + """ + Given the name of a Module.XYZ.cpp file generated by unreal + build tool, scan the module for include directives that include + another C++ file. Produce a list of these C++ files. + """ + result = [] + for line in Path(module).read_text().splitlines(): + if line.startswith("#include "): + file = line[9:].strip().strip('"') + if file.endswith(".cpp"): + result.append(file) + return result + + # # Applying patches to files with DOS line endings. # @@ -293,6 +312,9 @@ def build_intellisense_database_for_clangd(): cpp = rsp.removesuffix(".o.rsp") 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))