Commit 576b4e11 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Change --debug-port to --observatory-port (#7675)

...and add --diagnostic-port.

...and document port 0.
parent 682c7992
......@@ -445,7 +445,7 @@ class AndroidDevice extends Device {
Match match = discoverExp.firstMatch(line);
if (match != null) {
Map<String, dynamic> app = JSON.decode(match.group(1));
result.add(new DiscoveredApp(app['id'], app['observatoryPort']));
result.add(new DiscoveredApp(app['id'], app['observatoryPort'], app['diagnosticPort']));
}
});
......
......@@ -163,6 +163,7 @@ Future<int> findPreferredPort(int defaultPort, { int searchStep: 2 }) async {
Future<bool> _isPortAvailable(int port) async {
try {
// TODO(ianh): This is super racy.
ServerSocket socket = await ServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, port);
await socket.close();
return true;
......
......@@ -485,7 +485,8 @@ class AppDomain extends Domain {
return apps.map((DiscoveredApp app) {
return <String, dynamic>{
'id': app.id,
'observatoryDevicePort': app.observatoryPort
'observatoryDevicePort': app.observatoryPort,
'diagnosticDevicePort': app.diagnosticPort,
};
}).toList();
}
......
......@@ -65,10 +65,7 @@ class DriveCommand extends RunCommandBase {
'the application running after tests are done.'
);
argParser.addOption('debug-port',
defaultsTo: kDefaultDrivePort.toString(),
help: 'Listen to the given port for a debug connection.'
);
usesPortOptions();
}
@override
......@@ -87,7 +84,8 @@ class DriveCommand extends RunCommandBase {
// ignore: cancel_subscriptions
StreamSubscription<String> _deviceLogSubscription;
int get debugPort => int.parse(argResults['debug-port']);
int get observatoryPort => int.parse(argResults['observatory-port']);
int get diagnosticPort => int.parse(argResults['diagnostic-port']);
@override
Future<Null> verifyThenRunCommand() async {
......@@ -315,7 +313,8 @@ Future<int> startApp(DriveCommand command) async {
debuggingOptions: new DebuggingOptions.enabled(
command.getBuildMode(),
startPaused: true,
observatoryPort: command.debugPort
observatoryPort: command.observatoryPort,
diagnosticPort: command.diagnosticPort,
),
platformArgs: platformArgs
);
......
......@@ -50,8 +50,7 @@ class RunCommand extends RunCommandBase {
defaultsTo: false,
negatable: false,
help: 'Start in a paused mode and wait for a debugger to connect.');
argParser.addOption('debug-port',
help: 'Listen to the given port for a debug connection (defaults to $kDefaultObservatoryPort).');
usesPortOptions();
argParser.addFlag('build',
defaultsTo: true,
help: 'If necessary, build the app before running.');
......@@ -190,12 +189,21 @@ class RunCommand extends RunCommandBase {
return null;
}
int debugPort;
if (argResults['debug-port'] != null) {
int observatoryPort;
if (argResults['observatory-port'] != null) {
try {
debugPort = int.parse(argResults['debug-port']);
observatoryPort = int.parse(argResults['observatory-port']);
} catch (error) {
throwToolExit('Invalid port for `--debug-port`: $error');
throwToolExit('Invalid port for `--observatory-port`: $error');
}
}
int diagnosticPort;
if (argResults['diagnostic-port'] != null) {
try {
diagnosticPort = int.parse(argResults['diagnostic-port']);
} catch (error) {
throwToolExit('Invalid port for `--diagnostic-port`: $error');
}
}
......@@ -210,7 +218,8 @@ class RunCommand extends RunCommandBase {
options = new DebuggingOptions.enabled(
getBuildMode(),
startPaused: argResults['start-paused'],
observatoryPort: debugPort
observatoryPort: observatoryPort,
diagnosticPort: diagnosticPort,
);
}
......
......@@ -313,6 +313,8 @@ class DebuggingOptions {
/// Return the user specified diagnostic port. If that isn't available,
/// return [kDefaultDiagnosticPort], or a port close to that one.
Future<int> findBestDiagnosticPort() {
if (hasDiagnosticPort)
return new Future<int>.value(diagnosticPort);
return findPreferredPort(diagnosticPort ?? kDefaultDiagnosticPort);
}
}
......@@ -378,7 +380,8 @@ abstract class DeviceLogReader {
/// Describes an app running on the device.
class DiscoveredApp {
DiscoveredApp(this.id, this.observatoryPort);
DiscoveredApp(this.id, this.observatoryPort, this.diagnosticPort);
final String id;
final int observatoryPort;
final int diagnosticPort;
}
......@@ -183,7 +183,6 @@ class HotRunner extends ResidentRunner {
return 2;
}
try {
Uri baseUri = await _initDevFS();
if (connectionInfoCompleter != null) {
......
......@@ -299,8 +299,8 @@ class IOSDevice extends Device {
if (installationResult != 0) {
printError('Could not install ${bundle.path} on $id.');
printError("Try launching XCode and selecting 'Product > Run' to fix the problem:");
printError(" open ios/Runner.xcodeproj");
printError('Try launching XCode and selecting "Product > Run" to fix the problem:');
printError(' open ios/Runner.xcodeproj');
printError('');
return new LaunchResult.failed();
}
......
......@@ -453,6 +453,8 @@ class IOSSimulator extends Device {
int observatoryPort = await debuggingOptions.findBestObservatoryPort();
args.add("--observatory-port=$observatoryPort");
int diagnosticPort = await debuggingOptions.findBestDiagnosticPort();
args.add("--diagnostic-port=$diagnosticPort");
}
ProtocolDiscovery observatoryDiscovery;
......
......@@ -63,14 +63,13 @@ class ProtocolDiscovery {
hostPort = await portForwarder
.forward(devicePort, hostPort: hostPort)
.timeout(const Duration(seconds: 60), onTimeout: () {
throwToolExit('Timeout while atempting to foward device port $devicePort');
throwToolExit('Timeout while atempting to foward device port $devicePort for $_serviceName');
});
printTrace('Forwarded host port $hostPort to device port $devicePort');
printTrace('Forwarded host port $hostPort to device port $devicePort for $_serviceName');
hostUri = deviceUri.replace(port: hostPort);
} else {
hostUri = deviceUri;
}
printStatus('$_serviceName listening on $hostUri');
return hostUri;
}
......
......@@ -143,9 +143,8 @@ abstract class ResidentRunner {
}
Future<Null> startEchoingDeviceLog(ApplicationPackage app) async {
if (_loggingSubscription != null) {
if (_loggingSubscription != null)
return;
}
_loggingSubscription = device.getLogReader(app: app).logLines.listen((String line) {
if (!line.contains('Observatory listening on http') &&
!line.contains('Diagnostic server listening on http'))
......
......@@ -63,6 +63,19 @@ abstract class FlutterCommand extends Command<Null> {
_usesPubOption = true;
}
void usesPortOptions() {
argParser.addOption('observatory-port',
help: 'Listen to the given port for an observatory debugger connection.\n'
'Specifying port 0 will find a random free port.\n'
'Defaults to the first available port after $kDefaultObservatoryPort.'
);
argParser.addOption('diagnostic-port',
help: 'Listen to the given port for a diagnostic connection.\n'
'Specifying port 0 will find a random free port.\n'
'Defaults to the first available port after $kDefaultDiagnosticPort.'
);
}
void addBuildModeFlags({ bool defaultToRelease: true }) {
defaultBuildMode = defaultToRelease ? BuildMode.release : BuildMode.debug;
......
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