OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import atexit | 5 import atexit |
6 import hashlib | 6 import hashlib |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import os.path | 9 import os.path |
10 import random | 10 import random |
11 import re | 11 import re |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 import tempfile | 14 import tempfile |
15 import threading | 15 import threading |
16 import time | 16 import time |
17 import uuid | 17 import uuid |
18 | 18 |
19 from devtoolslib.http_server import start_http_server | 19 from devtoolslib import http_server |
20 from devtoolslib.shell import Shell | 20 from devtoolslib.shell import Shell |
21 from devtoolslib.utils import overrides | 21 from devtoolslib.utils import overrides |
22 | 22 |
23 | 23 |
24 # Tags used by mojo shell Java logging. | 24 # Tags used by mojo shell Java logging. |
25 _LOGCAT_JAVA_TAGS = [ | 25 _LOGCAT_JAVA_TAGS = [ |
26 'AndroidHandler', | 26 'AndroidHandler', |
27 'MojoFileHelper', | 27 'MojoFileHelper', |
28 'MojoMain', | 28 'MojoMain', |
29 'MojoShellActivity', | 29 'MojoShellActivity', |
(...skipping 384 matching lines...) Loading... |
414 host_port = self._forward_host_port_to_device(0, device_port) | 414 host_port = self._forward_host_port_to_device(0, device_port) |
415 print ("Dart observatory available at the host at http://127.0.0.1:%d" | 415 print ("Dart observatory available at the host at http://127.0.0.1:%d" |
416 % host_port) | 416 % host_port) |
417 | 417 |
418 logcat_watch_thread = threading.Thread( | 418 logcat_watch_thread = threading.Thread( |
419 target=_forward_observatories_as_needed) | 419 target=_forward_observatories_as_needed) |
420 logcat_watch_thread.daemon = True | 420 logcat_watch_thread.daemon = True |
421 logcat_watch_thread.start() | 421 logcat_watch_thread.start() |
422 | 422 |
423 @overrides(Shell) | 423 @overrides(Shell) |
424 def serve_local_directories(self, mappings, port=0, free_host_port=False): | 424 def serve_local_directories(self, mappings, port=0, reuse_servers=False): |
425 assert mappings | 425 assert mappings |
426 host_port = 0 if free_host_port else port | 426 if reuse_servers: |
427 server_address = start_http_server(mappings, host_port=host_port) | 427 assert port, 'Cannot reuse the server when |port| is 0.' |
| 428 server_address = ('127.0.0.1', port) |
| 429 else: |
| 430 server_address = http_server.start_http_server(mappings, port) |
428 | 431 |
429 return 'http://127.0.0.1:%d/' % self._forward_device_port_to_host( | 432 return 'http://127.0.0.1:%d/' % self._forward_device_port_to_host( |
430 port, server_address[1]) | 433 port, server_address[1]) |
431 | 434 |
432 @overrides(Shell) | 435 @overrides(Shell) |
433 def forward_host_port_to_shell(self, host_port): | 436 def forward_host_port_to_shell(self, host_port): |
434 self._forward_host_port_to_device(host_port, host_port) | 437 self._forward_host_port_to_device(host_port, host_port) |
435 | 438 |
436 @overrides(Shell) | 439 @overrides(Shell) |
437 def run(self, arguments): | 440 def run(self, arguments): |
(...skipping 23 matching lines...) Loading... |
461 Results.output = rf.read() | 464 Results.output = rf.read() |
462 | 465 |
463 run_thread = threading.Thread(target=do_run) | 466 run_thread = threading.Thread(target=do_run) |
464 run_thread.start() | 467 run_thread.start() |
465 run_thread.join(timeout) | 468 run_thread.join(timeout) |
466 | 469 |
467 if run_thread.is_alive(): | 470 if run_thread.is_alive(): |
468 self.stop_shell() | 471 self.stop_shell() |
469 return None, Results.output, True | 472 return None, Results.output, True |
470 return None, Results.output, False | 473 return None, Results.output, False |
OLD | NEW |