|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +<# |
| 5 | +.SYNOPSIS |
| 6 | + Builds the binaries needed to generate API reference docs for Mixed Reality Toolkit. |
| 7 | +.DESCRIPTION |
| 8 | + Builds the binaries needed to generate API reference docs for Mixed Reality Toolkit. |
| 9 | +.PARAMETER OutputDirectory |
| 10 | + Where should we place the output? |
| 11 | +.PARAMETER Version |
| 12 | + What version of the artifacts should we build? |
| 13 | +.PARAMETER UnityDirectory |
| 14 | + Where is the directory of the version of Unity we use to generate the binaries? |
| 15 | +#> |
| 16 | +param( |
| 17 | + [string]$OutputDirectory, |
| 18 | + [ValidatePattern("^\d+\.\d+\.\d+$")] |
| 19 | + [string]$Version, |
| 20 | + [string]$UnityDirectory |
| 21 | +) |
| 22 | + |
| 23 | +Write-Verbose "Checking parameters:" |
| 24 | +if (-not $OutputDirectory) { |
| 25 | + throw "-OutputDirectory is a required flag" |
| 26 | +} |
| 27 | +if (-not $Version) { |
| 28 | + throw "-Version is a required flag" |
| 29 | +} |
| 30 | +if (-not $UnityDirectory) { |
| 31 | + throw "-UnityDirectory is a required flag" |
| 32 | +} |
| 33 | + |
| 34 | +$unityEditor = Get-ChildItem $UnityDirectory -Filter 'Unity.exe' -Recurse | Select-Object -First 1 -ExpandProperty FullName |
| 35 | +if (-not $unityEditor) { |
| 36 | + throw "Unable to find the Unity editor executable in $UnityDirectory" |
| 37 | +} |
| 38 | +Write-Verbose $unityEditor; |
| 39 | + |
| 40 | +function RunUnityTask { |
| 41 | + param([string]$taskName, [string]$methodToExecute) |
| 42 | + Write-Output "Starting running Unity task: $($taskName)" |
| 43 | + $logFile = New-Item -Path "Logs\Unity.$($taskName).$($Version).log" -ItemType File -Force |
| 44 | + |
| 45 | + $ProjectLocation = Resolve-Path "$(Get-Location)\..\" |
| 46 | + Write-Output $ProjectLocation |
| 47 | + $proc = Start-Process -FilePath "$unityEditor" -ArgumentList "-projectPath $ProjectLocation -batchmode -executeMethod $($methodToExecute) -logFile $($logFile.FullName) -nographics -quit" -PassThru |
| 48 | + $ljob = Start-Job -ScriptBlock { param($log) Get-Content "$log" -Wait } -ArgumentList $logFile.FullName |
| 49 | + |
| 50 | + while (-not $proc.HasExited -and $ljob.HasMoreData) { |
| 51 | + Receive-Job $ljob |
| 52 | + Start-Sleep -Milliseconds 200 |
| 53 | + } |
| 54 | + Receive-Job $ljob |
| 55 | + |
| 56 | + Stop-Job $ljob |
| 57 | + |
| 58 | + Remove-Job $ljob |
| 59 | + Stop-Process $proc |
| 60 | + if ($proc.ExitCode -ge 1) { |
| 61 | + Write-Error "Failed to execute Unity Task '$($taskName)', see log '$($logFile)' for more information." |
| 62 | + exit($proc.ExitCode) |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +$OriginalPath = Get-Location |
| 67 | +try { |
| 68 | + Set-Location (Split-Path $MyInvocation.MyCommand.Path) |
| 69 | + Set-Location "..\\..\\" |
| 70 | + New-Item -ItemType Directory "BinariesForDocs" -ErrorAction SilentlyContinue |
| 71 | + Set-Location "BinariesForDocs" |
| 72 | + |
| 73 | + ### Run MSBuild Generation |
| 74 | + RunUnityTask -taskName "MSBuildGeneration" -methodToExecute "Microsoft.MixedReality.Toolkit.MSBuild.MSBuildTools.GenerateSDKProjects" |
| 75 | + |
| 76 | + ### Build the needed flavor for MRTK |
| 77 | + Write-Output "============ Building InEditor WSA ============ " |
| 78 | + dotnet msbuild ..\NuGet\BuildSource.proj -target:BuildWSAEditor > "Logs\Build.InEditor.WSA.$($Version).log" |
| 79 | + if ($lastexitcode -ge 1) { |
| 80 | + Write-Error "Building InEditor WSA Failed! See log file for more information $(Get-Location)\Logs\Build.InEditor.WSA.$($Version).log"; |
| 81 | + Copy-Item -Path "Logs\Unity.MSBuildGeneration.$($Version).log" -Destination "$OutputDirectory\" |
| 82 | + exit($lastexitcode) |
| 83 | + } |
| 84 | + |
| 85 | + Write-Output "============ Copying the binaries ============ " |
| 86 | + New-Item -ItemType Directory "MRTK_$($Version)" |
| 87 | + New-Item -ItemType Directory "MRTK_$($Version)\dependencies" |
| 88 | + Remove-Item "..\MSBuild\Publish\InEditor\WSA\*.pdb" |
| 89 | + Move-Item "..\MSBuild\Publish\InEditor\WSA\Microsoft.MixedReality.Toolkit*" "MRTK_$($Version)\" |
| 90 | + Move-Item "..\MSBuild\Publish\InEditor\WSA\*.dll" "MRTK_$($Version)\dependencies\" |
| 91 | + Copy-Item "$($UnityDirectory)\Data\Managed\UnityEditor.dll" "MRTK_$($Version)\dependencies\" |
| 92 | + Copy-Item "$($UnityDirectory)\Data\Managed\UnityEngine.dll" "MRTK_$($Version)\dependencies\" |
| 93 | + nuget install Microsoft.Windows.MixedReality.DotNetWinRT -OutputDirectory packages |
| 94 | + Copy-Item "packages\Microsoft.Windows.MixedReality.DotNetWinRT*\lib\unity\net46\Microsoft.Windows.MixedReality.DotNetWinRT.dll" "MRTK_$($Version)\dependencies\" |
| 95 | + Copy-Item -Path "MRTK_$($Version)" -Destination "$OutputDirectory" -Recurse |
| 96 | + |
| 97 | +} |
| 98 | +finally { |
| 99 | + Set-Location $OriginalPath |
| 100 | +} |
0 commit comments