plu / simctl

Ruby interface to xcrun simctl
http://www.rubydoc.info/gems/simctl
MIT License
104 stars 19 forks source link

dyld: app was built for iOS 10.0 which is newer than this simulator 9.2 #14

Closed danielribeiro closed 7 years ago

danielribeiro commented 7 years ago

Hi,

I've been experimenting with

device = SimCtl.device(udid: device_id)
device.boot
device.wait(timeout) { |d| d.state == :booted && d.ready? }

... to get a device up and running. It works on 64bit devices, but fails on 32 bit devices.

The following ruby script on the cosole outputs the details

ENV['SIMCTL_DEBUG']="true"
device_id="C21A5716-6FDB-4DB9-90F1-975BDB66EC80"
timeout = 240
device = SimCtl.device(udid: device_id)
device.boot
device.wait(timeout) { |d| d.state == :booted && d.ready? }

output

2.1.3 :010 > device.wait(timeout) { |d| d.state == :booted && d.ready? }
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn C21A5716-6FDB-4DB9-90F1-975BDB66EC80 /Applications/Xcode/8.0.0/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/bin/launchctl list
RuntimeError: dyld: app was built for iOS 10.0 which is newer than this simulator 9.2
Child process terminated with signal 5: Trace/BPT trap

    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/executor.rb:14:in `block in execute'
    from /Users/build/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/open3.rb:199:in `popen_run'
    from /Users/build/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/open3.rb:93:in `popen3'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/executor.rb:10:in `execute'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/command/spawn.rb:13:in `spawn'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl.rb:39:in `method_missing'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/device.rb:183:in `spawn'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/device_launchctl.rb:12:in `list'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/device.rb:116:in `ready?'
    from (irb):10:in `block in irb_binding'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/device.rb:199:in `block (2 levels) in wait'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/device.rb:198:in `loop'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/device.rb:198:in `block in wait'
    from /Users/build/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
    from /Users/build/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/timeout.rb:35:in `block in catch'
    from /Users/build/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/timeout.rb:35:in `catch'
    from /Users/build/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/timeout.rb:35:in `catch'
    from /Users/build/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/timeout.rb:106:in `timeout'
    from /Users/build/.rvm/gems/ruby-2.1.3/gems/simctl-1.6.1/lib/simctl/device.rb:197:in `wait'
    from (irb):10

All using xcode 8.0.0, on ElCapitain

plu commented 7 years ago

It seems it failed to find the 9.2 runtime and falls back to using the default one from Xcode.

It attempts to find it here: /Library/Developer/CoreSimulator/Profiles/Runtimes/

$ ls -la /Library/Developer/CoreSimulator/Profiles/Runtimes/
total 0
drwxr-xr-x  16 root  wheel  544 Dec 18 08:11 .
drwxr-xr-x   3 root  wheel  102 Feb  4  2016 ..
drwxrwxr-t   3 root  admin  102 Dec 18 08:09 iOS 10.0.simruntime
drwxrwxr-t   3 root  admin  102 Dec 13 09:09 iOS 10.1.simruntime
drwxrwxr-t   3 root  admin  102 Feb  6  2016 iOS 8.1.simruntime
drwxrwxr-t   3 root  admin  102 Feb  6  2016 iOS 8.2.simruntime
drwxrwxr-t   3 root  admin  102 Feb  6  2016 iOS 8.3.simruntime
drwxrwxr-t   3 root  admin  102 Feb  5  2016 iOS 8.4.simruntime
drwxrwxr-t   3 root  admin  102 Feb  4  2016 iOS 9.0.simruntime
drwxrwxr-t   3 root  admin  102 Feb  5  2016 iOS 9.1.simruntime
drwxrwxr-t   3 root  admin  102 Mar 23  2016 iOS 9.2.simruntime
drwxrwxr-t   3 root  admin  102 Jun 15  2016 iOS 9.3.simruntime
drwxrwxr-t   3 root  admin  102 Feb  6  2016 tvOS 9.0.simruntime
drwxrwxr-t   3 root  admin  102 Mar 24  2016 tvOS 9.1.simruntime
drwxrwxr-t   3 root  admin  102 Feb  7  2016 watchOS 2.0.simruntime
drwxrwxr-t   3 root  admin  102 Mar 24  2016 watchOS 2.1.simruntime
plu commented 7 years ago

The code in question is here: https://github.com/plu/simctl/blob/master/lib/simctl/device_path.rb#L36-L41

    def locate_runtime_root
      "/Library/Developer/CoreSimulator/Profiles/Runtimes/#{device.runtime.name}.simruntime/Contents/Resources/RuntimeRoot".tap do |path|
        return path if File.exists?(path)
      end
      Xcode::Path.sdk_root
    end

I've tried the same setup, iOS 9.x device, Xcode 8.0, El Capitan, using the same script and it works...

~/Development/simctl[master*]$ ruby -Ilib test.rb
xcrun simctl list -j devices
xcrun simctl boot A179B896-6B35-489D-9A2B-E19334CF01D5
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
xcrun simctl list -j runtimes
xcrun simctl spawn A179B896-6B35-489D-9A2B-E19334CF01D5 /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 9.0.simruntime/Contents/Resources/RuntimeRoot/bin/launchctl list
xcrun simctl list -j devices
~/Development/simctl[master*]$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    test.rb

nothing added to commit but untracked files present (use "git add" to track)
#!/usr/bin/env ruby
require 'simctl'

ENV['SIMCTL_DEBUG']="true"
device_id="A179B896-6B35-489D-9A2B-E19334CF01D5"
timeout = 240
device = SimCtl.device(udid: device_id)
device.boot
device.wait(timeout) { |d| d.state == :booted && d.ready? }
~/Development/simctl[master*]$ xcodebuild -version
Xcode 8.0
Build version 8A218a
danielribeiro commented 7 years ago

Thanks @plu ! It seems my simulator runtimes are in a non standard location.

plu commented 7 years ago

We can make this customizable in device_path.rb, if you want?

danielribeiro commented 7 years ago

It sounds useful, but I'm just moving the simulators to a standard location.

I believe there was a bug on Xcode 6 where just seeing newer simulators on the coresimulator folder was enough to make it crash. Xcode 7 does not have this problem, so going back to standard locations should suffice.