From b4434098c299114f94da64a9b35f32cac6f828a5 Mon Sep 17 00:00:00 2001 From: PrashantRaj18198 Date: Tue, 24 Mar 2026 13:47:33 +0800 Subject: [PATCH] fix: Configure-Xcode-Simulators duplicate removal logic There is a case where some duplicate xcode simulators are being missed. Case: Here A and B are simulators and the numeric values are time. [ A:0, A:1, A:2, B:0, B:1 ] Current, case i=0, compares A:0, A:1 and removes A:1, array now [ A:0, A:2, B:0, B:1 ]. But we also increment i at the end of the loop so i moves to 1. i=1, checks A:2 againsts B:0 which is ok. But multiple simulators for A are still present. The updated code basically updates i only if no simulator matches were found. --- .../build/Configure-Xcode-Simulators.ps1 | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/images/macos/scripts/build/Configure-Xcode-Simulators.ps1 b/images/macos/scripts/build/Configure-Xcode-Simulators.ps1 index 3e2791e927..5fc3279fa6 100644 --- a/images/macos/scripts/build/Configure-Xcode-Simulators.ps1 +++ b/images/macos/scripts/build/Configure-Xcode-Simulators.ps1 @@ -41,30 +41,38 @@ foreach ($xcodeVersion in $xcodeVersions.link) { } } Write-Host "///////////////////////////////////////////////////////////////////" - for ($i = 0; $i -lt $sameRuntimeDevices.Count; $i++) { - if ( [string]::IsNullOrEmpty($($sameRuntimeDevices[$i+1].DeviceName)) ){ - Write-Host "No more devices to compare in $simRuntume" - Write-Host "-------------------------------------------------------------------" - continue - } - Write-Host "$($sameRuntimeDevices[$i].DeviceName) - DeviceId $($sameRuntimeDevices[$i].DeviceId) comparing with" - Write-Host "$($sameRuntimeDevices[$i+1].DeviceName) - DeviceId $($sameRuntimeDevices[$i+1].DeviceId)" + + # Fixed iteration logic - don't increment when removing duplicates + $i = 0 + while ($i -lt ($sameRuntimeDevices.Count - 1)) { + $current = $sameRuntimeDevices[$i] + $next = $sameRuntimeDevices[$i + 1] + + Write-Host "$($current.DeviceName) - DeviceId $($current.DeviceId) comparing with" + Write-Host "$($next.DeviceName) - DeviceId $($next.DeviceId)" Write-Host "-------------------------------------------------------------------" - if ($sameRuntimeDevices[$i].DeviceName -eq $sameRuntimeDevices[$i+1].DeviceName) { + + if ($current.DeviceName -eq $next.DeviceName) { Write-Host "*******************************************************************" Write-Host "** Duplicate found" - if ($sameRuntimeDevices[$i].DeviceCreationTime -lt $sameRuntimeDevices[$i+1].DeviceCreationTime) { - Write-Host "** will be removed $($sameRuntimeDevices[$i+1].DeviceName) with id $($sameRuntimeDevices[$i+1].DeviceId)" - xcrun simctl delete $sameRuntimeDevices[$i+1].DeviceId - $sameRuntimeDevices.RemoveAt($i+1) + if ($current.DeviceCreationTime -lt $next.DeviceCreationTime) { + Write-Host "** will be removed $($next.DeviceName) with id $($next.DeviceId)" + xcrun simctl delete $next.DeviceId + $sameRuntimeDevices.RemoveAt($i + 1) } else { - Write-Host "** will be removed $($sameRuntimeDevices[$i].DeviceName) with id $($sameRuntimeDevices[$i].DeviceId)" - xcrun simctl delete $sameRuntimeDevices[$i].DeviceId + Write-Host "** will be removed $($current.DeviceName) with id $($current.DeviceId)" + xcrun simctl delete $current.DeviceId $sameRuntimeDevices.RemoveAt($i) } Write-Host "*******************************************************************" + # don't increment; compare again at same index + } else { + $i++ } } + + Write-Host "No more devices to compare in $simRuntume" + Write-Host "-------------------------------------------------------------------" } }