Commit b780c076 authored by Devon Carew's avatar Devon Carew

add --start-paused,--debug-port flags

parent 5a21ef24
......@@ -9,7 +9,9 @@ import 'package:crypto/crypto.dart';
import 'package:path/path.dart' as path;
import '../application_package.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../base/os.dart';
import '../base/process.dart';
import '../build_configuration.dart';
import '../device.dart';
......@@ -33,8 +35,6 @@ class AndroidDeviceDiscovery extends DeviceDiscovery {
}
class AndroidDevice extends Device {
static const int _observatoryPort = 8181;
static final String defaultDeviceID = 'default_android_device';
String productID;
......@@ -240,22 +240,37 @@ class AndroidDevice extends Device {
return true;
}
void _forwardObservatoryPort() {
// Set up port forwarding for observatory.
String portString = 'tcp:$_observatoryPort';
Future _forwardObservatoryPort(int port) async {
bool portWasZero = port == 0;
if (port == 0) {
// Auto-bind to a port. Set up forwarding for that port. Emit a stdout
// message similar to the command-line VM, so that tools can parse the output.
// "Observatory listening on http://127.0.0.1:52111"
port = await findAvailablePort();
}
try {
runCheckedSync(adbCommandForDevice(<String>['forward', portString, portString]));
// Set up port forwarding for observatory.
runCheckedSync(adbCommandForDevice(<String>[
'forward', 'tcp:$port', 'tcp:$observatoryDefaultPort'
]));
if (portWasZero)
printStatus('Observatory listening on http://127.0.0.1:$port');
} catch (e) {
printError('Unable to forward observatory port ($_observatoryPort):\n$e');
printError('Unable to forward Observatory port $port: $e');
}
}
bool startBundle(AndroidApk apk, String bundlePath, {
Future<bool> startBundle(AndroidApk apk, String bundlePath, {
bool checked: true,
bool traceStartup: false,
String route,
bool clearLogs: false
}) {
bool clearLogs: false,
bool startPaused: false,
int debugPort: observatoryDefaultPort
}) async {
printTrace('$this startBundle');
if (!FileSystemEntity.isFileSync(bundlePath)) {
......@@ -263,7 +278,7 @@ class AndroidDevice extends Device {
return false;
}
_forwardObservatoryPort();
await _forwardObservatoryPort(debugPort);
if (clearLogs)
this.clearLogs();
......@@ -280,6 +295,8 @@ class AndroidDevice extends Device {
cmd.addAll(['--ez', 'enable-checked-mode', 'true']);
if (traceStartup)
cmd.addAll(['--ez', 'trace-startup', 'true']);
if (startPaused)
cmd.addAll(['--ez', 'start-paused', 'true']);
if (route != null)
cmd.addAll(['--es', 'route', route]);
cmd.add(apk.launchActivity);
......@@ -295,22 +312,27 @@ class AndroidDevice extends Device {
String route,
bool checked: true,
bool clearLogs: false,
bool startPaused: false,
int debugPort: observatoryDefaultPort,
Map<String, dynamic> platformArgs
}) {
return flx.buildInTempDir(
}) async {
flx.DirectoryResult buildResult = await flx.buildInTempDir(
toolchain,
mainPath: mainPath
).then((flx.DirectoryResult buildResult) {
);
printTrace('Starting bundle for $this.');
try {
if (startBundle(
if (await startBundle(
package,
buildResult.localBundlePath,
checked: checked,
traceStartup: platformArgs['trace-startup'],
route: route,
clearLogs: clearLogs
clearLogs: clearLogs,
startPaused: startPaused,
debugPort: debugPort
)) {
return true;
} else {
......@@ -319,7 +341,6 @@ class AndroidDevice extends Device {
} finally {
buildResult.dispose();
}
});
}
Future<bool> stopApp(ApplicationPackage app) async {
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const int observatoryDefaultPort = 8181;
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
final OperatingSystemUtils os = new OperatingSystemUtils._();
......@@ -31,3 +32,10 @@ class _WindowsUtils implements OperatingSystemUtils {
return new ProcessResult(0, 0, null, null);
}
}
Future<int> findAvailablePort() async {
ServerSocket socket = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
int port = socket.port;
await socket.close();
return port;
}
......@@ -8,6 +8,7 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import '../application_package.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../device.dart';
import '../runner/flutter_command.dart';
......@@ -58,6 +59,13 @@ class StartCommand extends StartCommandBase {
argParser.addFlag('clear-logs',
defaultsTo: true,
help: 'Clear log history before starting the app.');
argParser.addFlag('start-paused',
defaultsTo: false,
negatable: false,
help: 'Start in a paused mode and wait for a debugger to connect.');
argParser.addOption('debug-port',
defaultsTo: observatoryDefaultPort.toString(),
help: 'Listen to the given port for a debug connection.');
}
@override
......@@ -71,6 +79,15 @@ class StartCommand extends StartCommandBase {
bool clearLogs = argResults['clear-logs'];
int debugPort;
try {
debugPort = int.parse(argResults['debug-port']);
} catch (error) {
printError('Invalid port for `--debug-port`: $error');
return 1;
}
int result = await startApp(
devices,
applicationPackages,
......@@ -81,7 +98,9 @@ class StartCommand extends StartCommandBase {
checked: argResults['checked'],
traceStartup: argResults['trace-startup'],
route: argResults['route'],
clearLogs: clearLogs
clearLogs: clearLogs,
startPaused: argResults['start-paused'],
debugPort: debugPort
);
printTrace('Finished start command.');
......@@ -99,7 +118,9 @@ Future<int> startApp(
bool checked: true,
bool traceStartup: false,
String route,
bool clearLogs: false
bool clearLogs: false,
bool startPaused: false,
int debugPort: observatoryDefaultPort
}) async {
String mainPath = findMainDartFile(target);
......@@ -144,6 +165,8 @@ Future<int> startApp(
route: route,
checked: checked,
clearLogs: clearLogs,
startPaused: startPaused,
debugPort: debugPort,
platformArgs: platformArgs
);
......
......@@ -6,6 +6,7 @@ import 'dart:async';
import 'android/device_android.dart';
import 'application_package.dart';
import 'base/common.dart';
import 'base/context.dart';
import 'build_configuration.dart';
import 'ios/device_ios.dart';
......@@ -104,6 +105,8 @@ abstract class Device {
String route,
bool checked: true,
bool clearLogs: false,
bool startPaused: false,
int debugPort: observatoryDefaultPort,
Map<String, dynamic> platformArgs
});
......
......@@ -8,6 +8,7 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import '../application_package.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../base/process.dart';
import '../build_configuration.dart';
......@@ -185,9 +186,12 @@ class IOSDevice extends Device {
String route,
bool checked: true,
bool clearLogs: false,
bool startPaused: false,
int debugPort: observatoryDefaultPort,
Map<String, dynamic> platformArgs
}) async {
// TODO(chinmaygarde): Use checked, mainPath, route, clearLogs.
// TODO(devoncarew): Handle startPaused, debugPort.
printTrace('Building ${app.name} for $id');
// Step 1: Install the precompiled application if necessary
......@@ -431,9 +435,12 @@ class IOSSimulator extends Device {
String route,
bool checked: true,
bool clearLogs: false,
bool startPaused: false,
int debugPort: observatoryDefaultPort,
Map<String, dynamic> platformArgs
}) async {
// TODO(chinmaygarde): Use checked, mainPath, route.
// TODO(devoncarew): Handle startPaused, debugPort.
printTrace('Building ${app.name} for $id');
if (clearLogs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment