Use different method to run unity to ensure it exits without hanging

This commit is contained in:
Andrew Kahr 2023-10-21 21:12:00 -07:00
parent d74bb9d4ad
commit 32e3b41ff7
3 changed files with 43 additions and 35 deletions

7
.vscode/launch.json vendored
View File

@ -1,5 +1,12 @@
{
"configurations": [
{
"name": "PowerShell Launch Current File",
"type": "PowerShell",
"request": "launch",
"script": "${file}",
"cwd": "${cwd}"
},
{
"type": "node",
"request": "launch",

View File

@ -131,27 +131,44 @@ Write-Output ""
# If $Env:CUSTOM_PARAMETERS contains spaces and is passed directly on the command line to Unity, powershell will wrap it
# in double quotes. To avoid this, parse $Env:CUSTOM_PARAMETERS into an array, while respecting any quotations within the string.
$_, $customParametersArray = Invoke-Expression('Write-Output -- "" ' + $Env:CUSTOM_PARAMETERS)
$_, $customParametersArray = Invoke-Expression('Write-Output -- "" ' + $Env:CUSTOM_PARAMETERS) | ForEach-Object { $_.ToString() }
& "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" -quit -batchmode -nographics `
-projectPath $Env:UNITY_PROJECT_PATH `
-executeMethod $Env:BUILD_METHOD `
-buildTarget $Env:BUILD_TARGET `
-customBuildTarget $Env:BUILD_TARGET `
-customBuildPath $Env:CUSTOM_BUILD_PATH `
-buildVersion $Env:VERSION `
-androidVersionCode $Env:ANDROID_VERSION_CODE `
-androidKeystorePass $Env:ANDROID_KEYSTORE_PASS `
-androidKeyaliasName $Env:ANDROID_KEYALIAS_NAME `
-androidKeyaliasPass $Env:ANDROID_KEYALIAS_PASS `
-androidTargetSdkVersion $Env:ANDROID_TARGET_SDK_VERSION `
-androidExportType $Env:ANDROID_EXPORT_TYPE `
-androidSymbolType $Env:ANDROID_SYMBOL_TYPE `
$customParametersArray `
-logfile | Out-Host
$process = Start-Process -FilePath "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" `
-ArgumentList @("-quit",
"-batchmode",
"-nographics",
"-projectPath", $Env:UNITY_PROJECT_PATH,
"-executeMethod", $Env:BUILD_METHOD,
"-buildTarget", $Env:BUILD_TARGET,
"-customBuildTarget", $Env:BUILD_TARGET,
"-customBuildPath", $Env:CUSTOM_BUILD_PATH,
"-buildVersion", $Env:VERSION,
"-androidVersionCode", $Env:ANDROID_VERSION_CODE,
"-androidKeystorePass", $Env:ANDROID_KEYSTORE_PASS,
"-androidKeyaliasName", $Env:ANDROID_KEYALIAS_NAME,
"-androidKeyaliasPass", $Env:ANDROID_KEYALIAS_PASS,
"-androidTargetSdkVersion", $Env:ANDROID_TARGET_SDK_VERSION,
"-androidExportType", $Env:ANDROID_EXPORT_TYPE,
"-androidSymbolType", $Env:ANDROID_SYMBOL_TYPE,
"-logfile", "-", "./build.log",
"-silent-crashes"
) + $customParametersArray `
-NoNewWindow `
-PassThru
# This ensures that the Unity Editor properly exits as it can hang on Windows
while (!$process.StandardOutput.EndOfStream) {
if ($process.HasExited) {
Write-Host "`nExecute Method Ended`n"
exit 0;
}
Start-Sleep -Seconds 1
}
# Catch exit code
$Env:BUILD_EXIT_CODE=$LastExitCode
$Env:BUILD_EXIT_CODE=$process.ExitCode
# Display results
if ($Env:BUILD_EXIT_CODE -eq 0)

View File

@ -1,37 +1,21 @@
Get-Process
# Import any necessary registry keys, ie: location of windows 10 sdk
# No guarantee that there will be any necessary registry keys, ie: tvOS
Get-ChildItem -Path c:\regkeys -File | Foreach {reg import $_.fullname}
Start-Sleep 3
Get-Process
Get-ChildItem -Path c:\regkeys -File | ForEach-Object {reg import $_.fullname}
# Register the Visual Studio installation so Unity can find it
regsvr32 C:\ProgramData\Microsoft\VisualStudio\Setup\x64\Microsoft.VisualStudio.Setup.Configuration.Native.dll
Start-Sleep 3
Get-Process
# Setup Git Credentials
& "c:\steps\set_gitcredential.ps1"
Start-Sleep 3
Get-Process
# Activate Unity
& "c:\steps\activate.ps1"
Start-Sleep 3
Get-Process
# Build the project
& "c:\steps\build.ps1"
Start-Sleep 3
Get-Process
# Free the seat for the activated license
& "c:\steps\return_license.ps1"
Start-Sleep 3
Get-Process
# Kill the regsvr process
Get-Process -Name regsvr32 | ForEach-Object { Stop-Process -Id $_.Id -Force }
Start-Sleep 3
Get-Process