Update to the latest Platform::CreateProcess

This commit is contained in:
Wojtek Figat
2023-03-22 14:18:52 +01:00
parent c31e4023c4
commit 7d4bf8356e
11 changed files with 103 additions and 32 deletions

View File

@@ -23,6 +23,7 @@
#include "Steps/CookAssetsStep.h"
#include "Steps/PostProcessStep.h"
#include "Engine/Platform/ConditionVariable.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Scripting/ManagedCLR/MDomain.h"
#include "Engine/Scripting/ManagedCLR/MCore.h"
#include "Engine/Scripting/ManagedCLR/MAssembly.h"
@@ -686,7 +687,15 @@ bool GameCookerImpl::Build()
const String commandLine = commandLineFormat.HasChars() ? String::Format(*commandLineFormat, gameArgs) : gameArgs;
if (workingDir.IsEmpty())
workingDir = data.NativeCodeOutputPath;
Platform::StartProcess(executableFile, commandLine, workingDir);
CreateProcessSettings procSettings;
procSettings.FileName = executableFile;
procSettings.Arguments = commandLine;
procSettings.WorkingDirectory = workingDir;
procSettings.HiddenWindow = false;
procSettings.WaitForEnd = false;
procSettings.LogOutput = false;
procSettings.ShellExecute = true;
Platform::CreateProcess(procSettings);
}
else
{

View File

@@ -9,6 +9,7 @@
#include "Editor/Utilities/EditorUtilities.h"
#include "Engine/Platform/File.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Platform/Android/AndroidPlatformSettings.h"
#include "Engine/Graphics/PixelFormatExtensions.h"
#include "Engine/Graphics/Textures/TextureData.h"
@@ -309,8 +310,10 @@ bool AndroidPlatformTools::OnPostProcess(CookingData& data)
Platform::RunProcess(String::Format(TEXT("chmod +x \"{0}/gradlew\""), data.OriginalOutputPath), data.OriginalOutputPath, Dictionary<String, String>(), true);
#endif
const bool distributionPackage = buildSettings->ForDistribution;
const String gradleCommand = String::Format(TEXT("\"{0}\" {1}"), data.OriginalOutputPath / gradlew, distributionPackage ? TEXT("assemble") : TEXT("assembleDebug"));
const int32 result = Platform::RunProcess(gradleCommand, data.OriginalOutputPath, Dictionary<String, String>(), true);
CreateProcessSettings procSettings;
procSettings.FileName = String::Format(TEXT("\"{0}\" {1}"), data.OriginalOutputPath / gradlew, distributionPackage ? TEXT("assemble") : TEXT("assembleDebug"));
procSettings.WorkingDirectory = data.OriginalOutputPath;
const int32 result = Platform::CreateProcess(procSettings);
if (result != 0)
{
data.Error(TEXT("Failed to build Gradle project into package (result code: {0}). See log for more info."), result);

View File

@@ -5,6 +5,7 @@
#include "GDKPlatformTools.h"
#include "Engine/Platform/File.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Platform/GDK/GDKPlatformSettings.h"
#include "Engine/Core/Types/StringBuilder.h"
#include "Engine/Core/Collections/Sorting.h"
@@ -126,9 +127,11 @@ bool GDKPlatformTools::OnPerformAOT(CookingData& data, AotConfig& config, const
FileSystem::DeleteFile(resultPathPdb);
// Call tool
const String workingDir = StringUtils::GetDirectoryName(config.AotCompilerPath);
const String command = String::Format(TEXT("\"{0}\" {1} \"{2}\""), config.AotCompilerPath, config.AotCompilerArgs, assemblyPath);
const int32 result = Platform::RunProcess(command, workingDir, config.EnvVars);
CreateProcessSettings procSettings;
procSettings.FileName = String::Format(TEXT("\"{0}\" {1} \"{2}\""), config.AotCompilerPath, config.AotCompilerArgs, assemblyPath);
procSettings.WorkingDirectory = StringUtils::GetDirectoryName(config.AotCompilerPath);
procSettings.Environment = config.EnvVars;
const int32 result = Platform::CreateProcess(procSettings);
if (result != 0)
{
data.Error(TEXT("AOT tool execution failed with result code {1} for assembly \"{0}\". See log for more info."), assemblyPath, result);
@@ -275,8 +278,10 @@ bool GDKPlatformTools::OnPostProcess(CookingData& data, GDKPlatformSettings* pla
data.StepProgress(TEXT("Generating package layout"), 0.3f);
const String gdkBinPath = _gdkPath / TEXT("../bin");
const String makePkgPath = gdkBinPath / TEXT("MakePkg.exe");
const String command = String::Format(TEXT("\"{0}\" genmap /f layout.xml /d \"{1}\""), makePkgPath, data.DataOutputPath);
const int32 result = Platform::RunProcess(command, data.DataOutputPath);
CreateProcessSettings procSettings;
procSettings.FileName = String::Format(TEXT("\"{0}\" genmap /f layout.xml /d \"{1}\""), makePkgPath, data.DataOutputPath);
procSettings.WorkingDirectory = data.DataOutputPath;
const int32 result = Platform::CreateProcess(procSettings);
if (result != 0)
{
data.Error(TEXT("Failed to generate package layout."));

View File

@@ -5,6 +5,7 @@
#include "UWPPlatformTools.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/File.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Platform/UWP/UWPPlatformSettings.h"
#include "Engine/Core/Config/GameSettings.h"
#include "Engine/Core/Types/StringBuilder.h"
@@ -460,9 +461,11 @@ bool UWPPlatformTools::OnPerformAOT(CookingData& data, AotConfig& config, const
FileSystem::DeleteFile(resultPathPdb);
// Call tool
String workingDir = StringUtils::GetDirectoryName(config.AotCompilerPath);
String command = String::Format(TEXT("\"{0}\" {1} \"{2}\""), config.AotCompilerPath, config.AotCompilerArgs, assemblyPath);
const int32 result = Platform::RunProcess(command, workingDir, config.EnvVars);
CreateProcessSettings procSettings;
procSettings.FileName = String::Format(TEXT("\"{0}\" {1} \"{2}\""), config.AotCompilerPath, config.AotCompilerArgs, assemblyPath);
procSettings.WorkingDirectory = StringUtils::GetDirectoryName(config.AotCompilerPath);
procSettings.Environment = config.EnvVars;
const int32 result = Platform::CreateProcess(procSettings);
if (result != 0)
{
data.Error(TEXT("AOT tool execution failed with result code {1} for assembly \"{0}\". See log for more info."), assemblyPath, result);

View File

@@ -697,9 +697,16 @@ namespace FlaxEditor
// Invoke new instance if need to open a project
if (!string.IsNullOrEmpty(_projectToOpen))
{
string args = string.Format("-project \"{0}\"", _projectToOpen);
var procSettings = new CreateProcessSettings
{
FileName = Platform.ExecutableFilePath,
Arguments = string.Format("-project \"{0}\"", _projectToOpen),
ShellExecute = true,
WaitForEnd = false,
HiddenWindow = false,
};
_projectToOpen = null;
Platform.StartProcess(Platform.ExecutableFilePath, args, null);
Platform.CreateProcess(ref procSettings);
}
}

View File

@@ -9,6 +9,7 @@
#include "Engine/Engine/Globals.h"
#include "Engine/Core/Collections/Sorting.h"
#include "Engine/Platform/File.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Serialization/Json.h"
#if PLATFORM_WINDOWS
@@ -242,8 +243,14 @@ void RiderCodeEditor::OpenFile(const String& path, int32 line)
// Open file
line = line > 0 ? line : 1;
const String args = String::Format(TEXT("\"{0}\" --line {2} \"{1}\""), _solutionPath, path, line);
Platform::StartProcess(_execPath, args, StringView::Empty);
CreateProcessSettings procSettings;
procSettings.FileName = _execPath;
procSettings.Arguments = String::Format(TEXT("\"{0}\" --line {2} \"{1}\""), _solutionPath, path, line);
procSettings.HiddenWindow = false;
procSettings.WaitForEnd = false;
procSettings.LogOutput = false;
procSettings.ShellExecute = true;
Platform::CreateProcess(procSettings);
}
void RiderCodeEditor::OpenSolution()
@@ -255,8 +262,14 @@ void RiderCodeEditor::OpenSolution()
}
// Open solution
const String args = String::Format(TEXT("\"{0}\""), _solutionPath);
Platform::StartProcess(_execPath, args, StringView::Empty);
CreateProcessSettings procSettings;
procSettings.FileName = _execPath;
procSettings.Arguments = String::Format(TEXT("\"{0}\""), _solutionPath);
procSettings.HiddenWindow = false;
procSettings.WaitForEnd = false;
procSettings.LogOutput = false;
procSettings.ShellExecute = true;
Platform::CreateProcess(procSettings);
}
void RiderCodeEditor::OnFileAdded(const String& path)

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#include "SystemDefaultCodeEditor.h"
#include "Engine/Core/Types/StringView.h"
#include "Engine/Platform/CreateProcessSettings.h"
CodeEditorTypes SystemDefaultCodeEditor::GetType() const
{
@@ -15,7 +15,13 @@ String SystemDefaultCodeEditor::GetName() const
void SystemDefaultCodeEditor::OpenFile(const String& path, int32 line)
{
Platform::StartProcess(path, StringView::Empty, StringView::Empty);
CreateProcessSettings procSettings;
procSettings.FileName = path;
procSettings.HiddenWindow = false;
procSettings.WaitForEnd = false;
procSettings.LogOutput = false;
procSettings.ShellExecute = true;
Platform::CreateProcess(procSettings);
}
void SystemDefaultCodeEditor::OpenSolution()

View File

@@ -2,14 +2,16 @@
#include "VisualStudioCodeEditor.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Core/Log.h"
#include "Editor/Editor.h"
#include "Editor/ProjectInfo.h"
#include "Editor/Scripting/ScriptsBuilder.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Platform/Win32/IncludeWindowsHeaders.h"
#if PLATFORM_LINUX
#include <stdio.h>
#elif PLATFORM_WINDOWS
#include "Engine/Platform/Win32/IncludeWindowsHeaders.h"
#elif PLATFORM_MAC
#include "Engine/Platform/Apple/AppleUtils.h"
#include <AppKit/AppKit.h>
@@ -140,8 +142,14 @@ void VisualStudioCodeEditor::OpenFile(const String& path, int32 line)
// Open file
line = line > 0 ? line : 1;
const String args = String::Format(TEXT("\"{0}\" -g \"{1}\":{2}"), _workspacePath, path, line);
Platform::StartProcess(_execPath, args, StringView::Empty);
CreateProcessSettings procSettings;
procSettings.FileName = _execPath;
procSettings.Arguments = String::Format(TEXT("\"{0}\" -g \"{1}\":{2}"), _workspacePath, path, line);
procSettings.HiddenWindow = false;
procSettings.WaitForEnd = false;
procSettings.LogOutput = false;
procSettings.ShellExecute = true;
Platform::CreateProcess(procSettings);
}
void VisualStudioCodeEditor::OpenSolution()
@@ -160,8 +168,14 @@ void VisualStudioCodeEditor::OpenSolution()
}
// Open solution
const String args = String::Format(TEXT("\"{0}\""), _workspacePath);
Platform::StartProcess(_execPath, args, StringView::Empty);
CreateProcessSettings procSettings;
procSettings.FileName = _execPath;
procSettings.Arguments = String::Format(TEXT("\"{0}\""), _workspacePath);
procSettings.HiddenWindow = false;
procSettings.WaitForEnd = false;
procSettings.LogOutput = false;
procSettings.ShellExecute = true;
Platform::CreateProcess(procSettings);
}
bool VisualStudioCodeEditor::UseAsyncForOpen() const

View File

@@ -10,9 +10,10 @@
#include "Engine/Debug/Exceptions/FileNotFoundException.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Engine/Globals.h"
#include "Engine/Engine/EngineService.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/FileSystemWatcher.h"
#include "Engine/Threading/ThreadPool.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Threading/Threading.h"
#include "Engine/Scripting/MainThreadManagedInvokeAction.h"
#include "Engine/Scripting/ScriptingType.h"
@@ -21,7 +22,6 @@
#include "Engine/Scripting/ManagedCLR/MClass.h"
#include "Engine/Scripting/Scripting.h"
#include "Engine/Scripting/Script.h"
#include "Engine/Engine/EngineService.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Level/Level.h"
#include "FlaxEngine.Gen.h"
@@ -253,7 +253,10 @@ bool ScriptsBuilder::RunBuildTool(const StringView& args, const StringView& work
// TODO: Set env var for the mono MONO_GC_PARAMS=nursery-size64m to boost build performance -> profile it
// Call build tool
const int32 result = Platform::RunProcess(StringView(*cmdLine, cmdLine.Length()), workingDir);
CreateProcessSettings procSettings;
procSettings.FileName = StringView(*cmdLine, cmdLine.Length());
procSettings.WorkingDirectory = workingDir;
const int32 result = Platform::CreateProcess(procSettings);
if (result != 0)
LOG(Error, "Failed to run build tool, result: {0:x}", (uint32)result);
return result != 0;

View File

@@ -4,6 +4,7 @@
#include "Engine/Engine/Globals.h"
#include "Engine/Platform/File.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/CreateProcessSettings.h"
#include "Engine/Core/Log.h"
#include "Engine/Graphics/Textures/TextureData.h"
#include "Engine/Graphics/PixelFormatExtensions.h"
@@ -726,8 +727,9 @@ bool EditorUtilities::GenerateCertificate(const String& name, const String& outp
// MakeCert
auto path = wdkPath / TEXT("makecert.exe");
auto args = String::Format(TEXT("\"{0}\" /r /h 0 /eku \"1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13\" /m 12 /len 2048 /n \"CN={1}\" -sv \"{2}\" \"{3}\""), path, name, outputPvkFilePath, outputCerFilePath);
int32 result = Platform::RunProcess(args, String::Empty);
CreateProcessSettings procSettings;
procSettings.FileName = String::Format(TEXT("\"{0}\" /r /h 0 /eku \"1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13\" /m 12 /len 2048 /n \"CN={1}\" -sv \"{2}\" \"{3}\""), path, name, outputPvkFilePath, outputCerFilePath);
int32 result = Platform::CreateProcess(procSettings);
if (result != 0)
{
LOG(Warning, "MakeCert failed with result {0}.", result);
@@ -736,8 +738,8 @@ bool EditorUtilities::GenerateCertificate(const String& name, const String& outp
// Pvk2Pfx
path = wdkPath / TEXT("pvk2pfx.exe");
args = String::Format(TEXT("\"{0}\" -pvk \"{1}\" -spc \"{2}\" -pfx \"{3}\""), path, outputPvkFilePath, outputCerFilePath, outputPfxFilePath);
result = Platform::RunProcess(args, String::Empty);
procSettings.FileName = String::Format(TEXT("\"{0}\" -pvk \"{1}\" -spc \"{2}\" -pfx \"{3}\""), path, outputPvkFilePath, outputCerFilePath, outputPfxFilePath);
result = Platform::CreateProcess(procSettings);
if (result != 0)
{
LOG(Warning, "MakeCert failed with result {0}.", result);

View File

@@ -569,7 +569,13 @@ namespace FlaxEditor.Windows
{
var tmpBat = StringUtils.CombinePaths(Globals.TemporaryFolder, Guid.NewGuid().ToString("N") + ".bat");
File.WriteAllText(tmpBat, command);
Platform.StartProcess(tmpBat, null, null, true, true);
var procSettings = new CreateProcessSettings
{
FileName = tmpBat,
HiddenWindow = true,
WaitForEnd = true,
};
Platform.CreateProcess(ref procSettings);
File.Delete(tmpBat);
}
catch (Exception ex)