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:
@@ -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));
|
||||
|
||||
|
||||
@@ -103,8 +103,8 @@ namespace AssetProcessor
|
||||
//! Sets the connection id and signals that the builder has connected
|
||||
void SetConnection(AZ::u32 connId);
|
||||
|
||||
AZStd::string BuildParams(const char* task, const char* moduleFilePath, const AZStd::string& builderGuid, const AZStd::string& jobDescriptionFile, const AZStd::string& jobResponseFile) const;
|
||||
AZStd::unique_ptr<AzFramework::ProcessWatcher> LaunchProcess(const char* fullExePath, const AZStd::string& params) const;
|
||||
AZStd::vector<AZStd::string> BuildParams(const char* task, const char* moduleFilePath, const AZStd::string& builderGuid, const AZStd::string& jobDescriptionFile, const AZStd::string& jobResponseFile) const;
|
||||
AZStd::unique_ptr<AzFramework::ProcessWatcher> LaunchProcess(const char* fullExePath, const AZStd::vector<AZStd::string>& params) const;
|
||||
|
||||
//! Waits for the builder exe to send the job response and pumps stdout/err
|
||||
BuilderRunJobOutcome WaitForBuilderResponse(AssetBuilderSDK::JobCancelListener* jobCancelListener, AZ::u32 processTimeoutLimitInSeconds, AZStd::binary_semaphore* waitEvent) const;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/StringFunc/StringFunc.h>
|
||||
|
||||
namespace AssetProcessor
|
||||
{
|
||||
//! Sends the job over to the builder and blocks until the response is received or the builder crashes/times out
|
||||
@@ -82,10 +84,12 @@ namespace AssetProcessor
|
||||
}
|
||||
|
||||
auto params = BuildParams(task.c_str(), modulePath.c_str(), "", jobRequestFile, jobResponseFile);
|
||||
AZStd::string paramString;
|
||||
AZ::StringFunc::Join(paramString, params.begin(), params.end(), " ");
|
||||
|
||||
AZ_TracePrintf(AssetProcessor::DebugChannel, "Job request written to %s\n", jobRequestFile.c_str());
|
||||
AZ_TracePrintf(AssetProcessor::DebugChannel, "To re-run this request manually, run AssetBuilder with the following parameters:\n");
|
||||
AZ_TracePrintf(AssetProcessor::DebugChannel, "%s\n", params.c_str());
|
||||
AZ_TracePrintf(AssetProcessor::DebugChannel, "%s\n", paramString.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -424,12 +424,12 @@ namespace O3DE::ProjectManager
|
||||
return;
|
||||
}
|
||||
|
||||
auto cmdPath = AZ::IO::FixedMaxPathString::format(
|
||||
"%s --regset=\"/Amazon/AzCore/Bootstrap/project_path=%s\"", editorExecutablePath.c_str(),
|
||||
fixedProjectPath.c_str());
|
||||
|
||||
AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
|
||||
processLaunchInfo.m_commandlineParameters = cmdPath;
|
||||
processLaunchInfo.m_commandlineParameters = AZStd::vector<AZStd::string>{
|
||||
editorExecutablePath.String(),
|
||||
AZStd::string::format(R"(--regset="/Amazon/AzCore/Bootstrap/project_path=%s")", fixedProjectPath.c_str())
|
||||
};
|
||||
;
|
||||
bool launchSucceeded = AzFramework::ProcessLauncher::LaunchUnwatchedProcess(processLaunchInfo);
|
||||
if (!launchSucceeded)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user