From 240667ae355a0fa0d74386294cc8c2e3f4d97344 Mon Sep 17 00:00:00 2001 From: Max Odnoletkov <1752162+odnoletkov@users.noreply.github.com> Date: Wed, 11 Jan 2023 20:19:38 +0000 Subject: [PATCH] Update simctl to Xcode 14 (#14) --- specs/simctl.txt | 105 +++++++++++++++++++++++++- src/_simctl | 188 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 269 insertions(+), 24 deletions(-) diff --git a/specs/simctl.txt b/specs/simctl.txt index 23ece40..f35a006 100644 --- a/specs/simctl.txt +++ b/specs/simctl.txt @@ -26,6 +26,7 @@ Subcommands: keychain Manipulate a device's keychain launch Launch an application by identifier on a device. list List available devices, device types, runtimes, or device pairs. + location Control a device's simulated location logverbose enable or disable verbose logging for a device openurl Open a URL in a device. pair Create a new watch and phone pair. @@ -36,6 +37,7 @@ Subcommands: privacy Grant, revoke, or reset privacy and permissions push Send a simulated push notification rename Rename a device. + runtime Perform operations on runtimes shutdown Shutdown a device. spawn Spawn a process by executing a given executable on a device. status_bar Set or clear status bar overrides @@ -249,6 +251,41 @@ Usage: simctl list [-j | --json] [-e | --no-escape-slashes] [-v] [devices|device Specify one of 'devices', 'devicetypes', 'runtimes', or 'pairs' to list only items of that type. If a type filter is specified you may also specify a search term. Search terms use a simple case-insensitive contains check against the item's description. You may use the search term 'available' to only list available items. +xcrun simctl help location +Control a device's simulated location +Usage: simctl location [arguments] + + list + List available simulation scenarios. + + clear + Stop any running scenario and clear any simulated location. + + set , + Set the location to a specific latitude and longitude. + + run + Run a simulated location scenario (use the list action to get a list of scenarios). + + start [--speed=] [--distance=|--interval=] , ,... + Set the location to a series of waypoints specified as 'lat,lon' pairs, interpolating between them over time. + At least two waypoints are required. Use '-' to read waypoints from stdin, one waypoint per line. + + Speed specifies how quickly to move between waypoints in meters per second. If not specified 20m/s is used. + + The system will issue location updates along the path between each pair of waypoints. Use distance or interval to + control how often those updates are issued. Distance will issue an update every travelled without regard + for the time between updates. Interval will issue updates at fixed times without regard for how much + the location moves between updates. + If neither are specified an interval of 1.0 seconds is used. If both are specified the system picks ones. + + Example simulating a direct line between San Francisco and New York City, with updates every km: + set --distance=1000 --speed=260 37.629538,-122.395733 40.628083,-73.768254 + +Latitude and longitude pairs must be specified using '.' as the decimal separator and ',' as the field separator. + + + xcrun simctl help logverbose enable or disable verbose logging for a device Usage: simctl logverbose [] (enable | disable) @@ -344,6 +381,73 @@ xcrun simctl help rename Rename a device. Usage: simctl rename +xcrun simctl help runtime +Perform operations on runtimes +Usage: simctl runtime + +Supported Operations: + add [-ma] + Add a runtime disk image to the secure storage area. The image will be staged, verified, and mounted. + When possible the image file will be cloned so no additional disk space will be used. + If stdout is a terminal and a copy is required then progress will be reported. + + --move | -m + Remove the original file if the image is added successfully. If the image cannot be staged + or the add fails the original is not removed. + --async | -a + Print the UUID of the new image then exit, do not wait on the results of the add operation. + + delete (|--notUsedSinceDays ) [--dry-run] + Delete a simulator runtime from the secure storage area. If runtime is a disk image + any booted simulators are shutdown and the disk is unmounted first. + Use the alias 'all' to delete all images. + + --notUsedSinceDays | -d + Delete images not used within the past days. + --dry-run | -n + Print what images would be deleted without actually deleting anything. + + verify + Re-verify the signature of a given runtime. + + list [-v] [-j | --json] + List runtime disk images, optionally outputting JSON to stdout. + -v + Print more verbose output + -j + Print as JSON + + match list [-v] [-j | --json] + List the SDK build to runtime build mapping rules for the selected Xcode. + Preferred means the runtime was either bundled with Xcode, exactly matched your SDK version, + or the downloadable index indicated a better match for your SDK +. Manual overrides using 'match set' have the highest priority. + + -v + Verbose mode. Includes the full preferred build map, user override map, and known SDK names. + -j + Print as JSON + + match set ( || --default) [--sdkBuild ] + Override the SDK to runtime build mapping. This controls which build of a given runtime + Xcode will prefer for building and running when using that SDK. This matters most + often during Beta releases when there are multiple builds for a given OS version. + If --sdkBuild is not specified it is assumed you mean the SDK build for the currently selected Xcode. + + Note: Remember this is about build numbers, not semantic versions. When using the iOS 16.0 SDK Xcode + will always prefer an iOS 16.0 runtime. Matching policy controls what to do when there are multiple + iOS 16.0 runtimes available, + eg if the iOS 16.0 SDK is 20A245 and the available runtimes are (20A248, 20A252, 20A254) which one + should Xcode use for building, SwiftUI Previews, and when launching iOS 16.0 Simulators? + They are all iOS 16.0 runtimes so a policy must decide which one is selected. + + --default + Clear the override for the given SDK and revert to default behavior. + --sdkBuild + Explicitly specify the SDK build, eg for an Xcode other than the selected Xcode. + + + xcrun simctl help shutdown Shutdown a device. Usage: simctl shutdown | all @@ -540,7 +644,6 @@ NOTE: If you install or uninstall roots, you must manually update the dyld_sim s See simctl help legacyruntime for information about triggering a dyld_sim shared cache rebuild. - xcrun simctl help legacyruntime Locate, copy, mount, and unmount simulator runtime disk images. Usage: simctl legacyruntime diff --git a/src/_simctl b/src/_simctl index 4581d15..6e2051e 100644 --- a/src/_simctl +++ b/src/_simctl @@ -22,6 +22,7 @@ _commands() { 'boot:boot a device or device pair' 'shutdown:shutdown a device' 'rename:rename a device' + 'runtime:perform operations on runtimes' 'getenv:print an environment variable from a running device' 'openurl:open a URL in a device' 'addmedia:add photos, live photos, videos, or contacts to the library of a device' @@ -33,6 +34,7 @@ _commands() { 'terminate:terminate an application by identifier on a device' 'spawn:spawn a process by executing a given executable on a device' 'list:list available devices, device types, runtimes, or device pairs' + 'location:control a device'"'"'s simulated location' 'icloud_sync:trigger iCloud sync on a device' 'pbsync:sync the pasteboard content from one pasteboard to another' 'pbcopy:copy standard input onto the device pasteboard' @@ -46,21 +48,21 @@ _commands() { 'push:send a simulated push notification' 'privacy:grant, revoke, or reset privacy and permissions' 'keychain:manipulate a device'"'"'s keychain' - 'addphoto:Add photos to the photo library of a device.' - 'addvideo:Add videos to the photo library of a device.' - 'pbinfo:Print information about the device'"'"'s pasteboard' - 'notify_post:Post a darwin notification on a device.' - 'notify_get_state:Get the state value of a darwin notification on a device.' - 'notify_set_state:Set the state value of a darwin notification on a device.' - 'register:Register a service from one bootstrap into another.' - 'unregister:Unregister a service from a device'"'"'s bootstrap.' - 'keyboard:Set the device'"'"'s keyboard language.' - 'monitor:List notifications as they arrive.' - 'appinfo:Show information about an installed application.' + 'addphoto:add photos to the photo library of a device' + 'addvideo:add videos to the photo library of a device' + 'pbinfo:print information about the device'"'"'s pasteboard' + 'notify_post:post a darwin notification on a device' + 'notify_get_state:get the state value of a darwin notification on a device' + 'notify_set_state:set the state value of a darwin notification on a device' + 'register:register a service from one bootstrap into another' + 'unregister:unregister a service from a device'"'"'s bootstrap' + 'keyboard:set the device'"'"'s keyboard language' + 'monitor:list notifications as they arrive' + 'appinfo:show information about an installed application' 'listapps:show the installed applications' - 'bootstatus:Checks device boot status.' - 'darwinup:Invoke darwinup to install a root for the specified simulator runtime.' - 'legacyruntime:Locate, copy, mount, and unmount simulator runtime disk images.' + 'bootstatus:checks device boot status' + 'darwinup:invoke darwinup to install a root for the specified simulator runtime' + 'legacyruntime:locate, copy, mount, and unmount simulator runtime disk images' 'reset:reset a given archive or database' ) _describe subcommand commands @@ -129,6 +131,12 @@ _options() { ':name:' ;; + (runtime) + _arguments \ + ': :_runtime_operations' \ + '*:: :_runtime_arguments' + ;; + (getenv) _arguments \ ': :{FILTER=booted _devices}' \ @@ -211,6 +219,12 @@ _options() { '::search term:(available)' ;; + (location) + _arguments \ + ': :{FILTER=booted _devices}' \ + '*:: :_location' + ;; + (icloud_sync|listapps) _arguments \ ': :{FILTER=booted _devices}' @@ -370,6 +384,134 @@ _options() { esac } +_runtime_operations() { + local -a operations + operations=( + 'add:add a runtime disk image to the secure storage area' + 'delete:delete a simulator runtime from the secure storage area' + 'verify:re-verify the signature of a given runtime' + 'list:list runtime disk images' + 'match' + ) + _describe operation operations +} + +_runtime_arguments() { + case $line[1] in + + (add) + _arguments \ + ':path:_files' \ + '(-m --move)'{-m,--move}'[remove the original file if the image is added successfully]' \ + '(-a --async)'{-a,--async}'[print the UUID of the new image then exit, do not wait on the results of the add operation]' + ;; + + (delete) + _arguments \ + '::identifier:_runtime_identifiers' \ + '(-d --notUsedSinceDays)'{-d,--notUsedSinceDays}'[delete images not used within the past days]:days:' \ + '(-n --dry-run)'{-n,--dry-run}'[print what images would be deleted without actually deleting anything]' + ;; + + (verify) + _arguments \ + '::identifier:_runtime_identifiers' + ;; + + (list) + _arguments \ + '-v[print more verbose output]' \ + '(-j --json)'{-j,--json}'[print as JSON]' + ;; + + (match) + _arguments \ + ': :_runtime_match_operations' \ + '*:: :_runtime_match_arguments' + ;; + + esac +} + +_runtime_match_operations() { + local -a operations + operations=( + 'list:list the SDK build to runtime build mapping rules for the selected Xcode' + 'set:override the SDK to runtime build mapping' + ) + _describe operation operations +} + +_runtime_match_arguments() { + case $line[1] in + + (list) + _arguments \ + '-v[verbose mode]' \ + '(-j --json)'{-j,--json}'[print as JSON]' + ;; + + (set) + _arguments \ + ':sdk canonical name:' \ + '::runtime build:' \ + '--default[clear the override for the given SDK and revert to default behavior]' \ + '--sdkBuild[explicitly specify the SDK build]:sdk build:' + ;; + + esac +} + +_runtime_identifiers() { + local -a identifiers + identifiers=(${(f)"$(xcrun simctl runtime list -j | jq -r ' + .[] | "\(.identifier):\(.runtimeIdentifier // "(\(.state) - \(.unusableSubstate): \(.unusableErrorMessage))")" + ')"}) + _describe -V identifier identifiers +} + +_location() { + _arguments \ + ': :_location_actions' \ + '*:: :_location_arguments' +} + +_location_actions() { + local -a actions + actions=( + 'list:list available simulation scenarios' + 'clear:stop any running scenario and clear any simulated location' + 'set:set the location to a specific latitude and longitude' + 'run:run a simulated location scenario (use the list action to get a list of scenarios)' + 'start:set the location to a series of waypoints' + ) + _describe action actions +} + +_location_arguments() { + case $line[1] in + + (set) + _arguments \ + ':lat1,lon1:' + ;; + + (run) + _arguments \ + ':scenario:' + ;; + + (start) + _arguments \ + '--speed=-:meters/sec:' \ + '(--interval)--distance=-:meters per second:' \ + '(--distance)--interval=-:seconds:' \ + '*::latN,lonN:' + ;; + + esac +} + _io() { _arguments \ ': :_io_operations' \ @@ -557,7 +699,7 @@ _legacyruntime_operations() { local -a operations operations=( 'mount:locate a Simulator Runtime for the given train and build, copy the disk image locally, then mount it to make the runtime available to CoreSimulator' - 'unmount:Unmount the Simulator Runtime if it is mounted' + 'unmount:unmount the Simulator Runtime if it is mounted' 'cache' 'pin:pin a device to use a specific runtime' 'info' @@ -594,8 +736,8 @@ _legacyruntime_arguments() { (cache) _arguments \ - ': :_runtime_cache_commands' \ - '*:: :_runtime_cache_arguments' \ + ': :_legacyruntime_cache_commands' \ + '*:: :_legacyruntime_cache_arguments' \ '--cache_path:path:_files' ;; @@ -610,8 +752,8 @@ _legacyruntime_arguments() { (info) _arguments \ - ': :_runtime_info_commands' \ - '*:: :_runtime_info_arguments' + ': :_legacyruntime_info_commands' \ + '*:: :_legacyruntime_info_arguments' ;; (update_dyld_shared_cache|remove_dyld_shared_cache) @@ -622,7 +764,7 @@ _legacyruntime_arguments() { esac } -_runtime_cache_commands() { +_legacyruntime_cache_commands() { local -a commands commands=( 'list:lists cached runtime disk images' @@ -631,7 +773,7 @@ _runtime_cache_commands() { _describe command commands } -_runtime_cache_arguments() { +_legacyruntime_cache_arguments() { case $line[1] in (clear) @@ -645,7 +787,7 @@ _runtime_cache_arguments() { '--cache-path:path:_files' } -_runtime_info_commands() { +_legacyruntime_info_commands() { local -a commands commands=( 'path:lists the path to the runtime' @@ -653,7 +795,7 @@ _runtime_info_commands() { _describe command commands } -_runtime_info_arguments() { +_legacyruntime_info_arguments() { case $line[1] in (path)