run_loop_tcc 2.1.3

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.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/bin/run-loop +19 -0
  4. data/lib/run_loop/abstract.rb +18 -0
  5. data/lib/run_loop/app.rb +372 -0
  6. data/lib/run_loop/cache/cache.rb +68 -0
  7. data/lib/run_loop/cli/cli.rb +48 -0
  8. data/lib/run_loop/cli/codesign.rb +24 -0
  9. data/lib/run_loop/cli/errors.rb +11 -0
  10. data/lib/run_loop/cli/instruments.rb +160 -0
  11. data/lib/run_loop/cli/locale.rb +31 -0
  12. data/lib/run_loop/cli/simctl.rb +257 -0
  13. data/lib/run_loop/cli/tcc.rb +139 -0
  14. data/lib/run_loop/codesign.rb +76 -0
  15. data/lib/run_loop/core.rb +902 -0
  16. data/lib/run_loop/core_simulator.rb +960 -0
  17. data/lib/run_loop/detect_aut/detect.rb +185 -0
  18. data/lib/run_loop/detect_aut/errors.rb +126 -0
  19. data/lib/run_loop/detect_aut/xamarin_studio.rb +46 -0
  20. data/lib/run_loop/detect_aut/xcode.rb +157 -0
  21. data/lib/run_loop/device.rb +722 -0
  22. data/lib/run_loop/device_agent/app/CBX-Runner.app.zip +0 -0
  23. data/lib/run_loop/device_agent/bin/xctestctl +0 -0
  24. data/lib/run_loop/device_agent/cbxrunner.rb +156 -0
  25. data/lib/run_loop/device_agent/frameworks/Frameworks.zip +0 -0
  26. data/lib/run_loop/device_agent/frameworks.rb +65 -0
  27. data/lib/run_loop/device_agent/ipa/CBX-Runner.app.zip +0 -0
  28. data/lib/run_loop/device_agent/launcher.rb +51 -0
  29. data/lib/run_loop/device_agent/xcodebuild.rb +91 -0
  30. data/lib/run_loop/device_agent/xctestctl.rb +109 -0
  31. data/lib/run_loop/directory.rb +179 -0
  32. data/lib/run_loop/dnssd.rb +148 -0
  33. data/lib/run_loop/dot_dir.rb +87 -0
  34. data/lib/run_loop/dylib_injector.rb +145 -0
  35. data/lib/run_loop/encoding.rb +56 -0
  36. data/lib/run_loop/environment.rb +361 -0
  37. data/lib/run_loop/fifo.rb +40 -0
  38. data/lib/run_loop/host_cache.rb +128 -0
  39. data/lib/run_loop/http/error.rb +15 -0
  40. data/lib/run_loop/http/request.rb +44 -0
  41. data/lib/run_loop/http/retriable_client.rb +166 -0
  42. data/lib/run_loop/http/server.rb +17 -0
  43. data/lib/run_loop/instruments.rb +436 -0
  44. data/lib/run_loop/ipa.rb +142 -0
  45. data/lib/run_loop/l10n.rb +93 -0
  46. data/lib/run_loop/language.rb +63 -0
  47. data/lib/run_loop/lipo.rb +132 -0
  48. data/lib/run_loop/lldb.rb +52 -0
  49. data/lib/run_loop/locale.rb +101 -0
  50. data/lib/run_loop/logging.rb +111 -0
  51. data/lib/run_loop/otool.rb +76 -0
  52. data/lib/run_loop/patches/awesome_print.rb +17 -0
  53. data/lib/run_loop/physical_device/life_cycle.rb +268 -0
  54. data/lib/run_loop/plist_buddy.rb +189 -0
  55. data/lib/run_loop/process_terminator.rb +128 -0
  56. data/lib/run_loop/process_waiter.rb +117 -0
  57. data/lib/run_loop/regex.rb +19 -0
  58. data/lib/run_loop/shell.rb +103 -0
  59. data/lib/run_loop/sim_control.rb +1264 -0
  60. data/lib/run_loop/simctl.rb +275 -0
  61. data/lib/run_loop/sqlite.rb +61 -0
  62. data/lib/run_loop/strings.rb +88 -0
  63. data/lib/run_loop/tcc/TCC.db +0 -0
  64. data/lib/run_loop/tcc/tcc.rb +240 -0
  65. data/lib/run_loop/template.rb +61 -0
  66. data/lib/run_loop/version.rb +182 -0
  67. data/lib/run_loop/xcode.rb +318 -0
  68. data/lib/run_loop/xcrun.rb +107 -0
  69. data/lib/run_loop/xcuitest.rb +550 -0
  70. data/lib/run_loop.rb +230 -0
  71. data/plists/simctl/com.apple.UIAutomation.plist +0 -0
  72. data/plists/simctl/com.apple.UIAutomationPlugIn.plist +0 -0
  73. data/scripts/calabash_script_uia.js +28184 -0
  74. data/scripts/lib/json2.min.js +26 -0
  75. data/scripts/lib/log.js +26 -0
  76. data/scripts/lib/on_alert.js +224 -0
  77. data/scripts/read-cmd.sh +2 -0
  78. data/scripts/run_dismiss_location.js +89 -0
  79. data/scripts/run_loop_basic.js +34 -0
  80. data/scripts/run_loop_fast_uia.js +188 -0
  81. data/scripts/run_loop_host.js +117 -0
  82. data/scripts/run_loop_shared_element.js +125 -0
  83. data/scripts/timeout3 +23 -0
  84. data/scripts/udidetect +0 -0
  85. data/vendor-licenses/FBSimulatorControl.LICENSE +30 -0
  86. data/vendor-licenses/xctestctl.LICENSE +32 -0
  87. metadata +443 -0
