Add ExcludeFiles or something to UBT

Hi,

Recently UE_4_X_OR_LATER was added to UBT, which is a start for plugins trying to stay cross UE4 version compatible (to some extent). The goal isn’t to keep versions 4.5 to 4.18, but at least not having to drop previous versions of UE4 everytime a reflected type is renamed in UE4 source code.

This is the case with FStringAssetReference which was renamed to FSoftObjectPath in this 4.18 version, and this type being part of UBT reflection, it is impossible (unless I missed a solution), for code in plugins that relied on this previous type to either:

  • Ifdef
  • define
  • typename

So ok, this is apparently known limitation of UBT, but if this will stay like this, is it possible to add:

  • Possibility for modules to register their own ifdefs, recognized by UBT (other than WITH_EDITOR and WITH_EDITORONLY_DATA)
  • Possibility for modules to exclude specific .cpp files or even folders, that would be a start

Because right now, we are kind of forced to drop previous versions of UE4 if this kind of scenario happen.

Regards.

By “UBT reflection” you mean UnrealHeaderTool (UHT), it’s that complitly different tool, UBT only manage compilation process and it runs UHT to do header processing work.

For this kind of things you have build scripts (*.target.cs and *.build.cs), they indeed don’t have file exclusion, but you can alter include paths in *.build.cs, this file shows all varbales you can put in ModuleInfo:

https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Programs/UnrealBuildTool/Configuration/ModuleRules.cs

This one is what you looking for:

	/// <summary>
	/// (This setting is currently not need as we discover all files from the 'Public' folder) List of all paths to include files that are exposed to other modules
	/// </summary>
	public List<string> PublicIncludePaths = new List<string>();

which let you add extra public (accessible from other modules, or else use PrivateIncludePaths) include files

There also this allowing to removed default include paths and add your own

	/// <summary>
	/// Whether to add all the default include paths to the module (eg. the Source/Classes folder, subfolders under Source/Public).
	/// </summary>
	public bool bAddDefaultIncludePaths = true;

Now to get engine version you need to read it out, it has nothing build in as UBT is made to work with everything else then Unreal (like ThirdParty libraries):

		BuildVersion Version;
		if(!BuildVersion.TryRead(out Version))
		{
			throw new BuildException("Couldn't read engine version");
		}

And from Version you can read MinorVersion which should be the X number (4.X)

Here you got a file:

https://github.com/EpicGames/UnrealEngine/blob/f794321ffcad597c6232bc706304c0c9b4e154b2/Engine/Source/Programs/UnrealBuildTool/System/BuildVersion.cs

Sadly you can add extra definition to UHT as it’s hardcoded in UHT code, i checked and adding new once require some extra code in few places. So try method mentioend above, i didn’t test it myself, but it’s worth a try, better then nothing. Biggest unknown is if UHT honors UBT include paths configuration or it goes stright to Public and Private directories. UHT process header files that are included in cpp files, so i think it should work as long as UHT looks in to include paths configured in UBT, for a test to put include file in non-default directory and see if UHT will work properly with such configuration

Hi,

Thanks for your answer, indeed UBT != UHT, but the problem stays the same.

What I’m trying to point out here is the fact that when UE4 devs rename a reflected type (like mentionned above), there is no way for a plugin (that has the need to remain cross UE4 version compatible) to patch header files that rely on those types so unfortunately your solution here cannot fix this problem (unless I missed the point ?)

Well you mention “ExcludeFiles” as potential solution in title, so there should be way to do so in build scripts but biggest problem is that is not much documented. My solution should direct UHT to proper header files for specific version, did you try it out?

It could have been a good solution, only problem is UHT will still parse all header files contained in the module’s Source/ folder, so won’t compile as one file will contain references to deprecated types.
We’re probably gonna have to adopt a hardcore solution… copy of appropritate files from the .build.cs

Ah ok you are correct