Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(938)

Side by Side Diff: sky/tools/shelldb

Issue 1221123003: SkyDemo should use explicit intents (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/shell/android/org/domokit/sky/shell/SkyActivity.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 from skypy.skyserver import SkyServer 6 from skypy.skyserver import SkyServer
7 import argparse 7 import argparse
8 import hashlib 8 import hashlib
9 import json 9 import json
10 import logging 10 import logging
11 import os 11 import os
12 import pipes 12 import pipes
13 import platform 13 import platform
14 import re 14 import re
15 import signal 15 import signal
16 import subprocess 16 import subprocess
17 import sys 17 import sys
18 import tempfile 18 import tempfile
19 import time 19 import time
20 import urlparse 20 import urlparse
21 21
22 SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) 22 SKY_TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
23 SKY_ROOT = os.path.dirname(SKY_TOOLS_DIR) 23 SKY_ROOT = os.path.dirname(SKY_TOOLS_DIR)
24 SRC_ROOT = os.path.dirname(SKY_ROOT) 24 SRC_ROOT = os.path.dirname(SKY_ROOT)
25 25
26 GDB_PORT = 8888 26 GDB_PORT = 8888
27 SKY_SERVER_PORT = 9888 27 SKY_SERVER_PORT = 9888
28 OBSERVATORY_PORT = 8181 28 OBSERVATORY_PORT = 8181
29 DEFAULT_URL = "sky://domokit.github.io/home.dart" 29 DEFAULT_URL = "https://domokit.github.io/home.dart"
30 APK_NAME = 'SkyDemo.apk' 30 APK_NAME = 'SkyDemo.apk'
31 ADB_PATH = os.path.join(SRC_ROOT, 31 ADB_PATH = os.path.join(SRC_ROOT,
32 'third_party/android_tools/sdk/platform-tools/adb') 32 'third_party/android_tools/sdk/platform-tools/adb')
33 ANDROID_PACKAGE = "org.domokit.sky.demo" 33 ANDROID_PACKAGE = "org.domokit.sky.demo"
34 ANDROID_COMPONENT = '%s/%s.SkyDemoActivity' % (ANDROID_PACKAGE, ANDROID_PACKAGE)
34 SHA1_PATH = '/sdcard/%s/%s.sha1' % (ANDROID_PACKAGE, APK_NAME) 35 SHA1_PATH = '/sdcard/%s/%s.sha1' % (ANDROID_PACKAGE, APK_NAME)
35 36
36 PID_FILE_PATH = "/tmp/skydemo.pids" 37 PID_FILE_PATH = "/tmp/skydemo.pids"
37 PID_FILE_KEYS = frozenset([ 38 PID_FILE_KEYS = frozenset([
38 'remote_sky_server_port', 39 'remote_sky_server_port',
39 'sky_server_pid', 40 'sky_server_pid',
40 'sky_server_port', 41 'sky_server_port',
41 'sky_server_root', 42 'sky_server_root',
42 'build_dir', 43 'build_dir',
43 'sky_shell_pid', 44 'sky_shell_pid',
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return cls(known_keys, contents) 98 return cls(known_keys, contents)
98 99
99 def write_to(self, path): 100 def write_to(self, path):
100 try: 101 try:
101 with open(path, 'w') as pid_file: 102 with open(path, 'w') as pid_file:
102 json.dump(self._dict, pid_file, indent=2, sort_keys=True) 103 json.dump(self._dict, pid_file, indent=2, sort_keys=True)
103 except: 104 except:
104 logging.warn('Failed to write pid file: %s' % path) 105 logging.warn('Failed to write pid file: %s' % path)
105 106
106 107
107 def _convert_to_sky_url(url):
108 parts = urlparse.urlsplit(url)
109 parts = parts._replace(scheme='sky')
110 return parts.geturl()
111
112
113 # A free function for possible future sharing with a 'load' command. 108 # A free function for possible future sharing with a 'load' command.
114 def _url_from_args(args, pids): 109 def _url_from_args(args, pids):
115 if urlparse.urlparse(args.url_or_path).scheme: 110 if urlparse.urlparse(args.url_or_path).scheme:
116 return args.url_or_path 111 return args.url_or_path
117 # The load happens on the remote device, use the remote port. 112 # The load happens on the remote device, use the remote port.
118 remote_sky_server_port = pids.get('remote_sky_server_port', 113 remote_sky_server_port = pids.get('remote_sky_server_port',
119 pids['sky_server_port']) 114 pids['sky_server_port'])
120 url = SkyServer.url_for_path(remote_sky_server_port, 115 return SkyServer.url_for_path(remote_sky_server_port,
121 pids['sky_server_root'], args.url_or_path) 116 pids['sky_server_root'], args.url_or_path)
122 return _convert_to_sky_url(url)
123 117
124 118
125 def dev_packages_root(build_dir): 119 def dev_packages_root(build_dir):
126 return os.path.join(build_dir, 'gen', 'dart-pkg', 'packages') 120 return os.path.join(build_dir, 'gen', 'dart-pkg', 'packages')
127 121
128 122
129 class SetBuildDir(object): 123 class SetBuildDir(object):
130 def add_subparser(self, subparsers): 124 def add_subparser(self, subparsers):
131 start_parser = subparsers.add_parser('set_build_dir', 125 start_parser = subparsers.add_parser('set_build_dir',
132 help='force the build_dir to a particular value without starting Sky ') 126 help='force the build_dir to a particular value without starting Sky ')
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 subprocess.check_call([ 222 subprocess.check_call([
229 ADB_PATH, 'forward', port_string, port_string 223 ADB_PATH, 'forward', port_string, port_string
230 ]) 224 ])
231 225
232 port_string = 'tcp:%s' % sky_server.port 226 port_string = 'tcp:%s' % sky_server.port
233 subprocess.check_call([ 227 subprocess.check_call([
234 ADB_PATH, 'reverse', port_string, port_string 228 ADB_PATH, 'reverse', port_string, port_string
235 ]) 229 ])
236 pids['remote_sky_server_port'] = sky_server.port 230 pids['remote_sky_server_port'] = sky_server.port
237 231
238
239 subprocess.check_call([ADB_PATH, 'shell', 232 subprocess.check_call([ADB_PATH, 'shell',
240 'am', 'start', 233 'am', 'start',
241 '-a', 'android.intent.action.VIEW', 234 '-a', 'android.intent.action.VIEW',
242 '-d', _url_from_args(args, pids)]) 235 '-d', _url_from_args(args, pids),
236 ANDROID_COMPONENT])
243 237
244 if not args.gdb: 238 if not args.gdb:
245 return 239 return
246 240
247 # TODO(eseidel): am start -W does not seem to work? 241 # TODO(eseidel): am start -W does not seem to work?
248 pid_tries = 0 242 pid_tries = 0
249 while True: 243 while True:
250 pid = self._find_remote_pid_for_package(ANDROID_PACKAGE) 244 pid = self._find_remote_pid_for_package(ANDROID_PACKAGE)
251 if pid or pid_tries > 3: 245 if pid or pid_tries > 3:
252 break 246 break
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 args = parser.parse_args() 493 args = parser.parse_args()
500 pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS) 494 pids = Pids.read_from(PID_FILE_PATH, PID_FILE_KEYS)
501 exit_code = args.func(args, pids) 495 exit_code = args.func(args, pids)
502 # We could do this with an at-exit handler instead? 496 # We could do this with an at-exit handler instead?
503 pids.write_to(PID_FILE_PATH) 497 pids.write_to(PID_FILE_PATH)
504 sys.exit(exit_code) 498 sys.exit(exit_code)
505 499
506 500
507 if __name__ == '__main__': 501 if __name__ == '__main__':
508 SkyShellRunner().main() 502 SkyShellRunner().main()
OLDNEW
« no previous file with comments | « sky/shell/android/org/domokit/sky/shell/SkyActivity.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698