Unverified Commit d4589e0c authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] ensure AppRunLogger is injected for run/attach machine (#61103)

run/attach --machine requires a different logger than daemon, which uses the NotifyingLogger. We have too many loggers!

Fixes #59463
parent 496ef4f7
......@@ -66,9 +66,9 @@ Future<void> main(List<String> args) async {
(args.isNotEmpty && args.first == 'help') || (args.length == 1 && verbose);
final bool muteCommandLogging = help || doctor;
final bool verboseHelp = help && verbose;
final bool daemon = args.contains('daemon') ||
(args.contains('--machine') && args.contains('run')) ||
(args.contains('--machine') && args.contains('attach'));
final bool daemon = args.contains('daemon');
final bool runMachine = (args.contains('--machine') && args.contains('run')) ||
(args.contains('--machine') && args.contains('attach'));
await runner.run(args, () => <FlutterCommand>[
AnalyzeCommand(
......@@ -151,5 +151,12 @@ Future<void> main(List<String> args) async {
terminal: globals.terminal,
outputPreferences: globals.outputPreferences,
))
else if (runMachine)
Logger: () => AppRunLogger(parent: StdoutLogger(
timeoutConfiguration: timeoutConfiguration,
stdio: globals.stdio,
terminal: globals.terminal,
outputPreferences: globals.outputPreferences,
))
});
}
......@@ -304,6 +304,7 @@ class AttachCommand extends FlutterCommand {
true,
globals.fs.currentDirectory,
LaunchMode.attach,
globals.logger as AppRunLogger,
);
} on Exception catch (error) {
throwToolExit(error.toString());
......
......@@ -9,7 +9,6 @@ import 'package:uuid/uuid.dart';
import '../android/android_workflow.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
......@@ -517,6 +516,7 @@ class AppDomain extends Domain {
enableHotReload,
cwd,
LaunchMode.run,
globals.logger as AppRunLogger,
);
}
......@@ -528,9 +528,10 @@ class AppDomain extends Domain {
bool enableHotReload,
Directory cwd,
LaunchMode launchMode,
AppRunLogger logger,
) async {
final AppInstance app = AppInstance(_getNewAppId(),
runner: runner, logToStdout: daemon.logToStdout);
runner: runner, logToStdout: daemon.logToStdout, logger: logger);
_apps.add(app);
_sendAppEvent(app, 'start', <String, dynamic>{
'deviceId': device.id,
......@@ -1015,13 +1016,13 @@ class NotifyingLogger extends Logger {
/// A running application, started by this daemon.
class AppInstance {
AppInstance(this.id, { this.runner, this.logToStdout = false });
AppInstance(this.id, { this.runner, this.logToStdout = false, @required AppRunLogger logger })
: _logger = logger;
final String id;
final ResidentRunner runner;
final bool logToStdout;
_AppRunLogger _logger;
final AppRunLogger _logger;
Future<OperationResult> restart({ bool fullRestart = false, bool pause = false, String reason }) {
return runner.restart(fullRestart: fullRestart, pause: pause, reason: reason);
......@@ -1038,15 +1039,10 @@ class AppInstance {
_logger.close();
}
Future<T> _runInZone<T>(AppDomain domain, FutureOr<T> method()) {
_logger ??= _AppRunLogger(domain, this, parent: logToStdout ? globals.logger : null);
return context.run<T>(
body: method,
overrides: <Type, Generator>{
Logger: () => _logger,
},
);
Future<T> _runInZone<T>(AppDomain domain, FutureOr<T> method()) async {
_logger.domain = domain;
_logger.app = this;
return method();
}
}
......@@ -1103,11 +1099,11 @@ class EmulatorDomain extends Domain {
//
// TODO(devoncarew): To simplify this code a bit, we could choose to specialize
// this class into two, one for each of the above use cases.
class _AppRunLogger extends Logger {
_AppRunLogger(this.domain, this.app, { this.parent });
class AppRunLogger extends Logger {
AppRunLogger({ this.parent });
AppDomain domain;
final AppInstance app;
AppInstance app;
final Logger parent;
int _nextProgressId = 0;
......
......@@ -139,7 +139,6 @@ abstract class ChromiumDevice extends Device {
debugPort: debuggingOptions.webBrowserDebugPort,
);
}
_logger.sendEvent('app.webLaunchUrl', <String, dynamic>{'url': url, 'launched': launchChrome});
return LaunchResult.succeeded(observatoryUri: url != null ? Uri.parse(url): null);
}
......
......@@ -41,26 +41,28 @@ void main() {
expect(result.stdout, isNot(contains('exiting with code 0')));
});
test('flutter run --machine uses NotifyingLogger', () async {
test('flutter run --machine uses AppRunLogger', () async {
final String flutterBin = globals.fs.path.join(getFlutterRoot(), 'bin', 'flutter');
final ProcessResult result = await const LocalProcessManager().run(<String>[
flutterBin,
'run',
'--machine',
'-v',
]);
expect(result.stdout, isEmpty);
expect(result.stdout, isNotEmpty);
});
test('flutter attach --machine uses NotifyingLogger', () async {
test('flutter attach --machine uses AppRunLogger', () async {
final String flutterBin = globals.fs.path.join(getFlutterRoot(), 'bin', 'flutter');
final ProcessResult result = await const LocalProcessManager().run(<String>[
flutterBin,
'attach',
'--machine',
'-v',
]);
expect(result.stdout, isEmpty);
expect(result.stdout, isNotEmpty);
});
test('flutter build aot is deprecated', () async {
......
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