param( [Parameter(Mandatory = $true)][string]$UnityPath, [string]$WorkDirectory, [string]$SourceProject, [switch]$SettingsOnly ) $ErrorActionPreference = 'Stop' $taskPackage = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..')) if (-not $WorkDirectory) { $WorkDirectory = Join-Path ([IO.Path]::GetTempPath()) ('ARCheck-' + [Guid]::NewGuid().ToString('N').Substring(0, 8)) } $taskProject = [IO.Path]::GetFullPath($WorkDirectory) if (Test-Path -LiteralPath $taskProject) { throw "Use a new validation directory: $taskProject" } if (-not (Test-Path -LiteralPath $UnityPath -PathType Leaf)) { throw "Unity executable not found: $UnityPath" } New-Item -ItemType Directory -Path $taskProject -Force | Out-Null if ($SourceProject) { foreach ($taskFolder in @('Assets', 'Packages', 'ProjectSettings')) { Copy-Item -LiteralPath (Join-Path $SourceProject $taskFolder) -Destination (Join-Path $taskProject $taskFolder) -Recurse } } foreach ($taskFolder in @('Assets/Editor', 'Packages', 'ProjectSettings')) { New-Item -ItemType Directory -Path (Join-Path $taskProject $taskFolder) -Force | Out-Null } if (-not $SourceProject) { $taskVersion = (Get-Item -LiteralPath $UnityPath).VersionInfo.ProductVersion.Split('_')[0] if ($taskVersion -notmatch '^\d+\.\d+\.\d+[abfp]\d+$') { throw "Cannot determine Unity version from $UnityPath" } [IO.File]::WriteAllText((Join-Path $taskProject 'ProjectSettings/ProjectVersion.txt'), "m_EditorVersion: $taskVersion`n") } $taskManifestPath = Join-Path $taskProject 'Packages/manifest.json' if ($SourceProject) { $taskManifest = Get-Content -LiteralPath $taskManifestPath -Raw | ConvertFrom-Json $taskManifest.dependencies.'come.app.runtimes' = 'file:' + $taskPackage.Replace('\', '/') } else { $taskManifest = @{ dependencies = @{ 'come.app.runtimes' = 'file:' + $taskPackage.Replace('\', '/') } } } [IO.File]::WriteAllText($taskManifestPath, ($taskManifest | ConvertTo-Json -Depth 20)) Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Editor/AppRuntimesPackageValidation.cs') -Destination (Join-Path $taskProject 'Assets/Editor/AppRuntimesPackageValidation.cs') Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Editor/AppRuntimesSettingsValidation.cs') -Destination (Join-Path $taskProject 'Assets/Editor/AppRuntimesSettingsValidation.cs') Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Editor/AppRuntimesGupsValidation.cs') -Destination (Join-Path $taskProject 'Assets/Editor/AppRuntimesGupsValidation.cs') Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Editor/AppRuntimesXcodeLayoutValidation.cs') -Destination (Join-Path $taskProject 'Assets/Editor/AppRuntimesXcodeLayoutValidation.cs') Copy-Item -LiteralPath (Join-Path $taskPackage 'Tests~/Runtime/AppRuntimesValidationStartup.cs') -Destination (Join-Path $taskProject 'Assets/AppRuntimesValidationStartup.cs') $taskBaseline = @() foreach ($taskAsset in (Get-ChildItem -LiteralPath (Join-Path $taskProject 'Assets') -Recurse -File)) { if ($taskAsset.Name -notin @('AppSettings.asset', 'FacebookSettings.asset', 'settings.asset')) { continue } $taskBaseline += @{ path = $taskAsset.FullName.Substring($taskProject.Length + 1).Replace('\', '/') hash = (Get-FileHash -LiteralPath $taskAsset.FullName -Algorithm SHA256).Hash metaHash = (Get-FileHash -LiteralPath ($taskAsset.FullName + '.meta') -Algorithm SHA256).Hash } } New-Item -ItemType Directory -Path (Join-Path $taskProject 'Library') -Force | Out-Null [IO.File]::WriteAllText((Join-Path $taskProject 'Library/AppRuntimesSettingsBaseline.json'), (ConvertTo-Json -InputObject @($taskBaseline) -Depth 4)) $taskLog = Join-Path $taskProject 'validation.log' $taskMethod = if ($SettingsOnly) { 'AppRuntimesSettingsValidation.Run' } else { 'AppRuntimesPackageValidation.Run' } $taskMarker = if ($SettingsOnly) { 'APP_RUNTIMES_SETTINGS_VALIDATION_PASS' } else { 'APP_RUNTIMES_IOS_VALIDATION_PASS' } $taskArguments = @('-batchmode', '-nographics', '-projectPath', ('"' + $taskProject + '"'), '-buildTarget', 'iOS', '-executeMethod', $taskMethod, '-quit', '-logFile', ('"' + $taskLog + '"')) if (-not $SourceProject) { $taskArguments += '-appRuntimesPackageOnly' } Write-Output "Validating come.app.runtimes on iOS. Log: $taskLog" $taskProcess = Start-Process -FilePath $UnityPath -ArgumentList $taskArguments -WindowStyle Hidden -PassThru -Wait if ($taskProcess.ExitCode -ne 0 -or -not (Select-String -LiteralPath $taskLog -Pattern $taskMarker -Quiet)) { throw "Validation failed (exit $($taskProcess.ExitCode)). Inspect $taskLog" } if (Select-String -LiteralPath $taskLog -Pattern 'Failed to write meta file|Cannot open file.*Settings.meta|\[OPS\] Error:' -Quiet) { throw "Validation logged an asset-write or obfuscator error. Inspect $taskLog" } if ($SettingsOnly) { Write-Output "PASS: settings startup, defaults and preservation. Project: $taskProject" } else { Write-Output "PASS: iOS. Xcode project: $taskProject/Build/iOS" }