|
|
|
@ -8,189 +8,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <ProjectBuilderWorker.h>
|
|
|
|
#include <ProjectBuilderWorker.h>
|
|
|
|
#include <ProjectManagerDefs.h>
|
|
|
|
#include <ProjectManagerDefs.h>
|
|
|
|
#include <PythonBindingsInterface.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QString>
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
|
|
#include <QProcessEnvironment>
|
|
|
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace O3DE::ProjectManager
|
|
|
|
namespace O3DE::ProjectManager
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AZ::Outcome<void, QString> ProjectBuilderWorker::BuildProjectForPlatform()
|
|
|
|
AZ::Outcome<QStringList, QString> ProjectBuilderWorker::ConstructCmakeGenerateProjectArguments(const QString& thirdPartyPath) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Check if we are trying to cancel task
|
|
|
|
QString targetBuildPath = QDir(m_projectInfo.m_path).filePath(ProjectBuildPathPostfix);
|
|
|
|
if (QThread::currentThread()->isInterruptionRequested())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QStringToAZTracePrint(BuildCancelled);
|
|
|
|
|
|
|
|
return AZ::Failure(BuildCancelled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFile logFile(GetLogFilePath());
|
|
|
|
return AZ::Success(QStringList{ ProjectCMakeCommand,
|
|
|
|
if (!logFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate))
|
|
|
|
"-B", targetBuildPath,
|
|
|
|
{
|
|
|
|
"-S", m_projectInfo.m_path,
|
|
|
|
QString error = tr("Failed to open log file.");
|
|
|
|
QString("-DLY_3RDPARTY_PATH=").append(thirdPartyPath),
|
|
|
|
QStringToAZTracePrint(error);
|
|
|
|
"-DLY_UNITY_BUILD=ON" } );
|
|
|
|
return AZ::Failure(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EngineInfo engineInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AZ::Outcome<EngineInfo> engineInfoResult = PythonBindingsInterface::Get()->GetEngineInfo();
|
|
|
|
|
|
|
|
if (engineInfoResult.IsSuccess())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
engineInfo = engineInfoResult.GetValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString error = tr("Failed to get engine info.");
|
|
|
|
|
|
|
|
QStringToAZTracePrint(error);
|
|
|
|
|
|
|
|
return AZ::Failure(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QTextStream logStream(&logFile);
|
|
|
|
|
|
|
|
if (QThread::currentThread()->isInterruptionRequested())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
logFile.close();
|
|
|
|
|
|
|
|
QStringToAZTracePrint(BuildCancelled);
|
|
|
|
|
|
|
|
return AZ::Failure(BuildCancelled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Show some kind of progress with very approximate estimates
|
|
|
|
|
|
|
|
UpdateProgress(++m_progressEstimate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QProcessEnvironment currentEnvironment(QProcessEnvironment::systemEnvironment());
|
|
|
|
|
|
|
|
// Append cmake path to PATH incase it is missing
|
|
|
|
|
|
|
|
QDir cmakePath(engineInfo.m_path);
|
|
|
|
|
|
|
|
cmakePath.cd("cmake/runtime/bin");
|
|
|
|
|
|
|
|
QString pathValue = currentEnvironment.value("PATH");
|
|
|
|
|
|
|
|
pathValue += ";" + cmakePath.path();
|
|
|
|
|
|
|
|
currentEnvironment.insert("PATH", pathValue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_configProjectProcess = new QProcess(this);
|
|
|
|
|
|
|
|
m_configProjectProcess->setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
|
|
|
|
m_configProjectProcess->setWorkingDirectory(m_projectInfo.m_path);
|
|
|
|
|
|
|
|
m_configProjectProcess->setProcessEnvironment(currentEnvironment);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_configProjectProcess->start(
|
|
|
|
|
|
|
|
"cmake",
|
|
|
|
|
|
|
|
QStringList
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"-B",
|
|
|
|
|
|
|
|
QDir(m_projectInfo.m_path).filePath(ProjectBuildPathPostfix),
|
|
|
|
|
|
|
|
"-S",
|
|
|
|
|
|
|
|
m_projectInfo.m_path,
|
|
|
|
|
|
|
|
"-G",
|
|
|
|
|
|
|
|
"Visual Studio 16",
|
|
|
|
|
|
|
|
"-DLY_3RDPARTY_PATH=" + engineInfo.m_thirdPartyPath,
|
|
|
|
|
|
|
|
"-DLY_UNITY_BUILD=1"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_configProjectProcess->waitForStarted())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString error = tr("Configuring project failed to start.");
|
|
|
|
|
|
|
|
QStringToAZTracePrint(error);
|
|
|
|
|
|
|
|
return AZ::Failure(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool containsGeneratingDone = false;
|
|
|
|
|
|
|
|
while (m_configProjectProcess->waitForReadyRead(MaxBuildTimeMSecs))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString configOutput = m_configProjectProcess->readAllStandardOutput();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (configOutput.contains("Generating done"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
containsGeneratingDone = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logStream << configOutput;
|
|
|
|
|
|
|
|
logStream.flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateProgress(qMin(++m_progressEstimate, 19));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (QThread::currentThread()->isInterruptionRequested())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
logFile.close();
|
|
|
|
|
|
|
|
m_configProjectProcess->close();
|
|
|
|
|
|
|
|
QStringToAZTracePrint(BuildCancelled);
|
|
|
|
|
|
|
|
return AZ::Failure(BuildCancelled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_configProjectProcess->exitStatus() != QProcess::ExitStatus::NormalExit
|
|
|
|
|
|
|
|
|| m_configProjectProcess->exitCode() != 0
|
|
|
|
|
|
|
|
|| !containsGeneratingDone)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString error = tr("Configuring project failed. See log for details.");
|
|
|
|
|
|
|
|
QStringToAZTracePrint(error);
|
|
|
|
|
|
|
|
return AZ::Failure(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UpdateProgress(++m_progressEstimate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_buildProjectProcess = new QProcess(this);
|
|
|
|
|
|
|
|
m_buildProjectProcess->setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
|
|
|
|
m_buildProjectProcess->setWorkingDirectory(m_projectInfo.m_path);
|
|
|
|
|
|
|
|
m_buildProjectProcess->setProcessEnvironment(currentEnvironment);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_buildProjectProcess->start(
|
|
|
|
|
|
|
|
"cmake",
|
|
|
|
|
|
|
|
QStringList
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"--build",
|
|
|
|
|
|
|
|
QDir(m_projectInfo.m_path).filePath(ProjectBuildPathPostfix),
|
|
|
|
|
|
|
|
"--target",
|
|
|
|
|
|
|
|
m_projectInfo.m_projectName + ".GameLauncher",
|
|
|
|
|
|
|
|
"Editor",
|
|
|
|
|
|
|
|
"--config",
|
|
|
|
|
|
|
|
"profile"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!m_buildProjectProcess->waitForStarted())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString error = tr("Building project failed to start.");
|
|
|
|
|
|
|
|
QStringToAZTracePrint(error);
|
|
|
|
|
|
|
|
return AZ::Failure(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// There are a lot of steps when building so estimate around 800 more steps ((100 - 20) * 10) remaining
|
|
|
|
|
|
|
|
m_progressEstimate = 200;
|
|
|
|
|
|
|
|
while (m_buildProjectProcess->waitForReadyRead(MaxBuildTimeMSecs))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
logStream << m_buildProjectProcess->readAllStandardOutput();
|
|
|
|
|
|
|
|
logStream.flush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Show 1% progress for every 10 steps completed
|
|
|
|
|
|
|
|
UpdateProgress(qMin(++m_progressEstimate / 10, 99));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (QThread::currentThread()->isInterruptionRequested())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// QProcess is unable to kill its child processes so we need to ask the operating system to do that for us
|
|
|
|
|
|
|
|
QProcess killBuildProcess;
|
|
|
|
|
|
|
|
killBuildProcess.setProcessChannelMode(QProcess::MergedChannels);
|
|
|
|
|
|
|
|
killBuildProcess.start(
|
|
|
|
|
|
|
|
"cmd.exe", QStringList{ "/C", "taskkill", "/pid", QString::number(m_buildProjectProcess->processId()), "/f", "/t" });
|
|
|
|
|
|
|
|
killBuildProcess.waitForFinished();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logStream << "Killing Project Build.";
|
|
|
|
AZ::Outcome<QStringList, QString> ProjectBuilderWorker::ConstructCmakeBuildCommandArguments() const
|
|
|
|
logStream << killBuildProcess.readAllStandardOutput();
|
|
|
|
{
|
|
|
|
m_buildProjectProcess->kill();
|
|
|
|
QString targetBuildPath = QDir(m_projectInfo.m_path).filePath(ProjectBuildPathPostfix);
|
|
|
|
logFile.close();
|
|
|
|
QString launcherTargetName = m_projectInfo.m_projectName + ".GameLauncher";
|
|
|
|
QStringToAZTracePrint(BuildCancelled);
|
|
|
|
|
|
|
|
return AZ::Failure(BuildCancelled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (m_configProjectProcess->exitStatus() != QProcess::ExitStatus::NormalExit
|
|
|
|
return AZ::Success(QStringList{ ProjectCMakeCommand,
|
|
|
|
|| m_configProjectProcess->exitCode() != 0)
|
|
|
|
"--build", targetBuildPath,
|
|
|
|
{
|
|
|
|
"--config", "profile",
|
|
|
|
QString error = tr("Building project failed. See log for details.");
|
|
|
|
"--target", launcherTargetName, ProjectCMakeBuildTargetEditor });
|
|
|
|
QStringToAZTracePrint(error);
|
|
|
|
}
|
|
|
|
return AZ::Failure(error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return AZ::Success();
|
|
|
|
AZ::Outcome<QStringList, QString> ProjectBuilderWorker::ConstructKillProcessCommandArguments(const QString& pidToKill) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return AZ::Success(QStringList { "cmd.exe", "/C", "taskkill", "/pid", pidToKill, "/f", "/t" } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace O3DE::ProjectManager
|
|
|
|
} // namespace O3DE::ProjectManager
|
|
|
|
|