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