Files
UnrealEngineUWP/Engine/Source/Programs/UnrealVirtualizationTool/Private/UnrealVirtualizationTool.cpp

108 lines
3.2 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#include "UnrealVirtualizationTool.h"
#include "Modules/ModuleManager.h"
#include "RequiredProgramMainCPPInclude.h"
#include "UnrealVirtualizationToolApp.h"
IMPLEMENT_APPLICATION(UnrealVirtualizationTool, "UnrealVirtualizationTool");
DEFINE_LOG_CATEGORY(LogVirtualizationTool);
int32 UnrealVirtualizationToolMain(int32 ArgC, TCHAR* ArgV[])
{
TRACE_CPUPROFILER_EVENT_SCOPE(UnrealVirtualizationToolMain);
using namespace UE::Virtualization;
// Although standalone tools can set the project path via the cmdline this will not change the ProjectDir being
// used as standalone tools have a beespoke path in FGenericPlatformMisc::ProjectDir. We can work around this
// for now by doing our own parsing then using the project dir override feature.
// This is a band aid while we consider adding better support for project files/directories with stand alone tools.
if(ArgC >= 2)
{
FString Cmd(ArgV[1]);
if (!Cmd.IsEmpty() && !Cmd.StartsWith(TEXT("-")) && Cmd.EndsWith(FProjectDescriptor::GetExtension()))
{
FString ProjectDir = FPaths::GetPath(Cmd);
ProjectDir = FFileManagerGeneric::DefaultConvertToRelativePath(*ProjectDir);
// The path should end with a trailing slash (see FGenericPlatformMisc::ProjectDir) so we use
// NormalizeFilename not NormalizeDirectoryName as the latter will remove trailing slashes. We
// also need to add one if it is missing.
// We probably should move this path fixup code to 'FPlatformMisc::SetOverrideProjectDir'
FPaths::NormalizeFilename(ProjectDir);
if (!ProjectDir.EndsWith(TEXT("/")))
{
ProjectDir += TEXT("/");
}
FPlatformMisc::SetOverrideProjectDir(ProjectDir);
}
}
GEngineLoop.PreInit(ArgC, ArgV);
check(GConfig && GConfig->IsReadyForUse());
UnrealVirtualizationTool can now be given the path of a package or the path of a directory of packages to virtualize in addition to previous functionality. NOTE that all existing functionality should continue to work but using -Mode=Changelist or -Mode=Packagelist will result in a warning prompting the future use of the new versions for those commands. #rb Per.Larsson #jira UE-170657, UE-160396 #rnx #preflight 637c9232fa348e8480bdc7e2 - When the rehydration functionality was added it started to look like more functionality would be added to the tool than originally thought so I started to add the new functionality via a command system. This change now moves the older legacy functionality to the coommand system as well. - Added a new FVirtualizeCommand which can accept package paths, directory paths, packagelist files or changelists as the input. -- Unlike the legacy commands, virtualizing via changelist does not require the client spec to be provided on the commandline, although doing so will avoid several perforce commands and speed up the call. It is expected that people calling the tool on the commandline will probably opt to not supply a clientspec and let the tool workout which workspace a changelist is under, where as calls from other tools (such as P4VUtils) can provide it if already known to speed things up. -- FVirtualizeLegacyChangeListCommand replicates the functionality of the old -Mode=Changelist command. -- FVirtualizeLegacyPackageListCommand replicates the functionality of the old -Mode=Packagelist command. -- The new command will only try to submit the results if a changelist was provided as the input and even then it will not do so by default. The tool now requires people to opt into submitting the changelist via the command line option -submit. NOTE: Other versions of the command maybe allow submission in the future but the virtualization process needs to be improved so that it can check out package files before this really makes sense. - The rehydration command no longer requires a clientspec on the command line, it wasn't using the value anyway. - Moved the source control code from the app code files to CommandBase. If we add more commands in the future we might want to factor this out to its own base class so commands can opt into source control functionality. - In the future we should probably move the package -> project sorting code (FUnrealVirtualizationToolApp::TrySortFilesByProject) into the command base code as well. [CL 23233456 by paul chipchase in ue5-main branch]
2022-11-22 07:23:08 -05:00
#if 0
while (!FPlatformMisc::IsDebuggerPresent())
{
FPlatformProcess::SleepNoStats(0.0f);
}
PLATFORM_BREAK();
#endif
FModuleManager::Get().StartProcessingNewlyLoadedObjects();
bool bRanSuccessfully = true;
FUnrealVirtualizationToolApp App;
EInitResult Result = App.Initialize();
if (Result == EInitResult::Success)
{
if (!App.Run())
{
Extend the VA stand-alone tool to work on both changelists (the existing functionality) and lists of packages stored in a text file (the new functionality) #rb PJ.Kack #jira UE-143675 #rnx #preflight 624c6a1814634fba5c7e3d71 ### Rationale - The new mode being added allows us to write a list of package file paths to be virtualized to a file on disk and then the file to be passed to the tool so that it knows what to virtualize. This new mode will then be used by P4VUtils.dll which is how we will run the virtualization process via p4v custom tools. - We need this second mode because: -- A workspace could have multiple projects in it, which means a user could try to virtualize a changelist with packages from more than one project. -- Projects can be associated with different engine installations so the user could try to virtualize a changelist with packages using different engine installations, which in turn means that they need to be virtualized by different versions of the stand-alone tool. -- This means we cannot rely on passing the CL number to the tool, install P4VUtils.dll will need to sort the package paths by engine installation, then pass those paths to the correct version of the tool. -- The paths need to be written to a text file to be passed to the tool as the total length of path data can easily exceed the commandline max length limit if someone were to try and virtualize an entire project in one go for example. - Note that the new mode does NOT submit the package files since there might be multiple calls to different versions of the stand-alone tool. In theory if all the packages are under one engine install (which is almost certainly going to be 99.999% of all submits) we could allow the tool to do the submit but that means we need to maintain two different code paths for the same operation. - The existing mode (virtualize and submit a changelist) remains unchanged. It is not likely that an end user will ever use this mode, but it will make for a useful debugging tool in the future. ### Changes - When the tool first starts we now print the log path to the user so that they can more easily find it. This might be something that we want to remove after a while, but during the initial release of the tool it should make getting good debug info back from users with problems somewhat easier. - Some logging and error messages have had small updates made, to make the final output to the user more readable (based on the many many times this tool was run while testing). In some places additional logging has been added where I felt it was not clear to the user as to what was going on. - Connecting to source control has been moved from the changelist parsing code to it's own method ::TryConnectToSourceControl since all modes will require it. - The cmdline help output has been redone to support the multiple command line options we now have. - Although we could infer the mode to run based on the commandline options, we require the users to explicitly state the mode via -Mode=XXX. In general the tool will be invoked from a gui so adding extra commands doesn't really affect the usability of the system and it makes things a bit clearer. [CL 19665307 by paul chipchase in ue5-main branch]
2022-04-07 02:08:03 -04:00
UE_LOG(LogVirtualizationTool, Error, TEXT("UnrealVirtualizationTool ran with errors"));
bRanSuccessfully = false;
}
}
else if(Result == EInitResult::Error)
{
UE_LOG(LogVirtualizationTool, Error, TEXT("UnrealVirtualizationTool failed to initialize"));
bRanSuccessfully = false;
}
UE_CLOG(bRanSuccessfully, LogVirtualizationTool, Display, TEXT("UnrealVirtualizationTool ran successfully"));
const uint8 ReturnCode = bRanSuccessfully ? 0 : 1;
if (FParse::Param(FCommandLine::Get(), TEXT("fastexit")))
{
FPlatformMisc::RequestExitWithStatus(true, ReturnCode);
}
else
{
TRACE_CPUPROFILER_EVENT_SCOPE(Shutdown);
GConfig->DisableFileOperations(); // We don't want to write out any config file changes!
// Even though we are exiting anyway we need to request an engine exit in order to get a clean shutdown
RequestEngineExit(TEXT("The process has finished"));
FEngineLoop::AppPreExit();
FModuleManager::Get().UnloadModulesAtShutdown();
FEngineLoop::AppExit();
}
return ReturnCode;
}
INT32_MAIN_INT32_ARGC_TCHAR_ARGV()
{
FTaskTagScope Scope(ETaskTag::EGameThread);
return UnrealVirtualizationToolMain(ArgC, ArgV);
}