patch from chinmaygarde@ to make progress on mac, ios.
[chromium-blink-merge.git] / build / config / ios / ios_sim.py
blob371719d5a31f64dd0cc8106884b6988e514f1f5d
1 #!/usr/bin/python
2 # Copyright (c) 2015 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.
6 import argparse
7 import errno
8 import os
9 import subprocess
10 import sys
11 import re
13 SIMCTL_PATH = [
14 '/usr/bin/env',
15 'xcrun',
16 'simctl',
19 PLIST_BUDDY_PATH = [
20 '/usr/bin/env',
21 'xcrun',
22 'PlistBuddy',
26 def ApplicationIdentifier(path):
27 identifier = subprocess.check_output(PLIST_BUDDY_PATH + [
28 '-c',
29 'Print CFBundleIdentifier',
30 '%s/Info.plist' % path,
32 return identifier.strip()
35 def Install(args):
36 return subprocess.check_call(SIMCTL_PATH + [
37 'install',
38 'booted',
39 args.path,
43 def InstallLaunchAndWait(args, wait):
44 res = Install(args)
46 if res != 0:
47 return res
49 identifier = ApplicationIdentifier(args.path)
51 launch_args = [ 'launch' ]
53 if wait:
54 launch_args += [ '-w' ]
56 launch_args += [
57 'booted',
58 identifier,
61 return subprocess.check_output(SIMCTL_PATH + launch_arg).strip()
64 def Launch(args):
65 InstallLaunchAndWait(args, False)
68 def Debug(args):
69 launch_res = InstallLaunchAndWait(args, True)
70 launch_pid = re.search('.*: (\d+)', launch_res).group(1)
71 return os.system(' '.join([
72 '/usr/bin/env',
73 'xcrun',
74 'lldb',
75 '-s',
76 os.path.join(os.path.dirname(__file__), 'lldb_start_commands.txt'),
77 '-p',
78 launch_pid,
79 ]))
82 def main():
83 parser = argparse.ArgumentParser(description='A script that launches an'
84 ' application in the simulator and attaches'
85 ' the debugger to the same')
87 parser.add_argument('-p', dest='path', required=True,
88 help='Path the the simulator application')
90 subparsers = parser.add_subparsers()
92 launch_parser = subparsers.add_parser('launch', help='Launch')
93 launch_parser.set_defaults(func=Launch)
95 install_parser = subparsers.add_parser('install', help='Install')
96 install_parser.set_defaults(func=Install)
98 debug_parser = subparsers.add_parser('debug', help='Debug')
99 debug_parser.set_defaults(func=Debug)
101 args = parser.parse_args()
102 return args.func(args)
105 if __name__ == '__main__':
106 sys.exit(main())