Unverified Commit 8e765c7f authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] put system clock on globals (#57447)

parent 49ad67cc
......@@ -2,11 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'context.dart';
/// The current system clock instance.
SystemClock get systemClock => context.get<SystemClock>();
/// A class for making time based operations testable.
class SystemClock {
/// A const constructor to allow subclasses to be const.
......
......@@ -9,7 +9,6 @@ import 'package:args/command_runner.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/time.dart';
import '../base/utils.dart';
import '../build_info.dart';
import '../cache.dart';
......@@ -428,7 +427,7 @@ class RunCommand extends RunCommandBase {
} on Exception catch (error) {
throwToolExit(error.toString());
}
final DateTime appStartedTime = systemClock.now();
final DateTime appStartedTime = globals.systemClock.now();
final int result = await app.runner.waitForAppToFinish();
if (result != 0) {
throwToolExit(null, exitCode: result);
......@@ -553,7 +552,7 @@ class RunCommand extends RunCommandBase {
// This callback can't throw.
unawaited(appStartedTimeRecorder.future.then<void>(
(_) {
appStartedTime = systemClock.now();
appStartedTime = globals.systemClock.now();
if (stayResident) {
TerminalHandler(runner)
..setupTerminal()
......
......@@ -54,13 +54,14 @@ Future<vm_service.VmService> _kDefaultFuchsiaIsolateDiscoveryConnector(Uri uri)
/// Read the log for a particular device.
class _FuchsiaLogReader extends DeviceLogReader {
_FuchsiaLogReader(this._device, [this._app]);
_FuchsiaLogReader(this._device, this._systemClock, [this._app]);
// \S matches non-whitespace characters.
static final RegExp _flutterLogOutput = RegExp(r'INFO: \S+\(flutter\): ');
final FuchsiaDevice _device;
final ApplicationPackage _app;
final SystemClock _systemClock;
@override
String get name => _device.name;
......@@ -79,7 +80,7 @@ class _FuchsiaLogReader extends DeviceLogReader {
}
// Get the starting time of the log processor to filter logs from before
// the process attached.
final DateTime startTime = systemClock.now();
final DateTime startTime = _systemClock.now();
// Determine if line comes from flutter, and optionally whether it matches
// the correct fuchsia module.
final RegExp matchRegExp = _app == null
......@@ -534,7 +535,7 @@ class FuchsiaDevice extends Device {
bool includePastLogs = false,
}) {
assert(!includePastLogs, 'Past log reading not supported on Fuchsia.');
return _logReader ??= _FuchsiaLogReader(this, app);
return _logReader ??= _FuchsiaLogReader(this, globals.systemClock, app);
}
_FuchsiaLogReader _logReader;
......
......@@ -20,6 +20,7 @@ import 'base/platform.dart';
import 'base/signals.dart';
import 'base/template.dart';
import 'base/terminal.dart';
import 'base/time.dart';
import 'base/user_messages.dart';
import 'build_system/build_system.dart';
import 'cache.dart';
......@@ -107,6 +108,9 @@ BotDetector get botDetector => context.get<BotDetector>() ?? _defaultBotDetector
Future<bool> get isRunningOnBot => botDetector.isRunningOnBot;
/// The current system clock instance.
SystemClock get systemClock => context.get<SystemClock>();
/// Display an error level message to the user. Commands should use this if they
/// fail in some way.
///
......
......@@ -11,7 +11,6 @@ import 'package:yaml/yaml.dart';
import 'android/gradle.dart';
import 'base/common.dart';
import 'base/file_system.dart';
import 'base/time.dart';
import 'convert.dart';
import 'dart/package_map.dart';
import 'features.dart';
......@@ -423,7 +422,7 @@ bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
/// should be removed once migration is complete.
/// https://github.com/flutter/flutter/issues/48918
result['dependencyGraph'] = _createPluginLegacyDependencyGraph(plugins);
result['date_created'] = systemClock.now().toString();
result['date_created'] = globals.systemClock.now().toString();
result['version'] = globals.flutterVersion.frameworkVersion;
// Only notify if the plugins list has changed. [date_created] will always be different,
......
......@@ -306,7 +306,7 @@ class _DefaultUsage implements Usage {
final Map<String, String> paramsWithLocalTime = <String, String>{
...?parameters,
cdKey(CustomDimensions.localTime): formatDateTime(systemClock.now()),
cdKey(CustomDimensions.localTime): formatDateTime(globals.systemClock.now()),
};
_analytics.sendScreenView(command, parameters: paramsWithLocalTime);
}
......@@ -325,7 +325,7 @@ class _DefaultUsage implements Usage {
final Map<String, String> paramsWithLocalTime = <String, String>{
...?parameters,
cdKey(CustomDimensions.localTime): formatDateTime(systemClock.now()),
cdKey(CustomDimensions.localTime): formatDateTime(globals.systemClock.now()),
};
_analytics.sendEvent(
......
......@@ -15,7 +15,6 @@ import '../base/common.dart';
import '../base/context.dart';
import '../base/io.dart' as io;
import '../base/signals.dart';
import '../base/time.dart';
import '../base/user_messages.dart';
import '../base/utils.dart';
import '../build_info.dart';
......@@ -680,7 +679,7 @@ abstract class FlutterCommand extends Command<void> {
/// so that this method can record and report the overall time to analytics.
@override
Future<void> run() {
final DateTime startTime = systemClock.now();
final DateTime startTime = globals.systemClock.now();
return context.run<void>(
name: 'command',
......@@ -694,7 +693,7 @@ abstract class FlutterCommand extends Command<void> {
try {
commandResult = await verifyThenRunCommand(commandPath);
} finally {
final DateTime endTime = systemClock.now();
final DateTime endTime = globals.systemClock.now();
globals.printTrace(userMessages.flutterElapsedTime(name, getElapsedAsMilliseconds(endTime.difference(startTime))));
_sendPostUsage(commandPath, commandResult, startTime, endTime);
}
......@@ -709,7 +708,7 @@ abstract class FlutterCommand extends Command<void> {
commandPath,
const FlutterCommandResult(ExitStatus.killed),
startTime,
systemClock.now(),
globals.systemClock.now(),
);
};
globals.signals.addHandler(io.ProcessSignal.SIGTERM, handler);
......
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