Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions scripts/device-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ param(

Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
. $PSScriptRoot/ios-simulator-utils.ps1

if (!$Build -and !$Run)
{
Expand Down Expand Up @@ -57,8 +58,15 @@ try
'--app', "$buildDir/Sentry.Maui.Device.TestApp.app",
'--target', 'ios-simulator-64',
'--launch-timeout', '00:10:00',
'--set-env', 'CI=$envValue'
'--set-env', "CI=$envValue"
)

$udid = Get-IosSimulatorUdid -IosVersion '18.5' -Verbose
if ($udid) {
$arguments += @('--device', $udid)
} else {
Write-Host "No suitable simulator found; proceeding without a specific --device"
}
}

if ($Build)
Expand All @@ -76,7 +84,7 @@ try
if (!(Get-Command xharness -ErrorAction SilentlyContinue))
{
Push-Location ($CI ? $env:RUNNER_TEMP : $IsWindows ? $env:TMP : $IsMacos ? $env:TMPDIR : '/temp')
dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version '10.0.0-prerelease.25330.2' `
dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version '10.0.0-prerelease.25412.1' `
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json
Pop-Location
}
Expand Down
95 changes: 95 additions & 0 deletions scripts/ios-simulator-utils.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
function Get-IosSimulatorUdid {
[CmdletBinding()]
param(
[string]$IosVersion = '18.5',
[string[]]$PreferredDeviceTypes = @(
'com.apple.CoreSimulator.SimDeviceType.iPhone-XS',
'com.apple.CoreSimulator.SimDeviceType.iPhone-16',
'com.apple.CoreSimulator.SimDeviceType.iPhone-15'
)
)

try {
$simDevices = & xcrun simctl list devices --json | ConvertFrom-Json
} catch {
Write-Verbose "Failed to query simctl: $($_.Exception.Message)"
return $null
}
if (-not $simDevices -or -not $simDevices.devices) {
Write-Verbose "No devices structure returned."
return $null
}

$devicesByRuntime = $simDevices.devices
$preferredIndex = @{}
for ($i = 0; $i -lt $PreferredDeviceTypes.Count; $i++) {
$preferredIndex[$PreferredDeviceTypes[$i]] = $i
}

$dashVer = $IosVersion -replace '\.','-'
$exactKey = "com.apple.CoreSimulator.SimRuntime.iOS-$dashVer"
$runtimeKey = $null

$allRuntimeNames = $devicesByRuntime.PSObject.Properties.Name
if ($allRuntimeNames -contains $exactKey) {
$runtimeKey = $exactKey
Write-Verbose "Found exact runtime: $runtimeKey"
} else {
$major = ($IosVersion.Split('.')[0])
$candidates = $allRuntimeNames | Where-Object { $_ -match "com\.apple\.CoreSimulator\.SimRuntime\.iOS-$major-" }
if ($candidates) {
$runtimeKey = $candidates |
Sort-Object {
$v = ($_ -replace '.*iOS-','') -replace '-','.'
try { [Version]$v } catch { [Version]'0.0' }
} -Descending |
Select-Object -First 1
Write-Verbose "Exact runtime $exactKey not found. Using fallback runtime $runtimeKey"
} else {
Write-Verbose "No simulator runtime found for iOS major $major"
return $null
}
}

$runtimeDevices = $devicesByRuntime.PSObject.Properties |
Where-Object { $_.Name -eq $runtimeKey } |
Select-Object -ExpandProperty Value

if (-not $runtimeDevices) {
Write-Verbose "Runtime key $runtimeKey present but no devices listed."
return $null
}

$usable = $runtimeDevices | Where-Object { $_.isAvailable -and $_.state -in @('Shutdown','Booted') }
if (-not $usable) {
Write-Verbose "No available devices in runtime $runtimeKey"
return $null
}

$ranked = $usable | ForEach-Object {
$dt = $_.deviceTypeIdentifier
$weightPref = if ($preferredIndex.ContainsKey($dt)) { $preferredIndex[$dt] } else { 9999 }
$weightFamily = if ($dt -match 'iPhone') { 0 } else { 1 } # prefer iPhone if not explicitly listed
[PSCustomObject]@{
Device = $_
WeightPref = $weightPref
WeightFamily = $weightFamily
WeightBoot = if ($_.state -eq 'Booted') { 0 } else { 1 }
SortName = $_.name
}
}

$sorted = $ranked | Sort-Object WeightPref, WeightFamily, WeightBoot, SortName
$sorted | Select-Object -First 5 | ForEach-Object {
Write-Verbose ("Candidate: {0} | {1} | pref={2} fam={3} bootW={4}" -f $_.Device.name, $_.Device.deviceTypeIdentifier, $_.WeightPref, $_.WeightFamily, $_.WeightBoot)
}

$selected = $sorted | Select-Object -First 1
if (-not $selected) {
Write-Verbose "Failed to select a simulator."
return $null
}

Write-Verbose ("Selected simulator: {0} ({1}) [{2}]" -f $selected.Device.name, $selected.Device.deviceTypeIdentifier, $selected.Device.udid)
return $selected.Device.udid
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<!-- Pin target iOS version so that our tests don't break when new versions of Xcode are released.
'net8.0-ios' resolves the latest version of the iOS SDK otherwise. -->
<TargetPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">18</TargetPlatformVersion>
<TargetPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">18.0</TargetPlatformVersion>

<EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>

Expand Down
Loading