I think I may have found a bug in the Unreal Build Tool, and just in case it is I would like to report it.
Note that all these tools are compiled by me from the 4.0.2 baseline.
To give some background I am calling the UnrealAutomationTool with the following command line:
BuildCookRun -nocompileeditor -nop4 -project=C:/UE4/ShooterGame/ShooterGame.uproject -cook -allmaps -stage -archive -archivedirectory=C:/PackageTest -package -WindowsNoEditor -clientconfig=Development -ue4exe=UE4Editor-Cmd -clean -pak -targetplatform=Win64 -build
The AutomationTool makes a call into the BuildTool to grab project info.
// Fill in the project info UnrealBuildTool.UProjectInfo.FillProjectInfo();
When the call is made the working directory has been set to the engine directory (“C:\UE4” for me) by the line a few before:
// Change CWD to UE4 root. Environment.CurrentDirectory = CommandUtils.CmdEnv.LocalRoot;
The line in question where I believe the bug is: @Engine\Source\Programs\UnrealBuildTool\System\UProjectInfo.cs:171
string RelativePath = Utils.MakePathRelativeTo(UProjFile, EngineSourceDirectory);
That causes problems for me, and I can fix it by using:
string RelativePath = Utils.MakePathRelativeTo(UProjFile, Environment.CurrentDirectory);
My current setup uses the engine in C:\UE4, with shootergame in C:\UE4\ShooterGame.
The location of shootergame is picked up via a “*.uprojectdirs” file with a single dot in it.
When the problem line runs, the relative path is set to: “…\…\ShooterGame\ShooterGame.uproject”
This is despite the fact that the working directory was set relative to the engine root not the engine source folder in the AutomationTool.
The problem manifests itself for me when the targets for ShooterGame are picked up:
string ProjectDir = ProjectFileInfo.DirectoryName;
The code there thinks that ShooterGame is in “C:\ShooterGame”, when in fact it is in “C:\UE4\ShooterGame”. This is because it is using the relative path for the project with respect to the engine source folder, when the working directory is set to the engine root. When I apply the fix above, that no longer happens and the targets are detected.
I am also fairly sure this is not simply a result of debugging in the editor, for when I look at the verbose output of the automation tool for the command line at the top, I see the following output at the spot where the projects are being detected:
UProjectInfo.FillProjectInfo: Searching C:\UE4 UProjectInfo.FillProjectInfo: Found subdir C:\UE4\.git UProjectInfo.FillProjectInfo: Found subdir C:\UE4\Engine UProjectInfo.FillProjectInfo: Found subdir C:\UE4\Samples UProjectInfo.FillProjectInfo: Found subdir C:\UE4\ShooterGame UProjectInfo.FillProjectInfo: ..\..\ShooterGame\ShooterGame.uproject
Where the last line is the relative path from above. With the fix applied the output becomes:
UProjectInfo.FillProjectInfo: Searching C:\UE4 UProjectInfo.FillProjectInfo: Found subdir C:\UE4\.git UProjectInfo.FillProjectInfo: Found subdir C:\UE4\Engine UProjectInfo.FillProjectInfo: Found subdir C:\UE4\Samples UProjectInfo.FillProjectInfo: Found subdir C:\UE4\ShooterGame UProjectInfo.FillProjectInfo: ShooterGame\ShooterGame.uproject
As a consequence of the above the variable “TargetToProjectDictionary” from the UProjectInfo class was not getting populated at the very least (which is how I noticed all this).
Again, no idea if this is a real problem or not, as I only noticed it when stepping through the source, but I fixed it on my end just in case.
After looking at another part of the source, I found a spot @Engine\Source\Programs\AutomationTool\ScriptCompiler.cs:132
Where the working directory is set to the engine source folder, and the path to the project needs to be either relative to that folder or absolute. Right now I’m just trying keeping that path specified above absolute, as in:
string RelativePath = UProjFile;
At this point I’m not entirely sure why the relative path is being passed into AddProject