Unverified Commit 4807f806 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove globals from logger (#78353)

parent 4b879c31
...@@ -9,7 +9,6 @@ import 'dart:async'; ...@@ -9,7 +9,6 @@ import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../convert.dart'; import '../convert.dart';
import '../globals.dart' as globals;
import 'io.dart'; import 'io.dart';
import 'terminal.dart' show Terminal, TerminalColor, OutputPreferences; import 'terminal.dart' show Terminal, TerminalColor, OutputPreferences;
import 'utils.dart'; import 'utils.dart';
...@@ -132,6 +131,10 @@ abstract class Logger { ...@@ -132,6 +131,10 @@ abstract class Logger {
int progressIndicatorPadding = kDefaultStatusPadding, int progressIndicatorPadding = kDefaultStatusPadding,
}); });
/// A [SilentStatus] or an [AnsiSpinner] (depending on whether the
/// terminal is fancy enough), already started.
Status startSpinner({ VoidCallback onFinish });
/// Send an event to be emitted. /// Send an event to be emitted.
/// ///
/// Only surfaces a value in machine modes, Loggers may ignore this message in /// Only surfaces a value in machine modes, Loggers may ignore this message in
...@@ -214,6 +217,11 @@ class DelegatingLogger implements Logger { ...@@ -214,6 +217,11 @@ class DelegatingLogger implements Logger {
); );
} }
@override
Status startSpinner({VoidCallback onFinish}) {
return _delegate.startSpinner(onFinish: onFinish);
}
@override @override
bool get supportsColor => _delegate.supportsColor; bool get supportsColor => _delegate.supportsColor;
...@@ -374,6 +382,22 @@ class StdoutLogger extends Logger { ...@@ -374,6 +382,22 @@ class StdoutLogger extends Logger {
return _status; return _status;
} }
@override
Status startSpinner({ VoidCallback onFinish }) {
if (terminal.supportsColor) {
return AnsiSpinner(
onFinish: onFinish,
stopwatch: _stopwatchFactory.createStopwatch(),
terminal: terminal,
stdio: _stdio,
)..start();
}
return SilentStatus(
onFinish: onFinish,
stopwatch: _stopwatchFactory.createStopwatch(),
)..start();
}
void _clearStatus() { void _clearStatus() {
_status = null; _status = null;
} }
...@@ -534,6 +558,14 @@ class BufferLogger extends Logger { ...@@ -534,6 +558,14 @@ class BufferLogger extends Logger {
)..start(); )..start();
} }
@override
Status startSpinner({VoidCallback onFinish}) {
return SilentStatus(
stopwatch: _stopwatchFactory.createStopwatch(),
onFinish: onFinish,
)..start();
}
@override @override
void clear() { void clear() {
_error.clear(); _error.clear();
...@@ -731,26 +763,6 @@ abstract class Status { ...@@ -731,26 +763,6 @@ abstract class Status {
@required Stopwatch stopwatch, @required Stopwatch stopwatch,
}) : _stopwatch = stopwatch; }) : _stopwatch = stopwatch;
/// A [SilentStatus] or an [AnsiSpinner] (depending on whether the
/// terminal is fancy enough), already started.
factory Status.withSpinner({
@required Stopwatch stopwatch,
@required Terminal terminal,
VoidCallback onFinish,
}) {
if (terminal.supportsColor) {
return AnsiSpinner(
onFinish: onFinish,
stopwatch: stopwatch,
terminal: terminal,
)..start();
}
return SilentStatus(
onFinish: onFinish,
stopwatch: stopwatch,
)..start();
}
final VoidCallback onFinish; final VoidCallback onFinish;
@protected @protected
...@@ -822,10 +834,10 @@ class SummaryStatus extends Status { ...@@ -822,10 +834,10 @@ class SummaryStatus extends Status {
@required Stopwatch stopwatch, @required Stopwatch stopwatch,
this.padding = kDefaultStatusPadding, this.padding = kDefaultStatusPadding,
VoidCallback onFinish, VoidCallback onFinish,
Stdio stdio, @required Stdio stdio,
}) : assert(message != null), }) : assert(message != null),
assert(padding != null), assert(padding != null),
_stdio = stdio ?? globals.stdio, _stdio = stdio,
super( super(
onFinish: onFinish, onFinish: onFinish,
stopwatch: stopwatch, stopwatch: stopwatch,
...@@ -890,8 +902,8 @@ class AnsiSpinner extends Status { ...@@ -890,8 +902,8 @@ class AnsiSpinner extends Status {
@required Stopwatch stopwatch, @required Stopwatch stopwatch,
@required Terminal terminal, @required Terminal terminal,
VoidCallback onFinish, VoidCallback onFinish,
Stdio stdio, @required Stdio stdio,
}) : _stdio = stdio ?? globals.stdio, }) : _stdio = stdio,
_terminal = terminal, _terminal = terminal,
super( super(
onFinish: onFinish, onFinish: onFinish,
......
...@@ -1024,6 +1024,7 @@ class NotifyingLogger extends DelegatingLogger { ...@@ -1024,6 +1024,7 @@ class NotifyingLogger extends DelegatingLogger {
@required Duration timeout, @required Duration timeout,
String progressId, String progressId,
bool multilineOutput = false, bool multilineOutput = false,
bool includeTiming = true,
int progressIndicatorPadding = kDefaultStatusPadding, int progressIndicatorPadding = kDefaultStatusPadding,
}) { }) {
assert(timeout != null); assert(timeout != null);
...@@ -1152,6 +1153,7 @@ class AppRunLogger extends DelegatingLogger { ...@@ -1152,6 +1153,7 @@ class AppRunLogger extends DelegatingLogger {
@required Duration timeout, @required Duration timeout,
String progressId, String progressId,
bool multilineOutput = false, bool multilineOutput = false,
bool includeTiming = true,
int progressIndicatorPadding = kDefaultStatusPadding, int progressIndicatorPadding = kDefaultStatusPadding,
}) { }) {
final int id = _nextProgressId++; final int id = _nextProgressId++;
......
...@@ -357,7 +357,6 @@ Future<T> runInContext<T>( ...@@ -357,7 +357,6 @@ Future<T> runInContext<T>(
processManager: globals.processManager, processManager: globals.processManager,
platform: globals.platform, platform: globals.platform,
fileSystem: globals.fs, fileSystem: globals.fs,
terminal: globals.terminal,
usage: globals.flutterUsage, usage: globals.flutterUsage,
), ),
}, },
......
...@@ -308,10 +308,7 @@ class Doctor { ...@@ -308,10 +308,7 @@ class Doctor {
for (final ValidatorTask validatorTask in startValidatorTasks()) { for (final ValidatorTask validatorTask in startValidatorTasks()) {
final DoctorValidator validator = validatorTask.validator; final DoctorValidator validator = validatorTask.validator;
final Status status = Status.withSpinner( final Status status = _logger.startSpinner();
stopwatch: Stopwatch(),
terminal: globals.terminal,
);
ValidationResult result; ValidationResult result;
try { try {
result = await validatorTask.result; result = await validatorTask.result;
......
...@@ -246,7 +246,6 @@ class XcodeProjectInterpreter { ...@@ -246,7 +246,6 @@ class XcodeProjectInterpreter {
@required ProcessManager processManager, @required ProcessManager processManager,
@required Logger logger, @required Logger logger,
@required FileSystem fileSystem, @required FileSystem fileSystem,
@required Terminal terminal,
@required Usage usage, @required Usage usage,
}) { }) {
return XcodeProjectInterpreter._( return XcodeProjectInterpreter._(
...@@ -254,7 +253,6 @@ class XcodeProjectInterpreter { ...@@ -254,7 +253,6 @@ class XcodeProjectInterpreter {
processManager: processManager, processManager: processManager,
logger: logger, logger: logger,
fileSystem: fileSystem, fileSystem: fileSystem,
terminal: terminal,
usage: usage, usage: usage,
); );
} }
...@@ -264,14 +262,12 @@ class XcodeProjectInterpreter { ...@@ -264,14 +262,12 @@ class XcodeProjectInterpreter {
@required ProcessManager processManager, @required ProcessManager processManager,
@required Logger logger, @required Logger logger,
@required FileSystem fileSystem, @required FileSystem fileSystem,
@required Terminal terminal,
@required Usage usage, @required Usage usage,
int majorVersion, int majorVersion,
int minorVersion, int minorVersion,
int patchVersion, int patchVersion,
}) : _platform = platform, }) : _platform = platform,
_fileSystem = fileSystem, _fileSystem = fileSystem,
_terminal = terminal,
_logger = logger, _logger = logger,
_processUtils = ProcessUtils(logger: logger, processManager: processManager), _processUtils = ProcessUtils(logger: logger, processManager: processManager),
_operatingSystemUtils = OperatingSystemUtils( _operatingSystemUtils = OperatingSystemUtils(
...@@ -307,7 +303,6 @@ class XcodeProjectInterpreter { ...@@ -307,7 +303,6 @@ class XcodeProjectInterpreter {
processManager: processManager, processManager: processManager,
usage: TestUsage(), usage: TestUsage(),
logger: BufferLogger.test(), logger: BufferLogger.test(),
terminal: Terminal.test(),
majorVersion: majorVersion, majorVersion: majorVersion,
minorVersion: minorVersion, minorVersion: minorVersion,
patchVersion: patchVersion, patchVersion: patchVersion,
...@@ -318,7 +313,6 @@ class XcodeProjectInterpreter { ...@@ -318,7 +313,6 @@ class XcodeProjectInterpreter {
final FileSystem _fileSystem; final FileSystem _fileSystem;
final ProcessUtils _processUtils; final ProcessUtils _processUtils;
final OperatingSystemUtils _operatingSystemUtils; final OperatingSystemUtils _operatingSystemUtils;
final Terminal _terminal;
final Logger _logger; final Logger _logger;
final Usage _usage; final Usage _usage;
...@@ -415,10 +409,7 @@ class XcodeProjectInterpreter { ...@@ -415,10 +409,7 @@ class XcodeProjectInterpreter {
String scheme, String scheme,
Duration timeout = const Duration(minutes: 1), Duration timeout = const Duration(minutes: 1),
}) async { }) async {
final Status status = Status.withSpinner( final Status status = _logger.startSpinner();
stopwatch: Stopwatch(),
terminal: _terminal,
);
final List<String> showBuildSettingsCommand = <String>[ final List<String> showBuildSettingsCommand = <String>[
...xcrunCommand(), ...xcrunCommand(),
'xcodebuild', 'xcodebuild',
......
...@@ -760,6 +760,7 @@ class StreamLogger extends Logger { ...@@ -760,6 +760,7 @@ class StreamLogger extends Logger {
@required Duration timeout, @required Duration timeout,
String progressId, String progressId,
bool multilineOutput = false, bool multilineOutput = false,
bool includeTiming = true,
int progressIndicatorPadding = kDefaultStatusPadding, int progressIndicatorPadding = kDefaultStatusPadding,
}) { }) {
_log('[progress] $message'); _log('[progress] $message');
...@@ -768,6 +769,14 @@ class StreamLogger extends Logger { ...@@ -768,6 +769,14 @@ class StreamLogger extends Logger {
)..start(); )..start();
} }
@override
Status startSpinner({ VoidCallback onFinish }) {
return SilentStatus(
stopwatch: Stopwatch(),
onFinish: onFinish,
)..start();
}
bool _interrupt = false; bool _interrupt = false;
void interrupt() { void interrupt() {
......
...@@ -18,7 +18,6 @@ import 'package:meta/meta.dart'; ...@@ -18,7 +18,6 @@ import 'package:meta/meta.dart';
import 'package:test/fake.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart';
import '../../src/fakes.dart'; import '../../src/fakes.dart';
final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false); final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
...@@ -659,7 +658,7 @@ void main() { ...@@ -659,7 +658,7 @@ void main() {
expect(lines[3], equals('0123456789' * 3)); expect(lines[3], equals('0123456789' * 3));
}); });
testUsingContext('AppRunLogger writes plain text statuses when no app is active', () async { testWithoutContext('AppRunLogger writes plain text statuses when no app is active', () async {
final BufferLogger buffer = BufferLogger.test(); final BufferLogger buffer = BufferLogger.test();
final AppRunLogger logger = AppRunLogger(parent: buffer); final AppRunLogger logger = AppRunLogger(parent: buffer);
......
...@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/base/file_system.dart'; ...@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/ios/xcodeproj.dart'; import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
...@@ -41,7 +40,6 @@ void main() { ...@@ -41,7 +40,6 @@ void main() {
fileSystem: fileSystem, fileSystem: fileSystem,
platform: platform, platform: platform,
processManager: processManager, processManager: processManager,
terminal: Terminal.test(),
usage: null, usage: null,
); );
}); });
...@@ -101,7 +99,6 @@ void main() { ...@@ -101,7 +99,6 @@ void main() {
fileSystem: fileSystem, fileSystem: fileSystem,
platform: platform, platform: platform,
processManager: fakeProcessManager, processManager: fakeProcessManager,
terminal: Terminal.test(),
usage: null, usage: null,
); );
}); });
...@@ -218,7 +215,6 @@ void main() { ...@@ -218,7 +215,6 @@ void main() {
fileSystem: fileSystem, fileSystem: fileSystem,
platform: platform, platform: platform,
processManager: fakeProcessManager, processManager: fakeProcessManager,
terminal: Terminal.test(),
usage: TestUsage(), usage: TestUsage(),
); );
fileSystem.file(xcodebuild).deleteSync(); fileSystem.file(xcodebuild).deleteSync();
...@@ -422,7 +418,6 @@ void main() { ...@@ -422,7 +418,6 @@ void main() {
fileSystem: fileSystem, fileSystem: fileSystem,
platform: platform, platform: platform,
processManager: fakeProcessManager, processManager: fakeProcessManager,
terminal: Terminal.test(),
usage: TestUsage(), usage: TestUsage(),
); );
...@@ -449,7 +444,6 @@ void main() { ...@@ -449,7 +444,6 @@ void main() {
fileSystem: fileSystem, fileSystem: fileSystem,
platform: platform, platform: platform,
processManager: fakeProcessManager, processManager: fakeProcessManager,
terminal: Terminal.test(),
usage: TestUsage(), usage: TestUsage(),
); );
......
...@@ -628,7 +628,7 @@ class FakeStatusLogger extends DelegatingLogger { ...@@ -628,7 +628,7 @@ class FakeStatusLogger extends DelegatingLogger {
Status status; Status status;
@override @override
Status startProgress(String message, {Duration timeout, String progressId, bool multilineOutput = false, int progressIndicatorPadding = kDefaultStatusPadding}) { Status startProgress(String message, {Duration timeout, String progressId, bool multilineOutput = false, bool includeTiming = true, int progressIndicatorPadding = kDefaultStatusPadding}) {
return status; return status;
} }
} }
......
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