JBurkeKF / UBTExample

Unreal Built Tool example projects
0 stars 0 forks source link

Working in UE 5.4.2? #1

Closed akrischer closed 1 month ago

akrischer commented 1 month ago

Hey, reaching out because I found this incredibly helpful resource for parsing CommandLine args from BuildCookRun command. I'm wondering if you've verified this is still working in UE 5.4, because following this guide no cmd line args are reaching the Target file.

I also don't see anywhere in the BuildCookRun source and through debugging where -ubtargs actually results in command line args getting passed in.


Pared down version of what we're doing:

public class MyGameTarget: TargetRules
{
    [CommandLine("-SomeFlag")]
    public bool SomeFlag= false;

    public MyGameTarget(TargetInfo Target) : base(Target)
    {
        Type = TargetType.Client;

        DefaultBuildSettings = BuildSettingsVersion.V5;
        IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_4;

                if (SomeFlag) { ... }

        ExtraModuleNames.AddRange(new string[]
        {
            // ...
        });
    }
}

And then we're calling BuildCookRun like

    call %RunUAT% BuildCookRun -project=... -noP4 -cook -server -serverplatform=... -platform=... -client -clientconfig=... -serverconfig=... -build -stage -pak -SomeFlag -UbtArgs="-SomeFlag" -prereqs %*

I've also tried -ubtargs=-SomeFlag, -ubtargs="-SomeFlag", and even "-ubtargs=-SomeFlag" and none seem to work.

JBurkeKF commented 1 month ago

This should work fine in UE 5.4, yes. I tested there and with UE 4.27. The only real difference is the namespace where the command line classes are kept. I tried using your command line, modified for my example project, and it worked fine for me.

call %RunUAT% BuildCookRun -project="<path to project>\UBTExample\UBTExample54\UBTExample54.uproject" -noP4 -cook platform=Win64 -clientconfig=Development -serverconfig=Development -build -stage -pak -targetsetting -UbtArgs="-targetsetting" -prereqs %*

You'll note in the output, though, that there are several different sections where the command line code is checked (really, the TargetRules class is processed), and they have different behaviors.

Initially, Unreal processes the TargetRules to get some basic information, and none of the command line arguments are available. This is normal and expected, and I haven't found a reason why I'd need things parsed at this stage of the build.

<path to project>\UBTExample\UBTExample54>call "<path to UE 5.4>\Engine\Build\BatchFiles\RunUAT.bat" BuildCookRun -project="<path to project>\UBTExample\UBTExample54\UBTExample54.uproject" -noP4 -cook platform=Win64 -clientconfig=Development -serverconfig=Development -build -stage -pak -targetsetting -UbtArgs="-targetsetting" -prereqs
Running AutomationTool...
Using bundled DotNet SDK version: 6.0.302
Starting AutomationTool...
Parsing command line: BuildCookRun -project=<path to project>\UBTExample\UBTExample54\UBTExample54.uproject -noP4 -cook platform=Win64 -clientconfig=Development -serverconfig=Development -build -stage -pak -targetsetting -UbtArgs=-targetsetting -prereqs
Initializing script modules...
Total script module initialization time: 0.30 s.
Using C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe
Executing commands...
Setting up ProjectParams for <path to project>\UBTExample\UBTExample54\UBTExample54.uproject
UBTExample: target setting value is set - False
UBTExampleEditor: target setting value is set - False
********** BUILD COMMAND STARTED **********

After that, the actual build command runs, and when it processes TargetRules again, the command line is actually properly in place for the build. You can also see, in my example, that it's processing the editor TargetRules and the game TargetRules, which have different command lines, so the first check for "-targetsetting" seems to fail, but the second one succeeds, because the second one is the actual game TargetRules which is checking for "-targetsetting", whereas my editor TargetRules is looking for "-editortargetsetting". You can also see, buried in the build command ("Running: \dotnet.exe ... -remoteini=... -targetsetting -log=...") that the command line flag is there without -UbtArgs. This is a good indication that Unreal accepted your command line and transferred it to the appropriate spot in the build process.

