UBT GenerateClangDatabase is NOT incremental and recreates whole compile_commands.json each time

Hi,

In order to generate compile_commands.json for clangd Language Server, one can use -mode=GenerateClangDatabase flag in Unreal Build Tool (more details described here )

However, a problem with this mode is that it isn’t “incremental” which means it regenerates whole file every time, not only the part that requires it, resulting in very long execution times (around 45sec on my machine).

This makes it pretty hard to use since database needs to be regenerated when any #include directive has changed or when any source file has been added/removed/renamed. This should pretty much run every time when build process is invoked, just to make sure database is up to date.

Is there some hidden option/flag that makes it incremental?
Is there a reason why it’s NOT incremental?
Was it incremental in the past?

My engine version is 5.4.2, built from git on Linux

TLDR: -NoExecCodeGenActions

I think I found a workaround/fix to this issue.
There is a hidden flag in UnrealEngine/Engine/Source/Programs/UnrealBuildTool/Modes/GenerateClangDatabase.cs


		/// <summary>
		/// Execute any actions which result in code generation (eg. ISPC compilation)
		/// </summary>
		[CommandLine("-ExecCodeGenActions")]
		[CommandLine("-NoExecCodeGenActions", Value = "false")]
		public bool bExecCodeGenActions = true;

which controls generation of *.generated.h files.

So adding -NoExecCodeGenActions fixes this issue for my use case.
Execution time is decreased from 45sec to roughly 3sec.
(but have in mind that whole Project and Engine must be compiled already)

I’m not sure if this is optimal though since 3 sec is still pretty long for something that should be run for each compilation attempt. For comparison, changing one .cpp file in my Project requires around 2-5sec for its recompilation. So additional 3sec would make noticeable difference.