Unverified Commit 830c0dfe authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Allow attaching to profile builds (#26720)

parent 179fa904
...@@ -16,6 +16,7 @@ import '../fuchsia/fuchsia_device.dart'; ...@@ -16,6 +16,7 @@ import '../fuchsia/fuchsia_device.dart';
import '../globals.dart'; import '../globals.dart';
import '../protocol_discovery.dart'; import '../protocol_discovery.dart';
import '../resident_runner.dart'; import '../resident_runner.dart';
import '../run_cold.dart';
import '../run_hot.dart'; import '../run_hot.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
...@@ -176,6 +177,7 @@ class AttachCommand extends FlutterCommand { ...@@ -176,6 +177,7 @@ class AttachCommand extends FlutterCommand {
: Uri.parse('http://$ipv4Loopback:$localPort/'); : Uri.parse('http://$ipv4Loopback:$localPort/');
} }
try { try {
final bool useHot = getBuildInfo().isDebug;
final FlutterDevice flutterDevice = FlutterDevice( final FlutterDevice flutterDevice = FlutterDevice(
device, device,
trackWidgetCreation: false, trackWidgetCreation: false,
...@@ -186,24 +188,32 @@ class AttachCommand extends FlutterCommand { ...@@ -186,24 +188,32 @@ class AttachCommand extends FlutterCommand {
targetModel: TargetModel(argResults['target-model']), targetModel: TargetModel(argResults['target-model']),
); );
flutterDevice.observatoryUris = <Uri>[ observatoryUri ]; flutterDevice.observatoryUris = <Uri>[ observatoryUri ];
final HotRunner hotRunner = hotRunnerFactory.build( final List<FlutterDevice> flutterDevices = <FlutterDevice>[flutterDevice];
<FlutterDevice>[flutterDevice], final DebuggingOptions debuggingOptions = DebuggingOptions.enabled(getBuildInfo());
final ResidentRunner runner = useHot ?
hotRunnerFactory.build(
flutterDevices,
target: targetFile, target: targetFile,
debuggingOptions: DebuggingOptions.enabled(getBuildInfo()), debuggingOptions: debuggingOptions,
packagesFilePath: globalResults['packages'], packagesFilePath: globalResults['packages'],
usesTerminalUI: daemon == null, usesTerminalUI: daemon == null,
projectRootPath: argResults['project-root'], projectRootPath: argResults['project-root'],
dillOutputPath: argResults['output-dill'], dillOutputPath: argResults['output-dill'],
ipv6: usesIpv6, ipv6: usesIpv6,
)
: ColdRunner(
flutterDevices,
target: targetFile,
debuggingOptions: debuggingOptions,
ipv6: usesIpv6,
); );
if (attachLogger) { if (attachLogger) {
flutterDevice.startEchoingDeviceLog(); flutterDevice.startEchoingDeviceLog();
} }
if (daemon != null) { if (daemon != null) {
AppInstance app; AppInstance app;
try { try {
app = await daemon.appDomain.launch(hotRunner, hotRunner.attach, app = await daemon.appDomain.launch(runner, runner.attach,
device, null, true, fs.currentDirectory); device, null, true, fs.currentDirectory);
} catch (error) { } catch (error) {
throwToolExit(error.toString()); throwToolExit(error.toString());
...@@ -212,7 +222,7 @@ class AttachCommand extends FlutterCommand { ...@@ -212,7 +222,7 @@ class AttachCommand extends FlutterCommand {
if (result != 0) if (result != 0)
throwToolExit(null, exitCode: result); throwToolExit(null, exitCode: result);
} else { } else {
await hotRunner.attach(); await runner.attach();
} }
} finally { } finally {
final List<ForwardedPort> ports = device.portForwarder.forwardedPorts.toList(); final List<ForwardedPort> ports = device.portForwarder.forwardedPorts.toList();
......
...@@ -489,6 +489,11 @@ abstract class ResidentRunner { ...@@ -489,6 +489,11 @@ abstract class ResidentRunner {
bool shouldBuild = true bool shouldBuild = true
}); });
Future<int> attach({
Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<void> appStartedCompleter,
});
bool get supportsRestart => false; bool get supportsRestart => false;
Future<OperationResult> restart({ bool fullRestart = false, bool pauseAfterRestart = false, String reason }) { Future<OperationResult> restart({ bool fullRestart = false, bool pauseAfterRestart = false, String reason }) {
......
...@@ -11,6 +11,7 @@ import 'device.dart'; ...@@ -11,6 +11,7 @@ import 'device.dart';
import 'globals.dart'; import 'globals.dart';
import 'resident_runner.dart'; import 'resident_runner.dart';
import 'tracing.dart'; import 'tracing.dart';
import 'vmservice.dart';
// TODO(mklim): Test this, flutter/flutter#23031. // TODO(mklim): Test this, flutter/flutter#23031.
class ColdRunner extends ResidentRunner { class ColdRunner extends ResidentRunner {
...@@ -34,6 +35,7 @@ class ColdRunner extends ResidentRunner { ...@@ -34,6 +35,7 @@ class ColdRunner extends ResidentRunner {
final bool traceStartup; final bool traceStartup;
final File applicationBinary; final File applicationBinary;
bool _didAttach = false;
@override @override
Future<int> run({ Future<int> run({
...@@ -111,12 +113,50 @@ class ColdRunner extends ResidentRunner { ...@@ -111,12 +113,50 @@ class ColdRunner extends ResidentRunner {
return 0; return 0;
} }
@override
Future<int> attach({
Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<void> appStartedCompleter,
}) async {
_didAttach = true;
try {
await connectToServiceProtocol();
} catch (error) {
printError('Error connecting to the service protocol: $error');
return 2;
}
for (FlutterDevice device in flutterDevices) {
device.initLogReader();
}
await refreshViews();
for (FlutterDevice device in flutterDevices) {
for (FlutterView view in device.views) {
printTrace('Connected to $view.');
}
}
if (stayResident) {
setupTerminal();
registerSignalHandlers();
}
appStartedCompleter?.complete();
if (stayResident) {
return waitForAppToFinish();
}
await cleanupAtFinish();
return 0;
}
@override @override
Future<void> handleTerminalCommand(String code) async { } Future<void> handleTerminalCommand(String code) async { }
@override @override
Future<void> cleanupAfterSignal() async { Future<void> cleanupAfterSignal() async {
await stopEchoingDeviceLog(); await stopEchoingDeviceLog();
if (_didAttach) {
appFinished();
} else {
await stopApp();
}
await stopApp(); await stopApp();
} }
...@@ -145,15 +185,18 @@ class ColdRunner extends ResidentRunner { ...@@ -145,15 +185,18 @@ class ColdRunner extends ResidentRunner {
haveAnything = true; haveAnything = true;
} }
} }
final String quitMessage = _didAttach
? 'To detach, press "d"; to quit, press "q".'
: 'To quit, press "q".';
if (haveDetails && !details) { if (haveDetails && !details) {
if (saveCompilationTrace) { if (saveCompilationTrace) {
printStatus('Compilation training data will be saved when flutter run quits...'); printStatus('Compilation training data will be saved when flutter run quits...');
} }
printStatus('For a more detailed help message, press "h". To quit, press "q".'); printStatus('For a more detailed help message, press "h". $quitMessage');
} else if (haveAnything) { } else if (haveAnything) {
printStatus('To repeat this help message, press "h". To quit, press "q".'); printStatus('To repeat this help message, press "h". $quitMessage');
} else { } else {
printStatus('To quit, press "q".'); printStatus(quitMessage);
} }
} }
......
...@@ -176,6 +176,7 @@ class HotRunner extends ResidentRunner { ...@@ -176,6 +176,7 @@ class HotRunner extends ResidentRunner {
throw 'Failed to compile $expression'; throw 'Failed to compile $expression';
} }
@override
Future<int> attach({ Future<int> attach({
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<void> appStartedCompleter, Completer<void> appStartedCompleter,
......
...@@ -40,6 +40,12 @@ class TestRunner extends ResidentRunner { ...@@ -40,6 +40,12 @@ class TestRunner extends ResidentRunner {
String route, String route,
bool shouldBuild = true, bool shouldBuild = true,
}) async => null; }) async => null;
@override
Future<int> attach({
Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<void> appStartedCompleter,
}) async => null;
} }
void main() { void main() {
......
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