********** BUILD COMMAND STARTED **********
Running: <path to UE 5.4>\Engine\Binaries\ThirdParty\DotNet\6.0.302\windows\dotnet.exe "<path to UE 5.4>\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll" -Target="UBTExample54Editor Win64 Development -Project=<path to project>\UBTExample\UBTExample54\UBTExample54.uproject -Manifest=<path to project>\UBTExample\UBTExample54\Intermediate\Build\Manifest-1-UBTExample54Editor-Win64-Development.xml" -Target="UBTExample54 Win64 Development -Project=<path to project>\UBTExample\UBTExample54\UBTExample54.uproject -Manifest=<path to project>\UBTExample\UBTExample54\Intermediate\Build\Manifest-2-UBTExample54-Win64-Development.xml  -remoteini=\"<path to project>\UBTExample\UBTExample54\"  -targetsetting " -log="<path to Windows AppData>\Unreal Engine\AutomationTool\Logs\<modified path to UE 5.4>\UBA-UBTExample54Editor-Win64-Development.txt"
Log file: <path to Windows AppData>\Unreal Engine\AutomationTool\Logs\<modified path to UE 5.4>\UBA-UBTExample54Editor-Win64-Development.txt
Using 'git status' to determine working set for adaptive non-unity build (<path to project>\UBTExample).
Creating makefile for UBTExample54Editor (manifest '<path to project>\UBTExample\UBTExample54\Intermediate\Build\Manifest-1-UBTExample54Editor-Win64-Development.xml' not found)
UBTExampleEditor: target setting value is set - False
UBTExample: module setting value is set - False
UBTExample: project command line data value - []
UBTExamplePlugin: plugin setting value is set - False
UBTExamplePlugin: base plugin command line data value - []
UBTExamplePlugin: command line data value - []
Writing manifest to <path to project>\UBTExample\UBTExample54\Intermediate\Build\Manifest-1-UBTExample54Editor-Win64-Development.xml
Creating makefile for UBTExample54 (manifest '<path to project>\UBTExample\UBTExample54\Intermediate\Build\Manifest-2-UBTExample54-Win64-Development.xml' not found)
UBTExample: target setting value is set - True
UBTExample: target could not access command line data value
UBTExample: module setting value is set - False
UBTExample: project command line data value - []
UBTExamplePlugin: plugin setting value is set - False
UBTExamplePlugin: base plugin command line data value - []
UBTExamplePlugin: command line data value - []
Writing manifest to <path to project>\UBTExample\UBTExample54\Intermediate\Build\Manifest-2-UBTExample54-Win64-Development.xml
Building UBTExample54Editor and UBTExample54...
UBTExample54Editor: Using Visual Studio 2022 14.38.33139 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130) and Windows 10.0.19041.0 SDK (C:\Program Files (x86)\Windows Kits\10).
UBTExample54: Using Visual Studio 2022 14.38.33139 toolchain (C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130) and Windows 10.0.19041.0 SDK (C:\Program Files (x86)\Windows Kits\10).
Determining max actions to execute in parallel (12 physical cores, 24 logical cores)
  Executing up to 12 processes, one per physical core
  Requested 1.5 GB memory per action, 14.69 GB available: limiting max parallel actions to 9
Using Parallel executor to run 11 action(s)
------ Building 11 action(s) started ------

Hopefully this helps. I did see your test command line has both -SomeFlag and -UbtArgs="-SomeFlag". The first is unnecessary, though it doesn't break anything. I duplicated my -targetsetting flag in my example to verify that for myself.

akrischer commented 1 month ago

First off, thanks so much for testing this you're a great samaritan. And you're right, I was getting thrown off by that initial setup where no cmd line args were available. I am seeing it work as expected now, so thanks so much.

The extra -SomeFlag added was because we 100% had this working in UE 5.2 and that was what we were running in the script at the time as well. We then no longer needed that script, then upgraded to 5.4, and then needed to again pass in cmd line args through BuildCookRun. But you're right, it's not necessary.