From 0177042b1c516ab39d26c03698a20b47f31201c6 Mon Sep 17 00:00:00 2001 From: Michael Thomsen Date: Mon, 22 Aug 2022 21:11:33 +0200 Subject: [PATCH] [imitation_game] Migrate imitation game to null safety (#2483) --- packages/imitation_game/CHANGELOG.md | 4 +++ .../imitation_game/bin/imitation_game.dart | 35 ++++++++++--------- packages/imitation_game/pubspec.yaml | 8 ++--- packages/imitation_game/run.sh | 2 +- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/imitation_game/CHANGELOG.md b/packages/imitation_game/CHANGELOG.md index d775621173..9a0072ccd8 100644 --- a/packages/imitation_game/CHANGELOG.md +++ b/packages/imitation_game/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.0.2 + +* Migrate to null safety. + ## 0.0.1 * Initial version (TBD). diff --git a/packages/imitation_game/bin/imitation_game.dart b/packages/imitation_game/bin/imitation_game.dart index 587546c823..175a20d2c6 100644 --- a/packages/imitation_game/bin/imitation_game.dart +++ b/packages/imitation_game/bin/imitation_game.dart @@ -8,14 +8,14 @@ import 'dart:io'; import 'package:args/args.dart'; import 'package:imitation_game/readme_template.dart'; -import 'package:mustache/mustache.dart'; +import 'package:mustache_template/mustache.dart'; // ignore_for_file: avoid_as const int _port = 4040; -Future _findIpAddress() async { - String result; +Future _findIpAddress() async { + String? result; final List interfaces = await NetworkInterface.list(); for (final NetworkInterface interface in interfaces) { for (final InternetAddress address in interface.addresses) { @@ -41,7 +41,7 @@ Future _getFlutterVersion() async { } typedef FileFilter = bool Function(FileSystemEntity); -Future> findFiles(Directory dir, {FileFilter where}) { +Future> findFiles(Directory dir, {FileFilter? where}) { final List files = []; final Completer> completer = Completer>(); @@ -68,7 +68,8 @@ Future _makeMarkdownOutput(Map results) async { /// have their values from [newResults] and the symmetric difference will have the /// value from their respective sets. Map _integrate( - {Map oldResults, Map newResults}) { + {required Map oldResults, + required Map newResults}) { final Map result = Map.from(oldResults); newResults.forEach((String test, dynamic testValue) { final Map testMap = testValue as Map; @@ -90,7 +91,7 @@ Map _integrate( } class _Script { - _Script({this.path}); + _Script({required this.path}); String path; } @@ -98,15 +99,15 @@ class _ScriptRunner { _ScriptRunner(this._scriptPaths); final List _scriptPaths; - Process _currentProcess; - StreamSubscription _stdoutSubscription; - StreamSubscription _stderrSubscription; + Process? _currentProcess; + late StreamSubscription _stdoutSubscription; + late StreamSubscription _stderrSubscription; - Future<_Script> runNext() async { + Future<_Script?> runNext() async { if (_currentProcess != null) { _stdoutSubscription.cancel(); _stderrSubscription.cancel(); - _currentProcess.kill(); + _currentProcess!.kill(); _currentProcess = null; } @@ -119,11 +120,11 @@ class _ScriptRunner { _currentProcess = await Process.start('sh', [path]); // TODO(gaaclarke): Implement a timeout. _stdoutSubscription = - _currentProcess.stdout.transform(utf8.decoder).listen((String data) { + _currentProcess!.stdout.transform(utf8.decoder).listen((String data) { print(data); }); _stderrSubscription = - _currentProcess.stderr.transform(utf8.decoder).listen((String data) { + _currentProcess!.stderr.transform(utf8.decoder).listen((String data) { print(data); }); return _Script(path: path); @@ -160,8 +161,8 @@ Map _map2List(Map map, List names) { class _ImitationGame { final Map results = {}; - _ScriptRunner _scriptRunner; - _Script _currentScript; + late _ScriptRunner _scriptRunner; + _Script? _currentScript; Future start(List iosScripts) { _scriptRunner = _ScriptRunner(iosScripts); @@ -170,7 +171,7 @@ class _ImitationGame { Future handleResult(Map data) { final String test = data['test']; - final String platform = data['platform']; + final String? platform = data['platform']; results.putIfAbsent(test, () => {}); results[test].putIfAbsent(platform, () => {}); data['results'].forEach((String k, dynamic v) { @@ -204,7 +205,7 @@ Future main(List args) async { InternetAddress.anyIPv4, _port, ); - final String ipaddress = await _findIpAddress(); + final String? ipaddress = await _findIpAddress(); print('Listening on $ipaddress:${server.port}'); for (final FileSystemEntity entity in await findFiles(Directory.current, diff --git a/packages/imitation_game/pubspec.yaml b/packages/imitation_game/pubspec.yaml index 725fc1516b..38ae95c3f7 100644 --- a/packages/imitation_game/pubspec.yaml +++ b/packages/imitation_game/pubspec.yaml @@ -2,11 +2,11 @@ name: imitation_game description: Testing framework for comparing multiple frameworks' performance. repository: https://github.com/flutter/packages/tree/main/packages/imitation_game issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+imitation_game%22 -version: 0.0.1 +version: 0.0.2 environment: - sdk: ">=2.7.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: - args: ^1.6.0 - mustache: ^1.1.1 + args: ^2.3.1 + mustache_template: ^2.0.0 diff --git a/packages/imitation_game/run.sh b/packages/imitation_game/run.sh index fb3ee33c70..ce82fcd5d8 100755 --- a/packages/imitation_game/run.sh +++ b/packages/imitation_game/run.sh @@ -6,4 +6,4 @@ if [ $# -eq 0 ]; then echo "usage: run.sh [android | ios]" fi -pub run imitation_game --platform=$1 +dart run imitation_game --platform=$1