From 53f697829526f575e1f46b2bdb9d877a198af500 Mon Sep 17 00:00:00 2001 From: Andrew Kahr <22359829+AndrewKahr@users.noreply.github.com> Date: Thu, 26 Oct 2023 20:26:21 -0700 Subject: [PATCH] Attempt to fix windows exit hang --- dist/platforms/windows/build.ps1 | 91 ++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/dist/platforms/windows/build.ps1 b/dist/platforms/windows/build.ps1 index ba674445..4568b8af 100644 --- a/dist/platforms/windows/build.ps1 +++ b/dist/platforms/windows/build.ps1 @@ -132,47 +132,58 @@ 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) +$unityArgs = @( + "-quit", + "-batchmode", + "-nographics", + "-silent-crashes", + "-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", "-" +) + $customParametersArray -& "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 +# Remove null items as that will fail the Start-Process call +$unityArgs = $unityArgs | Where-Object { $_ -ne $null } -# Catch exit code -$Env:BUILD_EXIT_CODE=$LastExitCode +$process = Start-Process -FilePath "C:\Program Files\Unity\Hub\Editor\$Env:UNITY_VERSION\Editor\Unity.exe" ` + -ArgumentList $unityArgs ` + -NoNewWindow ` + -PassThru -# Display results -if ($Env:BUILD_EXIT_CODE -eq 0) -{ - Write-Output "Build Succeeded!" -} else -{ - Write-Output "$('Build failed, with exit code ')$($Env:BUILD_EXIT_CODE)$('"')" +while (!$process.HasExited) { + if ($process.HasExited) { + + # Display results + if ($process.ExitCode -eq 0) + { + Write-Output "Build Succeeded!" + } else + { + Write-Output "$('Build failed, with exit code ')$($process.ExitCode)$('"')" + } + + Write-Output "" + Write-Output "###########################" + Write-Output "# Build output #" + Write-Output "###########################" + Write-Output "" + + Get-ChildItem $Env:BUILD_PATH_FULL + Write-Output "" + + exit $process.ExitCode + } + + Start-Sleep -Seconds 1 } - -# TODO: Determine if we need to set permissions on any files - -# -# Results -# - -Write-Output "" -Write-Output "###########################" -Write-Output "# Build output #" -Write-Output "###########################" -Write-Output "" - -Get-ChildItem $Env:BUILD_PATH_FULL -Write-Output ""