Skip to content

Commit

Permalink
Gradle plugin delete unavailable simulator (#2413)
Browse files Browse the repository at this point in the history
* fix gradle plugin delete unavailable simulator
* apply suggestion to simpify usage of getSimctlListData()
  • Loading branch information
dima-avdeev-jb authored Oct 17, 2022
1 parent 919d774 commit 11fad5e
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,22 @@ fun Project.registerSimulatorTasks(
)

val taskSimulatorDeleteUnavailable = tasks.composeIosTask<AbstractComposeIosTask>("iosSimulatorDeleteUnavailable$id") {
val condition = { device: DeviceData -> device.name == deviceName && device.state.contains("unavailable") }
onlyIf {
getSimctlListData().devices.map { it.value }.flatten().any(condition)
}
doLast {
val device = getSimctlListData().devices.map { it.value }.flatten().first(condition)

runExternalTool(
MacUtils.xcrun,
listOf("simctl", "delete", device.udid)
)
val device = getSimctlListData().devices.map { it.value }.flatten()
.firstOrNull { device: DeviceData ->
val xcode13Condition = device.state.contains("unavailable")
val xcode14Condition = device.isAvailable == false
device.name == deviceName && (xcode13Condition || xcode14Condition)
}
if (device != null) {
runExternalTool(
MacUtils.xcrun,
listOf("simctl", "delete", device.udid)
)
}
}
}


val taskCreateSimulator = tasks.composeIosTask<AbstractComposeIosTask>("iosSimulatorCreate$id") {
dependsOn(taskSimulatorDeleteUnavailable)
onlyIf { getSimctlListData().devices.map { it.value }.flatten().none { it.name == deviceName } }
Expand Down

0 comments on commit 11fad5e

Please sign in to comment.