run_loop 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: add525f78c7ac99df59033028904b5c6cdfab2c2
4
- data.tar.gz: 92408bd01935a5444d9ef268d36843d273567381
3
+ metadata.gz: 2b7bf28b320d229c203aba840fd310fa5d218969
4
+ data.tar.gz: df2729c85b406bac18cf9dbf82e44cdfa3fdcd48
5
5
  SHA512:
6
- metadata.gz: c4ad4e7a0d55f171dfc3a6448d5401db1b8823a05bd9b83878b08b0eee79b2118c3775bd5319ee9bd3b2bfd6e3946b335de8d08496f9e10249840ed6bdf7efb4
7
- data.tar.gz: fdc0619781bce185692842c1aad8bcd1fb3a23224f6d916e7a84198224315e52bb2bfb6caba3c1c2632c9fc80d5dd203b43e12e38da9a15a54de5a6e75da30a3
6
+ metadata.gz: 4ca074c5fa9370f9085758386a987fbeef3a534820cae5c7d41b1b0ab9c7a49c16df455684ebcbb323819dc987a46e5c63b6ba2abfa776ef280a48a57a31f180
7
+ data.tar.gz: 9b2ac244bc05587ecc7393a80c9eeb3c016fc623cbdbb8deafe0d72d1a059217daecbf99c829bbbb5247a41284b20028b06b23edf118f5b43ff9bfb66ae3d7d4
data/lib/run_loop/app.rb CHANGED
@@ -16,6 +16,16 @@ module RunLoop
16
16
  @path = File.expand_path(app_bundle_path)
17
17
  end
18
18
 
19
+ # @!visibility private
20
+ def to_s
21
+ "#<APP: #{path}>"
22
+ end
23
+
24
+ # @!visibility private
25
+ def inspect
26
+ to_s
27
+ end
28
+
19
29
  # Is this a valid app?
20
30
  def valid?
