Validate-iOS.ps1 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. param(
  2. [Parameter(Mandatory = $true)][string]$UnityPath,
  3. [string]$WorkDirectory,
  4. [string]$SourceProject,
  5. [switch]$SettingsOnly
  6. )
  7. $ErrorActionPreference = 'Stop'
  8. $taskPackage = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
  9. if (-not $WorkDirectory) {
  10. $WorkDirectory = Join-Path ([IO.Path]::GetTempPath()) ('ARCheck-' + [Guid]::NewGuid().ToString('N').Substring(0, 8))
  11. }
  12. $taskProject = [IO.Path]::GetFullPath($WorkDirectory)
  13. if (Test-Path -LiteralPath $taskProject) { throw "Use a new validation directory: $taskProject" }
  14. if (-not (Test-Path -LiteralPath $UnityPath -PathType Leaf)) { throw "Unity executable not found: $UnityPath" }
  15. New-Item -ItemType Directory -Path $taskProject -Force | Out-Null
  16. if ($SourceProject) {
  17. foreach ($taskFolder in @('Assets', 'Packages', 'ProjectSettings')) {
  18. Copy-Item -LiteralPath (Join-Path $SourceProject $taskFolder) -Destination (Join-Path $taskProject $taskFolder) -Recurse
  19. }
  20. }
  21. foreach ($taskFolder in @('Assets/Editor', 'Packages', 'ProjectSettings')) {
  22. New-Item -ItemType Directory -Path (Join-Path $taskProject $taskFolder) -Force | Out-Null
  23. }
  24. if (-not $SourceProject) {
  25. $taskVersion = (Get-Item -LiteralPath $UnityPath).VersionInfo.ProductVersion.Split('_')[0]
  26. if ($taskVersion -notmatch '^\d+\.\d+\.\d+[abfp]\d+$') { throw "Cannot determine Unity version from $UnityPath" }
  27. [IO.File]::WriteAllText((Join-Path $taskProject 'ProjectSettings/ProjectVersion.txt'), "m_EditorVersion: $taskVersion`n")
  28. }
  29. $taskManifestPath = Join-Path $taskProject 'Packages/manifest.json'
  30. if ($SourceProject) {
  31. $taskManifest = Get-Content -LiteralPath $taskManifestPath -Raw | ConvertFrom-Json
  32. $taskManifest.dependencies.'come.app.runtimes' = 'file:' + $taskPackage.Replace('\', '/')
  33. } else {
  34. $taskManifest = @{ dependencies = @{ 'come.app.runtimes' = 'file:' + $taskPackage.Replace('\', '/') } }
  35. }
  36. [IO.File]::WriteAllText($taskManifestPath, ($taskManifest | ConvertTo-Json -Depth 20))
  37. Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Editor/AppRuntimesPackageValidation.cs') -Destination (Join-Path $taskProject 'Assets/Editor/AppRuntimesPackageValidation.cs')
  38. Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Editor/AppRuntimesSettingsValidation.cs') -Destination (Join-Path $taskProject 'Assets/Editor/AppRuntimesSettingsValidation.cs')
  39. Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Editor/AppRuntimesGupsValidation.cs') -Destination (Join-Path $taskProject 'Assets/Editor/AppRuntimesGupsValidation.cs')
  40. Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Editor/AppRuntimesXcodeLayoutValidation.cs') -Destination (Join-Path $taskProject 'Assets/Editor/AppRuntimesXcodeLayoutValidation.cs')
  41. Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Runtime/AppRuntimesValidationStartup.cs') -Destination (Join-Path $taskProject 'Assets/AppRuntimesValidationStartup.cs')
  42. $taskBaseline = @()
  43. foreach ($taskAsset in (Get-ChildItem -LiteralPath (Join-Path $taskProject 'Assets') -Recurse -File)) {
  44. if ($taskAsset.Name -notin @('AppSettings.asset', 'FacebookSettings.asset', 'settings.asset')) { continue }
  45. $taskBaseline += @{
  46. path = $taskAsset.FullName.Substring($taskProject.Length + 1).Replace('\', '/')
  47. hash = (Get-FileHash -LiteralPath $taskAsset.FullName -Algorithm SHA256).Hash
  48. metaHash = (Get-FileHash -LiteralPath ($taskAsset.FullName + '.meta') -Algorithm SHA256).Hash
  49. }
  50. }
  51. New-Item -ItemType Directory -Path (Join-Path $taskProject 'Library') -Force | Out-Null
  52. [IO.File]::WriteAllText((Join-Path $taskProject 'Library/AppRuntimesSettingsBaseline.json'), (ConvertTo-Json -InputObject @($taskBaseline) -Depth 4))
  53. $taskLog = Join-Path $taskProject 'validation.log'
  54. $taskMethod = if ($SettingsOnly) { 'AppRuntimesSettingsValidation.Run' } else { 'AppRuntimesPackageValidation.Run' }
  55. $taskMarker = if ($SettingsOnly) { 'APP_RUNTIMES_SETTINGS_VALIDATION_PASS' } else { 'APP_RUNTIMES_IOS_VALIDATION_PASS' }
  56. $taskArguments = @('-batchmode', '-nographics', '-projectPath', ('"' + $taskProject + '"'),
  57. '-buildTarget', 'iOS', '-executeMethod', $taskMethod, '-quit', '-logFile', ('"' + $taskLog + '"'))
  58. if (-not $SourceProject) { $taskArguments += '-appRuntimesPackageOnly' }
  59. Write-Output "Validating come.app.runtimes on iOS. Log: $taskLog"
  60. $taskProcess = Start-Process -FilePath $UnityPath -ArgumentList $taskArguments -WindowStyle Hidden -PassThru -Wait
  61. if ($taskProcess.ExitCode -ne 0 -or -not (Select-String -LiteralPath $taskLog -Pattern $taskMarker -Quiet)) {
  62. throw "Validation failed (exit $($taskProcess.ExitCode)). Inspect $taskLog"
  63. }
  64. if (Select-String -LiteralPath $taskLog -Pattern 'Failed to write meta file|Cannot open file.*Settings.meta|\[OPS\] Error:' -Quiet) {
  65. throw "Validation logged an asset-write or obfuscator error. Inspect $taskLog"
  66. }
  67. if ($SettingsOnly) { Write-Output "PASS: settings startup, defaults and preservation. Project: $taskProject" }
  68. else { Write-Output "PASS: iOS. Xcode project: $taskProject/Build/iOS" }