| 1 |
#!/usr/bin/env python |
| 2 |
# Copyright 2020 The Chromium Authors. All rights reserved. |
| 3 |
# Use of this source code is governed by a BSD-style license that can be |
| 4 |
# found in the LICENSE file. |
| 5 |
|
| 6 |
import subprocess |
| 7 |
import sys |
| 8 |
import threading |
| 9 |
import time |
| 10 |
|
| 11 |
# Usage: ios_debug_cmd.py <bundle_id> <args...> |
| 12 |
# Runs the given app with the given args with full debug output enabled, then |
| 13 |
# outputs syslog for the period when the command was running. Exits with the |
| 14 |
# exit code of idevicedebug. |
| 15 |
|
| 16 |
|
| 17 |
bundle_id = sys.argv[1] |
| 18 |
args = sys.argv[2:] |
| 19 |
|
| 20 |
logp = subprocess.Popen(['idevicesyslog'], stdout=subprocess.PIPE, bufsize=-1) |
| 21 |
log = '' |
| 22 |
def collect_log(): |
| 23 |
global log |
| 24 |
while True: |
| 25 |
out = logp.stdout.read().decode('utf-8') |
| 26 |
if out: |
| 27 |
log = log + out |
| 28 |
else: |
| 29 |
return |
| 30 |
|
| 31 |
logt = threading.Thread(target=collect_log) |
| 32 |
logt.start() |
| 33 |
|
| 34 |
rv = subprocess.call(['idevicedebug', '--debug', 'run', bundle_id] + args) |
| 35 |
|
| 36 |
print('\n\nreturned %d' % rv) |
| 37 |
|
| 38 |
logp.terminate() |
| 39 |
print('\n\nreading syslog...') |
| 40 |
logt.join() |
| 41 |
print('syslog follows') |
| 42 |
print(log) |
| 43 |
|
| 44 |
exit(rv) |