Unverified Commit 4f8acd84 authored by Michael Klimushyn's avatar Michael Klimushyn Committed by GitHub

Set `FlutterDevice.viewFilter` by CLI flag (#23026)

`FlutterDevice.views` is limited by a filter. Pipe this filter up as an
option for the commands that instantiate `FlutterDevice`s. This is the
first change necessary for the CLI tooling to target specific isolates
(#22009).

More work needs to be done after this patch.
* Isolate names are dynamically generated and change every restart.
* This just filters views, not background isolates (`VMService.isolates`).
parent e4c2c978
...@@ -37,6 +37,7 @@ final String ipv4Loopback = InternetAddress.loopbackIPv4.address; ...@@ -37,6 +37,7 @@ final String ipv4Loopback = InternetAddress.loopbackIPv4.address;
class AttachCommand extends FlutterCommand { class AttachCommand extends FlutterCommand {
AttachCommand({bool verboseHelp = false, this.hotRunnerFactory}) { AttachCommand({bool verboseHelp = false, this.hotRunnerFactory}) {
addBuildModeFlags(defaultToRelease: false); addBuildModeFlags(defaultToRelease: false);
usesIsolateFilterOption(hide: !verboseHelp);
usesTargetOption(); usesTargetOption();
usesFilesystemOptions(hide: !verboseHelp); usesFilesystemOptions(hide: !verboseHelp);
argParser argParser
...@@ -122,6 +123,7 @@ class AttachCommand extends FlutterCommand { ...@@ -122,6 +123,7 @@ class AttachCommand extends FlutterCommand {
dillOutputPath: argResults['output-dill'], dillOutputPath: argResults['output-dill'],
fileSystemRoots: argResults['filesystem-root'], fileSystemRoots: argResults['filesystem-root'],
fileSystemScheme: argResults['filesystem-scheme'], fileSystemScheme: argResults['filesystem-scheme'],
viewFilter: argResults['isolate-filter'],
); );
flutterDevice.observatoryUris = <Uri>[ observatoryUri ]; flutterDevice.observatoryUris = <Uri>[ observatoryUri ];
final HotRunner hotRunner = hotRunnerFactory.build( final HotRunner hotRunner = hotRunnerFactory.build(
......
...@@ -338,6 +338,7 @@ class AppDomain extends Domain { ...@@ -338,6 +338,7 @@ class AppDomain extends Domain {
String packagesFilePath, String packagesFilePath,
String dillOutputPath, String dillOutputPath,
bool ipv6 = false, bool ipv6 = false,
String isolateFilter,
}) async { }) async {
if (await device.isLocalEmulator && !options.buildInfo.supportsEmulator) { if (await device.isLocalEmulator && !options.buildInfo.supportsEmulator) {
throw '${toTitleCase(options.buildInfo.modeName)} mode is not supported for emulators.'; throw '${toTitleCase(options.buildInfo.modeName)} mode is not supported for emulators.';
...@@ -351,6 +352,7 @@ class AppDomain extends Domain { ...@@ -351,6 +352,7 @@ class AppDomain extends Domain {
device, device,
trackWidgetCreation: trackWidgetCreation, trackWidgetCreation: trackWidgetCreation,
dillOutputPath: dillOutputPath, dillOutputPath: dillOutputPath,
viewFilter: isolateFilter,
); );
ResidentRunner runner; ResidentRunner runner;
......
...@@ -158,6 +158,7 @@ class FuchsiaReloadCommand extends FlutterCommand { ...@@ -158,6 +158,7 @@ class FuchsiaReloadCommand extends FlutterCommand {
final FlutterDevice flutterDevice = FlutterDevice( final FlutterDevice flutterDevice = FlutterDevice(
device, device,
trackWidgetCreation: false, trackWidgetCreation: false,
viewFilter: isolateName,
); );
flutterDevice.observatoryUris = observatoryUris; flutterDevice.observatoryUris = observatoryUris;
final HotRunner hotRunner = HotRunner(<FlutterDevice>[flutterDevice], final HotRunner hotRunner = HotRunner(<FlutterDevice>[flutterDevice],
...@@ -166,7 +167,7 @@ class FuchsiaReloadCommand extends FlutterCommand { ...@@ -166,7 +167,7 @@ class FuchsiaReloadCommand extends FlutterCommand {
projectRootPath: _fuchsiaProjectPath, projectRootPath: _fuchsiaProjectPath,
packagesFilePath: _dotPackagesPath); packagesFilePath: _dotPackagesPath);
printStatus('Connecting to $_modName'); printStatus('Connecting to $_modName');
await hotRunner.attach(viewFilter: isolateName); await hotRunner.attach();
} finally { } finally {
await Future.wait<void>(forwardedPorts.map<Future<void>>((_PortForwarder pf) => pf.stop())); await Future.wait<void>(forwardedPorts.map<Future<void>>((_PortForwarder pf) => pf.stop()));
} }
......
...@@ -19,6 +19,7 @@ import '../run_hot.dart'; ...@@ -19,6 +19,7 @@ import '../run_hot.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import 'daemon.dart'; import 'daemon.dart';
// TODO(flutter/flutter#23031): Test this.
abstract class RunCommandBase extends FlutterCommand { abstract class RunCommandBase extends FlutterCommand {
// Used by run and drive commands. // Used by run and drive commands.
RunCommandBase({ bool verboseHelp = false }) { RunCommandBase({ bool verboseHelp = false }) {
...@@ -46,6 +47,7 @@ abstract class RunCommandBase extends FlutterCommand { ...@@ -46,6 +47,7 @@ abstract class RunCommandBase extends FlutterCommand {
usesTargetOption(); usesTargetOption();
usesPortOptions(); usesPortOptions();
usesPubOption(); usesPubOption();
usesIsolateFilterOption(hide: !verboseHelp);
} }
bool get traceStartup => argResults['trace-startup']; bool get traceStartup => argResults['trace-startup'];
...@@ -351,6 +353,7 @@ class RunCommand extends RunCommandBase { ...@@ -351,6 +353,7 @@ class RunCommand extends RunCommandBase {
dillOutputPath: argResults['output-dill'], dillOutputPath: argResults['output-dill'],
fileSystemRoots: argResults['filesystem-root'], fileSystemRoots: argResults['filesystem-root'],
fileSystemScheme: argResults['filesystem-scheme'], fileSystemScheme: argResults['filesystem-scheme'],
viewFilter: argResults['isolate-filter'],
); );
}).toList(); }).toList();
......
...@@ -34,6 +34,7 @@ class FlutterDevice { ...@@ -34,6 +34,7 @@ class FlutterDevice {
this.dillOutputPath, this.dillOutputPath,
this.fileSystemRoots, this.fileSystemRoots,
this.fileSystemScheme, this.fileSystemScheme,
this.viewFilter,
ResidentCompiler generator, ResidentCompiler generator,
}) : generator = generator ?? ResidentCompiler( }) : generator = generator ?? ResidentCompiler(
artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
...@@ -51,7 +52,7 @@ class FlutterDevice { ...@@ -51,7 +52,7 @@ class FlutterDevice {
List<String> fileSystemRoots; List<String> fileSystemRoots;
String fileSystemScheme; String fileSystemScheme;
StreamSubscription<String> _loggingSubscription; StreamSubscription<String> _loggingSubscription;
String viewFilter; final String viewFilter;
/// If the [reloadSources] parameter is not null the 'reloadSources' service /// If the [reloadSources] parameter is not null the 'reloadSources' service
/// will be registered. /// will be registered.
...@@ -618,14 +619,12 @@ abstract class ResidentRunner { ...@@ -618,14 +619,12 @@ abstract class ResidentRunner {
/// If the [reloadSources] parameter is not null the 'reloadSources' service /// If the [reloadSources] parameter is not null the 'reloadSources' service
/// will be registered /// will be registered
Future<void> connectToServiceProtocol({String viewFilter, Future<void> connectToServiceProtocol({ReloadSources reloadSources, CompileExpression compileExpression}) async {
ReloadSources reloadSources, CompileExpression compileExpression}) async {
if (!debuggingOptions.debuggingEnabled) if (!debuggingOptions.debuggingEnabled)
return Future<void>.error('Error the service protocol is not enabled.'); return Future<void>.error('Error the service protocol is not enabled.');
bool viewFound = false; bool viewFound = false;
for (FlutterDevice device in flutterDevices) { for (FlutterDevice device in flutterDevices) {
device.viewFilter = viewFilter;
await device._connect(reloadSources: reloadSources, await device._connect(reloadSources: reloadSources,
compileExpression: compileExpression); compileExpression: compileExpression);
await device.getVMs(); await device.getVMs();
......
...@@ -12,6 +12,7 @@ import 'globals.dart'; ...@@ -12,6 +12,7 @@ import 'globals.dart';
import 'resident_runner.dart'; import 'resident_runner.dart';
import 'tracing.dart'; import 'tracing.dart';
// TODO(flutter/flutter#23031): Test this.
class ColdRunner extends ResidentRunner { class ColdRunner extends ResidentRunner {
ColdRunner( ColdRunner(
List<FlutterDevice> devices, { List<FlutterDevice> devices, {
......
...@@ -41,6 +41,7 @@ HotRunnerConfig get hotRunnerConfig => context[HotRunnerConfig]; ...@@ -41,6 +41,7 @@ HotRunnerConfig get hotRunnerConfig => context[HotRunnerConfig];
const bool kHotReloadDefault = true; const bool kHotReloadDefault = true;
// TODO(flutter/flutter#23031): Test this.
class HotRunner extends ResidentRunner { class HotRunner extends ResidentRunner {
HotRunner( HotRunner(
List<FlutterDevice> devices, { List<FlutterDevice> devices, {
...@@ -152,13 +153,10 @@ class HotRunner extends ResidentRunner { ...@@ -152,13 +153,10 @@ class HotRunner extends ResidentRunner {
Future<int> attach({ Future<int> attach({
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<void> appStartedCompleter, Completer<void> appStartedCompleter,
String viewFilter,
}) async { }) async {
_didAttach = true; _didAttach = true;
try { try {
await connectToServiceProtocol(viewFilter: viewFilter, await connectToServiceProtocol(reloadSources: _reloadSourcesService, compileExpression: _compileExpressionService);
reloadSources: _reloadSourcesService,
compileExpression: _compileExpressionService);
} catch (error) { } catch (error) {
printError('Error connecting to the service protocol: $error'); printError('Error connecting to the service protocol: $error');
return 2; return 2;
...@@ -285,6 +283,12 @@ class HotRunner extends ResidentRunner { ...@@ -285,6 +283,12 @@ class HotRunner extends ResidentRunner {
// occurred and tighten this message. // occurred and tighten this message.
printStatus('Try again after fixing the above error(s).', emphasis: true); printStatus('Try again after fixing the above error(s).', emphasis: true);
} }
} else if (lower == 'l') {
final List<FlutterView> views = flutterDevices.expand((FlutterDevice d) => d.views).toList();
printStatus('Connected ${pluralize('view', views.length)}:');
for (FlutterView v in views) {
printStatus('${v.uiIsolate.name} (${v.uiIsolate.id})', indent: 2);
}
} }
} }
......
...@@ -166,6 +166,14 @@ abstract class FlutterCommand extends Command<void> { ...@@ -166,6 +166,14 @@ abstract class FlutterCommand extends Command<void> {
valueHelp: 'x.y.z'); valueHelp: 'x.y.z');
} }
void usesIsolateFilterOption({@required bool hide}) {
argParser.addOption('isolate-filter',
defaultsTo: null,
hide: hide,
help: 'Restricts commands to a subset of the available isolates (running instances of Flutter).\n'
'Normally there\'s only one, but when adding Flutter to a pre-existing app it\'s possible to create multiple.');
}
void addBuildModeFlags({bool defaultToRelease = true, bool verboseHelp = false}) { void addBuildModeFlags({bool defaultToRelease = true, bool verboseHelp = false}) {
defaultBuildMode = defaultToRelease ? BuildMode.release : BuildMode.debug; defaultBuildMode = defaultToRelease ? BuildMode.release : BuildMode.debug;
......
...@@ -102,6 +102,7 @@ const Duration kLongRequestTimeout = Duration(minutes: 1); ...@@ -102,6 +102,7 @@ const Duration kLongRequestTimeout = Duration(minutes: 1);
/// Used for RPC requests that should never take a long time. /// Used for RPC requests that should never take a long time.
const Duration kShortRequestTimeout = Duration(seconds: 5); const Duration kShortRequestTimeout = Duration(seconds: 5);
// TODO(flutter/flutter#23031): Test this.
/// A connection to the Dart VM Service. /// A connection to the Dart VM Service.
class VMService { class VMService {
VMService._( VMService._(
......
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