21
31
  [File.exist?(path),
@@ -16,8 +16,13 @@ module RunLoop
16
16
  no_commands do
17
17
  def tail_booted
18
18
  device = booted_device
19
- log_file = device.simulator_log_file_path
20
- exec('tail', *['-F', log_file])
19
+ if device.nil?
20
+ version = Xcode.new.version
21
+ puts "No simulator for active Xcode (version #{version}) is booted."
22
+ else
23
+ log_file = device.simulator_log_file_path
24
+ exec('tail', *['-F', log_file])
25
+ end
21
26
  end
22
27
  end
23
28
 
@@ -25,7 +30,8 @@ module RunLoop
25
30
  def booted
26
31
  device = booted_device
27
32
  if device.nil?
28
- puts 'No simulator is booted.'
33
+ version = Xcode.new.version
34
+ puts "No simulator for active Xcode (version #{version}) is booted."
29
35
  else
30
36
  puts device
31
37
  end
data/lib/run_loop/core.rb CHANGED
@@ -29,7 +29,7 @@ module RunLoop
29
29
  SCRIPTS_PATH
30
30
  end
31
31
 
32
- def self.log_run_loop_options(options, xctools)
32
+ def self.log_run_loop_options(options, xcode)
33
33
  return unless RunLoop::Environment.debug?
34
34
  # Ignore :sim_control b/c it is a ruby object; printing is not useful.
35
35
  ignored_keys = [:sim_control]
@@ -41,8 +41,8 @@ module RunLoop
41
41
  # Objects that override '==' cannot be printed by awesome_print
42
42
  # https://github.com/michaeldv/awesome_print/issues/154
43
43
  # RunLoop::Version overrides '=='
44
- options_to_log[:xcode] = xctools.xcode_version.to_s
45
- options_to_log[:xcode_path] = xctools.xcode_developer_dir
44
+ options_to_log[:xcode] = xcode.version.to_s
45
+ options_to_log[:xcode_path] = xcode.developer_dir
46
46
  message = options_to_log.ai({:sort_keys => true})
47
47
  logger = options[:logger]
48
48
  RunLoop::Logging.log_debug(logger, "\n" + message)
@@ -87,7 +87,7 @@ module RunLoop
87
87
  if sim_control.xcode_version_gte_6?
88
88
  sim_identifier = launch_options[:udid]
89
89
  simulator = sim_control.simulators.find do |simulator|
90
- [simulator.instruments_identifier(sim_control.xctools),
90
+ [simulator.instruments_identifier(sim_control.xcode),
91
91
  simulator.udid].include?(sim_identifier)
92
92
  end
93
93
 
@@ -100,7 +100,7 @@ module RunLoop
100
100
  RunLoop::Logging.log_debug(logger, "Simulator instruction set '#{simulator.instruction_set}' is compatible with #{lipo.info}")
101
101
  true
102
102
  else
103
- RunLoop::Logging.log_debug(logger, "Xcode #{sim_control.xctools.xcode_version} detected; skipping simulator architecture check.")
103
+ RunLoop::Logging.log_debug(logger, "Xcode #{sim_control.xcode_version} detected; skipping simulator architecture check.")
104
104
  false
105
105
  end
106
106
  end
@@ -124,7 +124,7 @@ module RunLoop
124
124
  sim_control.quit_sim
125
125
  end
126
126
 
127
- if !sim_control.xctools.xcode_version_gte_6?
127
+ if !sim_control.xcode_version_gte_6?
128
128
  # Xcode 5.1.1
129
129
 
130
130
  # Will quit the simulator!
@@ -134,8 +134,10 @@ module RunLoop
134
134
  # CoreSimulator
135
135
 
136
136
  udid = launch_options[:udid]
137
+ xcode = sim_control.xcode
138
+
137
139
  device = sim_control.simulators.detect do |sim|
138
- sim.udid == udid || sim.instruments_identifier == udid
140
+ sim.udid == udid || sim.instruments_identifier(xcode) == udid
139
141
  end
140
142
 
141
143
  if device.nil?
@@ -156,7 +158,7 @@ module RunLoop
156
158
 
157
159
  # Xcode 6.3 instruments cannot launch an app that is already installed on
158
160
  # iOS 8.3 Simulators. See: https://github.com/calabash/calabash-ios/issues/744
159
- if sim_control.xctools.xcode_version_gte_63?
161
+ if sim_control.xcode.version_gte_63?
160
162
  app_bundle_path = launch_options[:bundle_dir_or_bundle_id]
161
163
  bridge = RunLoop::Simctl::Bridge.new(device, app_bundle_path)
162
164
 
@@ -172,10 +174,18 @@ module RunLoop
172
174
 
173
175
  logger = options[:logger]
174
176
  sim_control ||= options[:sim_control] || RunLoop::SimControl.new
175
- xctools ||= options[:xctools] || sim_control.xctools
177
+
178
+ if options[:xctools]
179
+ RunLoop.deprecated('1.5.0', %q(
180
+ RunLoop::XCTools has been replaced with RunLoop::Xcode.
181
+ The :xctools key will be ignored. It has been replaced by the :xcode key.
182
+ Please update your sources to pass an instance of RunLoop::Xcode))
183
+ end
184
+
185
+ xcode ||= options[:xcode] || sim_control.xcode
176
186
 
177
187
  instruments = RunLoop::Instruments.new
178
- instruments.kill_instruments
188
+ instruments.kill_instruments(xcode)
179
189
 
180
190
  device_target = options[:udid] || options[:device_target] || detect_connected_device || 'simulator'
181
191
  if device_target && device_target.to_s.downcase == 'device'
@@ -251,9 +261,9 @@ module RunLoop
251
261
  self.prepare_simulator(merged_options, sim_control)
252
262
  end
253
263
 
254
- self.log_run_loop_options(merged_options, xctools)
264
+ self.log_run_loop_options(merged_options, xcode)
255
265
 
256
- automation_template = automation_template(xctools)
266
+ automation_template = automation_template(instruments)
257
267
 
258
268
  RunLoop::Logging.log_header(logger, "Starting on #{device_target} App: #{bundle_dir_or_bundle_id}")
259
269
 
@@ -388,20 +398,27 @@ module RunLoop
388
398
  #
389
399
  # For historical reasons, the most recent non-64b SDK should be used.
390
400
  #
391
- # @param [RunLoop::XCTools] xcode_tools Used to detect the current xcode
401
+ # @param [RunLoop::XCTools, RunLoop::XCode] xcode Used to detect the current xcode
392
402
  # version.
393
- def self.default_simulator(xcode_tools=RunLoop::XCTools.new)
394
- if xcode_tools.xcode_version_gte_7?
395
- 'iPhone 5s (9.0 Simulator)'
396
- elsif xcode_tools.xcode_version_gte_64?
403
+ def self.default_simulator(xcode=RunLoop::Xcode.new)
404
+ if xcode.is_a?(RunLoop::XCTools)
405
+ RunLoop.deprecated('1.5.0',
406
+ %q(
407
+ RunLoop::XCTools has been replaced with RunLoop::Xcode.
408
+ Please update your sources to pass an instance of RunLoop::Xcode))
409
+ end
410
+
411
+ if xcode.version_gte_7?
412
+ 'iPhone 5s (9.0)'
413
+ elsif xcode.version_gte_64?
397
414
  'iPhone 5s (8.4 Simulator)'
398
- elsif xcode_tools.xcode_version_gte_63?
415
+ elsif xcode.version_gte_63?
399
416
  'iPhone 5s (8.3 Simulator)'
400
- elsif xcode_tools.xcode_version_gte_62?
417
+ elsif xcode.version_gte_62?
401
418
  'iPhone 5s (8.2 Simulator)'
402
- elsif xcode_tools.xcode_version_gte_61?
419
+ elsif xcode.version_gte_61?
403
420
  'iPhone 5s (8.1 Simulator)'
404
- elsif xcode_tools.xcode_version_gte_6?
421
+ elsif xcode.version_gte_6?
405
422
  'iPhone 5s (8.0 Simulator)'
406
423
  else
407
424
  'iPhone Retina (4-inch) - Simulator - iOS 7.1'
@@ -409,7 +426,7 @@ module RunLoop
409
426
  end
410
427
 
411
428
  def self.udid_and_bundle_for_launcher(device_target, options, sim_control=RunLoop::SimControl.new)
412
- xctools = sim_control.xctools
429
+ xcode = sim_control.xcode
413
430
 
414
431
  bundle_dir_or_bundle_id = options[:app] || RunLoop::Environment.bundle_id || RunLoop::Environment.path_to_app_bundle
415
432
 
@@ -419,9 +436,9 @@ module RunLoop
419
436
 
420
437
  udid = nil
421
438
 
422
- if xctools.xcode_version_gte_51?
439
+ if xcode.version_gte_51?
423
440
  if device_target.nil? || device_target.empty? || device_target == 'simulator'
424
- device_target = self.default_simulator(xctools)
441
+ device_target = self.default_simulator(xcode)
425
442
  end
426
443
  udid = device_target
427
444
 
@@ -429,6 +446,7 @@ module RunLoop
429
446
  bundle_dir_or_bundle_id = options[:bundle_id] if options[:bundle_id]
430
447
  end
431
448
  else
449
+ #TODO: this can be removed - Xcode < 5.1.1 not supported.
432
450
  if device_target == 'simulator'
433
451
 
434
452
  unless File.exist?(bundle_dir_or_bundle_id)
@@ -621,15 +639,25 @@ module RunLoop
621
639
  result
622
640
  end
623
641
 
624
- def self.automation_template(xctools, candidate = RunLoop::Environment.trace_template)
642
+ def self.automation_template(instruments, candidate=RunLoop::Environment.trace_template)
625
643
  unless candidate && File.exist?(candidate)
626
- candidate = default_tracetemplate xctools
644
+ candidate = default_tracetemplate(instruments)
627
645
  end
628
646
  candidate
629
647
  end
630
648
 
631
- def self.default_tracetemplate(xctools=RunLoop::XCTools.new)
632
- templates = xctools.instruments :templates
649
+ def self.default_tracetemplate(instruments_arg=RunLoop::Instruments.new)
650
+ if instruments_arg.is_a?(RunLoop::XCTools)
651
+ RunLoop.deprecated('1.5.0',
652
+ %q(
653
+ RunLoop::XCTools has been replaced with RunLoop::Xcode.
654
+ Please update your sources to pass an instance of RunLoop::Instruments))
655
+ instruments = RunLoop::Instruments.new
656
+ else
657
+ instruments = instruments_arg
658
+ end
659
+
660
+ templates = instruments.templates
633
661
 
634
662
  # xcrun instruments -s templates
635
663
  # Xcode >= 6 will return known, Apple defined tracetemplates as names
@@ -641,23 +669,23 @@ module RunLoop
641
669
  # behavior when GM is released.
642
670
  #
643
671
  # Xcode 7 Beta versions appear to behavior like Xcode 6 Beta versions.
644
- res = templates.select { |name| name == 'Automation' }.first
645
- return res if res
672
+ template = templates.find { |name| name == 'Automation' }
673
+ return template if template
646
674
 
647
- candidate = templates.select do |path|
675
+ candidate = templates.find do |path|
648
676
  path =~ /\/Automation.tracetemplate/ and path =~ /Xcode/
649
677
  end
650
678
 
651
- if !candidate.empty? && !candidate.first.nil?
652
- return candidate.first.tr("\"", '').strip
679
+ if !candidate.nil?
680
+ return candidate.tr("\"", '').strip
653
681
  end
654
682
 
655
- msgs = ['Expected instruments to report an Automation tracetemplate.',
683
+ message = ['Expected instruments to report an Automation tracetemplate.',
656
684
  'Please report this as bug: https://github.com/calabash/run_loop/issues',
657
685
  "In the bug report, include the output of:\n",
658
686
  '$ xcrun xcodebuild -version',
659
687
  "$ xcrun instruments -s templates\n"]
660
- raise msgs.join("\n")
688
+ raise message.join("\n")
661
689
  end
662
690
 
663
691
  # @deprecated 1.0.5
@@ -675,8 +703,8 @@ module RunLoop
675
703
  end
676
704
 
677
705
  # @deprecated 1.0.0 replaced with Xctools#version
678
- def self.xcode_version(xctools=RunLoop::XCTools.new)
679
- xctools.xcode_version.to_s
706
+ def self.xcode_version(xcode=RunLoop::Xcode.new)
707
+ xcode.version
680
708
  end
681
709
 
682
710
  # @deprecated since 1.0.0
@@ -1,6 +1,8 @@
1
1
  module RunLoop
2
2
  class Device
3
3
 
4
+ include RunLoop::Regex
5
+
4
6
  attr_reader :name
5
7
  attr_reader :version
6
8
  attr_reader :udid
@@ -40,7 +42,7 @@ module RunLoop
40
42
  # passed to instruments.
41
43
  #
42
44
  # @example
43
- # RunLoop::Device.device_with_identifier('iPhone 4s (8.3 Simulator')
45
+ # RunLoop::Device.device_with_identifier('iPhone 4s (8.3 Simulator'))
44
46
  # RunLoop::Device.device_with_identifier('6E43E3CF-25F5-41CC-A833-588F043AE749')
45
47
  # RunLoop::Device.device_with_identifier('denis') # Simulator or device named 'denis'
46
48
  # RunLoop::Device.device_with_identifier('893688959205dc7eb48d603c558ede919ad8dd0c')
@@ -50,20 +52,45 @@ module RunLoop
50
52
  #
51
53
  # @param [String] udid_or_name A name or udid that identifies the device you
52
54
  # are looking for.
53
- # @param [RunLoop::SimControl] sim_control An instance of SimControl that
54
- # can be used for looking of simulators and providing an XCTools instance.
55
- # Users should never need to provide this.
55
+ # @param [Hash] options Allows callers to pass runtime models that might
56
+ # optimize performance (via memoization).
57
+ # @option options [RunLoop::SimControl] :sim_control An instance of
58
+ # SimControl.
59
+ # @option options [RunLoop::Instruments] :instruments An instance of
60
+ # Instruments.
61
+ #
56
62
  # @return [RunLoop::Device] A device that matches `udid_or_name`.
57
63
  # @raise [ArgumentError] If no matching device can be found.
58
- def self.device_with_identifier(udid_or_name, sim_control=RunLoop::SimControl.new)
64
+ def self.device_with_identifier(udid_or_name, options={})
65
+ if options.is_a?(RunLoop::SimControl)
66
+ RunLoop.deprecated('1.5.0', %q(
67
+ The 'sim_control' argument has been deprecated. It has been replaced by an
68
+ options hash with two keys: :sim_control and :instruments.
69
+ Please update your sources.))
70
+ merged_options = {
71
+ :sim_control => options,
72
+ :instruments => RunLoop::Instruments.new
73
+ }
74
+ else
75
+ default_options = {
76
+ :sim_control => RunLoop::SimControl.new,
77
+ :instruments => RunLoop::Instruments.new
78
+ }
79
+ merged_options = default_options.merge(options)
80
+ end
81
+
82
+ instruments = merged_options[:instruments]
83
+ sim_control = merged_options[:sim_control]
84
+
85
+ xcode = sim_control.xcode
59
86
  simulator = sim_control.simulators.detect do |sim|
60
- sim.instruments_identifier == udid_or_name ||
87
+ sim.instruments_identifier(xcode) == udid_or_name ||
61
88
  sim.udid == udid_or_name
62
89
  end
63
90
 
64
91
  return simulator if !simulator.nil?
65
92
 
66
- physical_device = sim_control.xctools.instruments(:devices).detect do |device|
93
+ physical_device = instruments.physical_devices.detect do |device|
67
94
  device.name == udid_or_name ||
68
95
  device.udid == udid_or_name
69
96
  end
@@ -73,46 +100,68 @@ module RunLoop
73
100
  raise ArgumentError, "Could not find a device with a UDID or name matching '#{udid_or_name}'"
74
101
  end
75
102
 
103
+ # @!visibility private
76
104
  def to_s
77
105
  if simulator?
78
- "#<Simulator: #{instruments_identifier} #{udid} #{instruction_set}>"
106
+ "#<Simulator: #{name} #{udid} #{instruction_set}>"
79
107
  else
80
108
  "#<Device: #{name} #{udid}>"
81
109
  end
82
110
  end
83
111
 
112
+ # @!visibility private
113
+ def inspect
114
+ to_s
115
+ end
116
+
84
117
  # Returns and instruments-ready device identifier that is a suitable value
85
118
  # for DEVICE_TARGET environment variable.
86
119
  #
120
+ # @note As of 1.5.0, the XCTools optional argument has become a non-optional
121
+ # Xcode argument.
122
+ #
123
+ # @param [RunLoop::Xcode, RunLoop::XCTools] xcode The version of the active
124
+ # Xcode.
87
125
  # @return [String] An instruments-ready device identifier.
88
126
  # @raise [RuntimeError] If trying to obtain a instruments-ready identifier
89
127
  # for a simulator when Xcode < 6.
90
- def instruments_identifier(xcode_tools=RunLoop::XCTools.new)
128
+ def instruments_identifier(xcode=SIM_CONTROL.xcode)
129
+ if xcode.is_a?(RunLoop::XCTools)
130
+ RunLoop.deprecated('1.5.0',
131
+ %q(
132
+ RunLoop::XCTools has been replaced with a non-optional RunLoop::Xcode argument.
133
+ Please update your sources to pass an instance of RunLoop::Xcode))
134
+ end
135
+
91
136
  if physical_device?
92
- self.udid
137
+ udid
93
138
  else
94
- unless xcode_tools.xcode_version_gte_6?
95
- raise "Expected Xcode >= 6, but found version #{xcode_tools.xcode_version} - cannot create an identifier"
139
+ if version == RunLoop::Version.new('7.0.3')
140
+ version_part = version.to_s
141
+ else
142
+ version_part = "#{version.major}.#{version.minor}"
96
143
  end
97
- if self.version == RunLoop::Version.new('7.0.3')
98
- version_part = self.version.to_s
144
+
145
+ if xcode.version_gte_7?
146
+ "#{name} (#{version_part})"
147
+ elsif xcode.version_gte_6?
148
+ "#{name} (#{version_part} Simulator)"
99
149
  else
100
- version_part = "#{self.version.major}.#{self.version.minor}"
150
+ udid
101
151
  end
102
- "#{self.name} (#{version_part} Simulator)"
103
152
  end
104
153
  end
105
154
 
106
155
  # Is this a physical device?
107
156
  # @return [Boolean] Returns true if this is a device.
108
157
  def physical_device?
109
- not self.udid[/[a-f0-9]{40}/, 0].nil?
158
+ not udid[DEVICE_UDID_REGEX, 0].nil?
110
159
  end
111
160
 
112
161
  # Is this a simulator?
113
162
  # @return [Boolean] Returns true if this is a simulator.
114
163
  def simulator?
115
- not self.physical_device?
164
+ not physical_device?
116
165
  end
117
166
 
118
167
  # Return the instruction set for this device.
@@ -128,7 +177,7 @@ module RunLoop
128
177
  # @raise [RuntimeError] Raises an error if this device is a physical device.
129
178
  # @return [String] An instruction set.
130
179
  def instruction_set
131
- if self.simulator?
180
+ if simulator?
132
181
  if ['iPhone 4s', 'iPhone 5', 'iPad 2', 'iPad Retina'].include?(self.name)
133
182
  'i386'
134
183
  else
@@ -171,5 +220,8 @@ module RunLoop
171
220
 
172
221
  CORE_SIMULATOR_DEVICE_DIR = File.expand_path('~/Library/Developer/CoreSimulator/Devices')
173
222
  CORE_SIMULATOR_LOGS_DIR = File.expand_path('~/Library/Logs/CoreSimulator')
223
+
224
+ # TODO Is this a good idea? It speeds up rspec tests by a factor of ~2x...
225
+ SIM_CONTROL = RunLoop::SimControl.new
174
226
  end
175
227
  end
@@ -64,6 +64,16 @@ module RunLoop
64
64
  end
65
65
  end
66
66
 
67
+ # @!visibility private
68
+ def to_s
69
+ "#<HostCache #{path}>"
70
+ end
71
+
72
+ # @!visibility private
73
+ def inspect
74
+ to_s
75
+ end
76
+
67
77
  # Reads the current cache.
68
78
  # @return [Hash] A hash representation of the current state of the run-loop.
69
79
  def read