data/lib/run_loop.rb ADDED
@@ -0,0 +1,230 @@
1
+ require "run_loop/abstract"
2
+ require 'run_loop/regex'
3
+ require 'run_loop/directory'
4
+ require "run_loop/encoding"
5
+ require "run_loop/shell"
6
+ require 'run_loop/environment'
7
+ require 'run_loop/logging'
8
+ require 'run_loop/dot_dir'
9
+ require 'run_loop/xcrun'
10
+ require 'run_loop/xcode'
11
+ require 'run_loop/l10n'
12
+ require 'run_loop/process_terminator'
13
+ require 'run_loop/process_waiter'
14
+ require 'run_loop/lldb'
15
+ require 'run_loop/dylib_injector'
16
+ require 'run_loop/fifo'
17
+ require 'run_loop/core'
18
+ require 'run_loop/version'
19
+ require 'run_loop/plist_buddy'
20
+ require "run_loop/codesign"
21
+ require 'run_loop/app'
22
+ require 'run_loop/ipa'
23
+ require "run_loop/device_agent/cbxrunner"
24
+ require "run_loop/device_agent/frameworks"
25
+ require "run_loop/device_agent/launcher"
26
+ require "run_loop/device_agent/xctestctl"
27
+ require "run_loop/device_agent/xcodebuild"
28
+ require "run_loop/detect_aut/errors"
29
+ require "run_loop/detect_aut/xamarin_studio"
30
+ require "run_loop/detect_aut/xcode"
31
+ require "run_loop/detect_aut/detect"
32
+ require 'run_loop/sim_control'
33
+ require 'run_loop/device'
34
+ require 'run_loop/instruments'
35
+ require 'run_loop/lipo'
36
+ require "run_loop/otool"
37
+ require "run_loop/strings"
38
+ require 'run_loop/cache/cache'
39
+ require 'run_loop/host_cache'
40
+ require 'run_loop/patches/awesome_print'
41
+ require 'run_loop/core_simulator'
42
+ require "run_loop/simctl"
43
+ require 'run_loop/template'
44
+ require "run_loop/locale"
45
+ require "run_loop/language"
46
+ require "run_loop/xcuitest"
47
+ require "run_loop/http/error"
48
+ require "run_loop/http/server"
49
+ require "run_loop/http/request"
50
+ require "run_loop/http/retriable_client"
51
+ require "run_loop/physical_device/life_cycle"
52
+ require "run_loop/dnssd"
53
+ require "run_loop/sqlite"
54
+ require "run_loop/tcc/tcc"
55
+
56
+ module RunLoop
57
+
58
+ # Prints a deprecated message that includes the line number.
59
+ #
60
+ # @param [String] version Indicates when the feature was deprecated.
61
+ # @param [String] msg Deprecation message (possibly suggesting alternatives)
62
+ # @return [void]
63
+ def self.deprecated(version, msg)
64
+
65
+ stack = Kernel.caller(0, 6)[1..-1].join("\n")
66
+
67
+ msg = "deprecated '#{version}' - #{msg}\n#{stack}"
68
+
69
+ $stderr.puts "\033[34mWARN: #{msg}\033[0m"
70
+ $stderr.flush
71
+ end
72
+
73
+ class TimeoutError < RuntimeError
74
+ end
75
+
76
+ class WriteFailedError < RuntimeError
77
+ end
78
+
79
+ def self.run(options={})
80
+
81
+ cloned_options = options.clone
82
+
83
+ # We want to use the _exact_ objects that were passed.
84
+ if options[:xcode]
85
+ cloned_options[:xcode] = options[:xcode]
86
+ end
87
+
88
+ if options[:simctl]
89
+ cloned_options[:simctl] = options[:simctl]
90
+ end
91
+
92
+ # Soon to be unsupported.
93
+ if options[:sim_control]
94
+ cloned_options[:sim_control] = options[:sim_control]
95
+ end
96
+
97
+ if options[:xcuitest]
98
+ RunLoop::XCUITest.run(cloned_options)
99
+ else
100
+ if RunLoop::Instruments.new.instruments_app_running?
101
+ raise %q(The Instruments.app is open.
102
+
103
+ If the Instruments.app is open, the instruments command line tool cannot take
104
+ control of your application.
105
+
106
+ Please quit the Instruments.app and try again.)
107
+
108
+ end
109
+ Core.run_with_options(cloned_options)
110
+ end
111
+ end
112
+
113
+ def self.send_command(run_loop, cmd, options={timeout: 60}, num_retries=0, last_error=nil)
114
+ if num_retries > 3
115
+ if last_error
116
+ raise last_error
117
+ else
118
+ raise "Max retries exceeded #{num_retries} > 3. No error recorded."
119
+ end
120
+ end
121
+
122
+ if options.is_a?(Numeric)
123
+ options = {timeout: options}
124
+ end
125
+
126
+ if not cmd.is_a?(String)
127
+ raise "Illegal command #{cmd} (must be a string)"
128
+ end
129
+
130
+ if not options.is_a?(Hash)
131
+ raise "Illegal options #{options} (must be a Hash (or number for compatibility))"
132
+ end
133
+
134
+ timeout = options[:timeout] || 60
135
+ logger = options[:logger]
136
+ interrupt_retry_timeout = options[:interrupt_retry_timeout] || 25
137
+
138
+ expected_index = run_loop[:index]
139
+ result = nil
140
+ begin
141
+ expected_index = Core.write_request(run_loop, cmd, logger)
142
+ rescue RunLoop::WriteFailedError, Errno::EINTR => write_error
143
+ # Attempt recover from interrupt by attempting to read result (assuming write went OK)
144
+ # or retry if attempted read result fails
145
+ run_loop[:index] = expected_index # restore expected index in case it changed
146
+ log_info(logger, "Core.write_request failed: #{write_error}. Attempting recovery...")
147
+ log_info(logger, "Attempting read in case the request was received... Please wait (#{interrupt_retry_timeout})...")
148
+ begin
149
+ Timeout::timeout(interrupt_retry_timeout, TimeoutError) do
150
+ result = Core.read_response(run_loop, expected_index)
151
+ end
152
+ # Update run_loop expected index since we succeeded in reading the index
153
+ run_loop[:index] = expected_index + 1
154
+ log_info(logger, "Did read response for interrupted request of index #{expected_index}... Proceeding.")
155
+ return result
156
+ rescue TimeoutError => _
157
+ log_info(logger, "Read did not result in a response for index #{expected_index}... Retrying send_command...")
158
+ return send_command(run_loop, cmd, options, num_retries+1, write_error)
159
+ end
160
+ end
161
+
162
+
163
+ begin
164
+ Timeout::timeout(timeout, TimeoutError) do
165
+ result = Core.read_response(run_loop, expected_index)
166
+ end
167
+ rescue TimeoutError => _
168
+ raise TimeoutError, "Time out waiting for UIAutomation run-loop for command #{cmd}. Waiting for index:#{expected_index}"
169
+ end
170
+
171
+ result
172
+ end
173
+
174
+ def self.stop(run_loop, out=Dir.pwd)
175
+ return if run_loop.nil?
176
+ results_dir = run_loop[:results_dir]
177
+ dest = out
178
+
179
+ RunLoop::Instruments.new.kill_instruments
180
+
181
+ FileUtils.mkdir_p(dest)
182
+ if results_dir
183
+ pngs = Dir.glob(File.join(results_dir, 'Run 1', '*.png'))
184
+ else
185
+ pngs = []
186
+ end
187
+ FileUtils.cp(pngs, dest) if pngs and pngs.length > 0
188
+ end
189
+
190
+ # @!visibility private
191
+ #
192
+ # @deprecated since 2.1.2
193
+ def self.default_script_for_uia_strategy(uia_strategy)
194
+ self.deprecated("2.1.2", "Replaced by methods in RunLoop::Core")
195
+ case uia_strategy
196
+ when :preferences
197
+ Core.script_for_key(:run_loop_fast_uia)
198
+ when :host
199
+ Core.script_for_key(:run_loop_host)
200
+ when :shared_element
201
+ Core.script_for_key(:run_loop_shared_element)
202
+ else
203
+ Core.script_for_key(:run_loop_basic)
204
+ end
205
+ end
206
+
207
+ # @!visibility private
208
+ #
209
+ # @deprecated since 2.1.2
210
+ def self.validate_script(script)
211
+ self.deprecated("2.1.2", "Replaced by methods in RunLoop::Core")
212
+ if script.is_a?(String)
213
+ unless File.exist?(script)
214
+ raise "Unable to find file: #{script}"
215
+ end
216
+ elsif script.is_a?(Symbol)
217
+ script = Core.script_for_key(script)
218
+ unless script
219
+ raise "Unknown script for symbol: #{script}. Options: #{Core::SCRIPTS.keys.join(', ')}"
220
+ end
221
+ else
222
+ raise "Script must be a symbol or path: #{script}"
223
+ end
224
+ script
225
+ end
226
+
227
+ def self.log_info(*args)
228
+ RunLoop::Logging.log_info(*args)
229
+ end
230
+ end