Process launcher updates (#6183)

* Enable process and ap connection tests on linux
* Updated 'OpenProjectManager' to use new the ProcessLauncher argument type
* Add logic to double-escape escaped double quotes in arguments on windows platforms
* Updated argument for LaunchProjectManager to reflect new ProcessLauncher argument type
* Fixed unit test arguments for 'arg=value' condition
* Fix compile errors for BuilderManager and RHI.Edit\Utils.cpp
* PAL'ify the GetCommandLineParametersAsString() to handle windows specific behavior

Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>

Co-authored-by: byrcolin <byrcolin@amazon.com>
This commit is contained in:
Steve Pham
2021-12-08 09:30:19 -08:00
committed by GitHub
parent 29da71e64e
commit 558532f094
17 changed files with 285 additions and 180 deletions
@@ -155,7 +155,7 @@ namespace AssetProcessor
return false;
}
const AZStd::string params = BuildParams("resident", buildersFolder.c_str(), UuidString(), "", "");
const AZStd::vector<AZStd::string> params = BuildParams("resident", buildersFolder.c_str(), UuidString(), "", "");
m_processWatcher = LaunchProcess(fullExePathString.c_str(), params);
@@ -179,7 +179,7 @@ namespace AssetProcessor
return !m_processWatcher || (m_processWatcher && m_processWatcher->IsProcessRunning(exitCode));
}
AZStd::string Builder::BuildParams(const char* task, const char* moduleFilePath, const AZStd::string& builderGuid, const AZStd::string& jobDescriptionFile, const AZStd::string& jobResponseFile) const
AZStd::vector<AZStd::string> Builder::BuildParams(const char* task, const char* moduleFilePath, const AZStd::string& builderGuid, const AZStd::string& jobDescriptionFile, const AZStd::string& jobResponseFile) const
{
QDir projectCacheRoot;
AssetUtilities::ComputeProjectCacheRoot(projectCacheRoot);
@@ -191,35 +191,24 @@ namespace AssetProcessor
int portNumber = 0;
ApplicationServerBus::BroadcastResult(portNumber, &ApplicationServerBus::Events::GetServerListeningPort);
AZStd::string params;
#if !AZ_TRAIT_OS_PLATFORM_APPLE && !AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
params = AZStd::string::format(
R"(-task=%s -id="%s" -project-name="%s" -project-cache-path="%s" -project-path="%s" -engine-path="%s" -port %d)",
task, builderGuid.c_str(), projectName.c_str(), projectCacheRoot.absolutePath().toUtf8().constData(),
projectPath.c_str(), enginePath.c_str(), portNumber);
#else
params = AZStd::string::format(
R"(-task=%s -id="%s" -project-name="\"%s\"" -project-cache-path="\"%s\"" -project-path="\"%s\"" -engine-path="\"%s\"" -port %d)",
task, builderGuid.c_str(), projectName.c_str(), projectCacheRoot.absolutePath().toUtf8().constData(),
projectPath.c_str(), enginePath.c_str(), portNumber);
#endif // !AZ_TRAIT_OS_PLATFORM_APPLE && !AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
AZStd::vector<AZStd::string> params;
params.emplace_back(AZStd::string::format(R"(-task="%s")", task));
params.emplace_back(AZStd::string::format(R"(-id="%s")", builderGuid.c_str()));
params.emplace_back(AZStd::string::format(R"(-project-name="%s")", projectName.c_str()));
params.emplace_back(AZStd::string::format(R"(-project-cache-path="%s")", projectCacheRoot.absolutePath().toUtf8().constData()));
params.emplace_back(AZStd::string::format(R"(-project-path="%s")", projectPath.c_str()));
params.emplace_back(AZStd::string::format(R"(-engine-path="%s")", enginePath.c_str()));
params.emplace_back(AZStd::string::format("-port=%d", portNumber));
if (moduleFilePath && moduleFilePath[0])
{
#if !AZ_TRAIT_OS_PLATFORM_APPLE && !AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
params.append(AZStd::string::format(R"( -module="%s")", moduleFilePath).c_str());
#else
params.append(AZStd::string::format(R"( -module="\"%s\"")", moduleFilePath).c_str());
#endif // !AZ_TRAIT_OS_PLATFORM_APPLE && !AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
params.emplace_back(AZStd::string::format(R"(-module="%s")", moduleFilePath));
}
if (!jobDescriptionFile.empty() && !jobResponseFile.empty())
{
#if !AZ_TRAIT_OS_PLATFORM_APPLE && !AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
params = AZStd::string::format(R"(%s -input="%s" -output="%s")", params.c_str(), jobDescriptionFile.c_str(), jobResponseFile.c_str());
#else
params = AZStd::string::format(R"(%s -input="\"%s\"" -output="\"%s\"")", params.c_str(), jobDescriptionFile.c_str(), jobResponseFile.c_str());
#endif // !AZ_TRAIT_OS_PLATFORM_APPLE && !AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
params.emplace_back(AZStd::string::format(R"(-input="%s")", jobDescriptionFile.c_str()));
params.emplace_back(AZStd::string::format(R"(-output="%s")", jobResponseFile.c_str()));
}
auto settingsRegistry = AZ::SettingsRegistry::Get();
@@ -232,28 +221,25 @@ namespace AssetProcessor
for (size_t optionIndex = 0; optionIndex < commandOptionCount; ++optionIndex)
{
const AZStd::string& optionValue = commandLine.GetSwitchValue(optionKey, optionIndex);
params.append(AZStd::string::format(
#if !AZ_TRAIT_OS_PLATFORM_APPLE && !AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS
R"( --%s="%s")",
#else
R"( --%s="\"%s\"")",
#endif
optionKey, optionValue.c_str()));
params.emplace_back(AZStd::string::format(R"(--%s="%s")", optionKey, optionValue.c_str()));
}
}
return params;
}
AZStd::unique_ptr<AzFramework::ProcessWatcher> Builder::LaunchProcess(const char* fullExePath, const AZStd::string& params) const
AZStd::unique_ptr<AzFramework::ProcessWatcher> Builder::LaunchProcess(const char* fullExePath, const AZStd::vector<AZStd::string>& params) const
{
AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
processLaunchInfo.m_processExecutableString = fullExePath;
processLaunchInfo.m_commandlineParameters = AZStd::string::format("\"%s\" %s", fullExePath, params.c_str());
AZStd::vector<AZStd::string> commandLineArray{ fullExePath };
commandLineArray.insert(commandLineArray.end(), params.begin(), params.end());
processLaunchInfo.m_commandlineParameters = AZStd::move(commandLineArray);
processLaunchInfo.m_showWindow = false;
processLaunchInfo.m_processPriority = AzFramework::ProcessPriority::PROCESSPRIORITY_IDLE;
AZ_TracePrintf(AssetProcessor::DebugChannel, "Executing AssetBuilder with parameters: %s\n", processLaunchInfo.m_commandlineParameters.c_str());
AZ_TracePrintf(AssetProcessor::DebugChannel, "Executing AssetBuilder with parameters: %s\n", processLaunchInfo.GetCommandLineParametersAsString().c_str());
auto processWatcher = AZStd::unique_ptr<AzFramework::ProcessWatcher>(AzFramework::ProcessWatcher::LaunchProcess(processLaunchInfo, AzFramework::ProcessCommunicationType::COMMUNICATOR_TYPE_STDINOUT));