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