Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -45,7 +45,7 @@ bool _isTaskRegistered = false;
///
/// If no `processManager` is provided, a default [LocalProcessManager] is created
/// for the task.
Future<TaskResult> task(TaskFunction task, { ProcessManager? processManager }) async {
Future<TaskResult> task(TaskFunction task, {ProcessManager? processManager}) async {
if (_isTaskRegistered) {
throw StateError('A task is already registered');
}
@@ -66,18 +66,16 @@ Future<TaskResult> task(TaskFunction task, { ProcessManager? processManager }) a
class _TaskRunner {
_TaskRunner(this.task, this.processManager) {
final String successResponse = json.encode(
const <String, String>{
'result': 'success',
},
);
final String successResponse = json.encode(const <String, String>{'result': 'success'});
registerExtension('ext.cocoonRunTask',
(String method, Map<String, String> parameters) async {
final Duration? taskTimeout = parameters.containsKey('timeoutInMinutes')
? Duration(minutes: int.parse(parameters['timeoutInMinutes']!))
: null;
final bool runFlutterConfig = parameters['runFlutterConfig'] != 'false'; // used by tests to avoid changing the configuration
registerExtension('ext.cocoonRunTask', (String method, Map<String, String> parameters) async {
final Duration? taskTimeout =
parameters.containsKey('timeoutInMinutes')
? Duration(minutes: int.parse(parameters['timeoutInMinutes']!))
: null;
final bool runFlutterConfig =
parameters['runFlutterConfig'] !=
'false'; // used by tests to avoid changing the configuration
final bool runProcessCleanup = parameters['runProcessCleanup'] != 'false';
final String? localEngine = parameters['localEngine'];
final String? localEngineHost = parameters['localEngineHost'];
@@ -89,22 +87,25 @@ class _TaskRunner {
localEngineHost: localEngineHost,
);
const Duration taskResultReceivedTimeout = Duration(seconds: 30);
_taskResultReceivedTimeout = Timer(
taskResultReceivedTimeout,
() {
logger.severe('Task runner did not acknowledge task results in $taskResultReceivedTimeout.');
_closeKeepAlivePort();
exitCode = 1;
}
);
_taskResultReceivedTimeout = Timer(taskResultReceivedTimeout, () {
logger.severe(
'Task runner did not acknowledge task results in $taskResultReceivedTimeout.',
);
_closeKeepAlivePort();
exitCode = 1;
});
return ServiceExtensionResponse.result(json.encode(result.toJson()));
});
registerExtension('ext.cocoonRunnerReady',
(String method, Map<String, String> parameters) async {
registerExtension('ext.cocoonRunnerReady', (
String method,
Map<String, String> parameters,
) async {
return ServiceExtensionResponse.result(successResponse);
});
registerExtension('ext.cocoonTaskResultReceived',
(String method, Map<String, String> parameters) async {
registerExtension('ext.cocoonTaskResultReceived', (
String method,
Map<String, String> parameters,
) async {
_closeKeepAlivePort();
return ServiceExtensionResponse.result(successResponse);
});
@@ -134,7 +135,8 @@ class _TaskRunner {
/// Signals that this task runner finished running the task.
Future<TaskResult> get whenDone => _completer.future;
Future<TaskResult> run(Duration? taskTimeout, {
Future<TaskResult> run(
Duration? taskTimeout, {
bool runFlutterConfig = true,
bool runProcessCleanup = true,
required String? localEngine,
@@ -151,7 +153,9 @@ class _TaskRunner {
processName: 'dart$exe',
processManager: processManager,
);
final Set<RunningProcessInfo> allProcesses = await getRunningProcesses(processManager: processManager);
final Set<RunningProcessInfo> allProcesses = await getRunningProcesses(
processManager: processManager,
);
beforeRunningDartInstances.forEach(print);
for (final RunningProcessInfo info in allProcesses) {
if (info.commandLine.contains('iproxy')) {
@@ -162,14 +166,18 @@ class _TaskRunner {
if (runFlutterConfig) {
print('Enabling configs for macOS and Linux...');
final int configResult = await exec(path.join(flutterDirectory.path, 'bin', 'flutter'), <String>[
'config',
'-v',
'--enable-macos-desktop',
'--enable-linux-desktop',
if (localEngine != null) ...<String>['--local-engine', localEngine],
if (localEngineHost != null) ...<String>['--local-engine-host', localEngineHost],
], canFail: true);
final int configResult = await exec(
path.join(flutterDirectory.path, 'bin', 'flutter'),
<String>[
'config',
'-v',
'--enable-macos-desktop',
'--enable-linux-desktop',
if (localEngine != null) ...<String>['--local-engine', localEngine],
if (localEngineHost != null) ...<String>['--local-engine-host', localEngineHost],
],
canFail: true,
);
if (configResult != 0) {
print('Failed to enable configuration, tasks may not run.');
}
@@ -184,7 +192,8 @@ class _TaskRunner {
IOSink? sink;
try {
if (device != null && device.canStreamLogs && hostAgent.dumpDirectory != null) {
sink = File(path.join(hostAgent.dumpDirectory!.path, '${device.deviceId}.log')).openWrite();
sink =
File(path.join(hostAgent.dumpDirectory!.path, '${device.deviceId}.log')).openWrite();
await device.startLoggingToSink(sink);
}
@@ -295,23 +304,26 @@ class _TaskRunner {
Future<TaskResult> _performTask() {
final Completer<TaskResult> completer = Completer<TaskResult>();
Chain.capture(() async {
completer.complete(await task());
}, onError: (dynamic taskError, Chain taskErrorStack) {
final String message = 'Task failed: $taskError';
stderr
..writeln(message)
..writeln('\nStack trace:')
..writeln(taskErrorStack.terse);
// IMPORTANT: We're completing the future _successfully_ but with a value
// that indicates a task failure. This is intentional. At this point we
// are catching errors coming from arbitrary (and untrustworthy) task
// code. Our goal is to convert the failure into a readable message.
// Propagating it further is not useful.
if (!completer.isCompleted) {
completer.complete(TaskResult.failure(message));
}
});
Chain.capture(
() async {
completer.complete(await task());
},
onError: (dynamic taskError, Chain taskErrorStack) {
final String message = 'Task failed: $taskError';
stderr
..writeln(message)
..writeln('\nStack trace:')
..writeln(taskErrorStack.terse);
// IMPORTANT: We're completing the future _successfully_ but with a value
// that indicates a task failure. This is intentional. At this point we
// are catching errors coming from arbitrary (and untrustworthy) task
// code. Our goal is to convert the failure into a readable message.
// Propagating it further is not useful.
if (!completer.isCompleted) {
completer.complete(TaskResult.failure(message));
}
},
);
return completer.future;
}
}