Unverified Commit e3b9223a authored by Liam Appelbe's avatar Liam Appelbe Committed by GitHub

Null safety migration of packages/flutter_tools/bin (#110706)

* Migrate packages/flutter_tools/bin

* Fix NPE

* Fix test

* Fix test

* Fix l10n optionalParameters

* Fix ChromeTab nullability

* Fix another type cast error

* Fix another cast error

* Fix another cast error (copied from #110711)

* Fix NPE

* Fix another NPE

* Assert that testDirectory is not null
parent a34e6b07
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:flutter_tools/executable.dart' as executable; import 'package:flutter_tools/executable.dart' as executable;
void main(List<String> args) { void main(List<String> args) {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:args/args.dart'; import 'package:args/args.dart';
import 'package:flutter_tools/src/asset.dart' hide defaultManifestPath; import 'package:flutter_tools/src/asset.dart' hide defaultManifestPath;
import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/common.dart';
...@@ -63,10 +61,10 @@ Future<void> run(List<String> args) async { ...@@ -63,10 +61,10 @@ Future<void> run(List<String> args) async {
Cache.flutterRoot = globals.platform.environment['FLUTTER_ROOT']; Cache.flutterRoot = globals.platform.environment['FLUTTER_ROOT'];
final String assetDir = argResults[_kOptionAsset] as String; final String assetDir = argResults[_kOptionAsset] as String;
final AssetBundle assets = await buildAssets( final AssetBundle? assets = await buildAssets(
manifestPath: argResults[_kOptionManifest] as String ?? defaultManifestPath, manifestPath: argResults[_kOptionManifest] as String? ?? defaultManifestPath,
assetDirPath: assetDir, assetDirPath: assetDir,
packagesPath: argResults[_kOptionPackages] as String, packagesPath: argResults[_kOptionPackages] as String?,
targetPlatform: TargetPlatform.fuchsia_arm64 // This is not arch specific. targetPlatform: TargetPlatform.fuchsia_arm64 // This is not arch specific.
); );
...@@ -84,8 +82,9 @@ Future<void> run(List<String> args) async { ...@@ -84,8 +82,9 @@ Future<void> run(List<String> args) async {
final String outputMan = argResults[_kOptionAssetManifestOut] as String; final String outputMan = argResults[_kOptionAssetManifestOut] as String;
await writeFuchsiaManifest(assets, argResults[_kOptionAsset] as String, outputMan, argResults[_kOptionComponentName] as String); await writeFuchsiaManifest(assets, argResults[_kOptionAsset] as String, outputMan, argResults[_kOptionComponentName] as String);
if (argResults.options.contains(_kOptionDepfile)) { final String? depfilePath = argResults[_kOptionDepfile] as String?;
await writeDepfile(assets, outputMan, argResults[_kOptionDepfile] as String); if (depfilePath != null) {
await writeDepfile(assets, outputMan, depfilePath);
} }
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'dart:convert' show json; import 'dart:convert' show json;
import 'dart:math' as math; import 'dart:math' as math;
...@@ -57,7 +55,6 @@ Future<void> run(List<String> args) async { ...@@ -57,7 +55,6 @@ Future<void> run(List<String> args) async {
..addOption(_kOptionTests, help: 'Path to json file that maps Dart test files to precompiled dill files') ..addOption(_kOptionTests, help: 'Path to json file that maps Dart test files to precompiled dill files')
..addOption(_kOptionCoverageDirectory, help: 'The path to the directory that will have coverage collected') ..addOption(_kOptionCoverageDirectory, help: 'The path to the directory that will have coverage collected')
..addFlag(_kOptionCoverage, ..addFlag(_kOptionCoverage,
defaultsTo: false,
negatable: false, negatable: false,
help: 'Whether to collect coverage information.', help: 'Whether to collect coverage information.',
) )
...@@ -84,7 +81,7 @@ Future<void> run(List<String> args) async { ...@@ -84,7 +81,7 @@ Future<void> run(List<String> args) async {
if (!globals.fs.isDirectorySync(sdkRootSrc.path)) { if (!globals.fs.isDirectorySync(sdkRootSrc.path)) {
throwToolExit('Cannot find SDK files at ${sdkRootSrc.path}'); throwToolExit('Cannot find SDK files at ${sdkRootSrc.path}');
} }
Directory coverageDirectory; Directory? coverageDirectory;
final String coverageDirectoryPath = argResults[_kOptionCoverageDirectory] as String; final String coverageDirectoryPath = argResults[_kOptionCoverageDirectory] as String;
if (coverageDirectoryPath != null) { if (coverageDirectoryPath != null) {
if (!globals.fs.isDirectorySync(coverageDirectoryPath)) { if (!globals.fs.isDirectorySync(coverageDirectoryPath)) {
...@@ -95,13 +92,14 @@ Future<void> run(List<String> args) async { ...@@ -95,13 +92,14 @@ Future<void> run(List<String> args) async {
// Put the tester shell where runTests expects it. // Put the tester shell where runTests expects it.
// TODO(garymm): Switch to a Fuchsia-specific Artifacts impl. // TODO(garymm): Switch to a Fuchsia-specific Artifacts impl.
final Artifacts artifacts = globals.artifacts!;
final Link testerDestLink = final Link testerDestLink =
globals.fs.link(globals.artifacts.getArtifactPath(Artifact.flutterTester)); globals.fs.link(artifacts.getArtifactPath(Artifact.flutterTester));
testerDestLink.parent.createSync(recursive: true); testerDestLink.parent.createSync(recursive: true);
testerDestLink.createSync(globals.fs.path.absolute(shellPath)); testerDestLink.createSync(globals.fs.path.absolute(shellPath));
final Directory sdkRootDest = final Directory sdkRootDest =
globals.fs.directory(globals.artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath)); globals.fs.directory(artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath));
sdkRootDest.createSync(recursive: true); sdkRootDest.createSync(recursive: true);
for (final FileSystemEntity artifact in sdkRootSrc.listSync()) { for (final FileSystemEntity artifact in sdkRootSrc.listSync()) {
globals.fs.link(sdkRootDest.childFile(artifact.basename).path).createSync(artifact.path); globals.fs.link(sdkRootDest.childFile(artifact.basename).path).createSync(artifact.path);
...@@ -109,12 +107,12 @@ Future<void> run(List<String> args) async { ...@@ -109,12 +107,12 @@ Future<void> run(List<String> args) async {
// TODO(tvolkert): Remove once flutter_tester no longer looks for this. // TODO(tvolkert): Remove once flutter_tester no longer looks for this.
globals.fs.link(sdkRootDest.childFile('platform.dill').path).createSync('platform_strong.dill'); globals.fs.link(sdkRootDest.childFile('platform.dill').path).createSync('platform_strong.dill');
Directory testDirectory; Directory? testDirectory;
CoverageCollector collector; CoverageCollector? collector;
if (argResults['coverage'] as bool) { if (argResults['coverage'] as bool) {
// If we have a specified coverage directory then accept all libraries by // If we have a specified coverage directory then accept all libraries by
// setting libraryNames to null. // setting libraryNames to null.
final Set<String> libraryNames = coverageDirectory != null ? null : final Set<String>? libraryNames = coverageDirectory != null ? null :
<String>{FlutterProject.current().manifest.appName}; <String>{FlutterProject.current().manifest.appName};
final String packagesPath = globals.fs.path.normalize(globals.fs.path.absolute(argResults[_kOptionPackages] as String)); final String packagesPath = globals.fs.path.normalize(globals.fs.path.absolute(argResults[_kOptionPackages] as String));
collector = CoverageCollector( collector = CoverageCollector(
...@@ -162,7 +160,7 @@ Future<void> run(List<String> args) async { ...@@ -162,7 +160,7 @@ Future<void> run(List<String> args) async {
// package (i.e. contains lib/ and test/ sub-dirs). In some cases, // package (i.e. contains lib/ and test/ sub-dirs). In some cases,
// test files may appear to be in the root directory. // test files may appear to be in the root directory.
if (coverageDirectory == null) { if (coverageDirectory == null) {
globals.fs.currentDirectory = testDirectory.parent; globals.fs.currentDirectory = testDirectory!.parent;
} else { } else {
globals.fs.currentDirectory = testDirectory; globals.fs.currentDirectory = testDirectory;
} }
......
...@@ -521,9 +521,9 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -521,9 +521,9 @@ class ResidentWebRunner extends ResidentRunner {
}) async { }) async {
if (_chromiumLauncher != null) { if (_chromiumLauncher != null) {
final Chromium chrome = await _chromiumLauncher!.connectedInstance; final Chromium chrome = await _chromiumLauncher!.connectedInstance;
final ChromeTab chromeTab = await (chrome.chromeConnection.getTab((ChromeTab chromeTab) { final ChromeTab? chromeTab = await chrome.chromeConnection.getTab((ChromeTab chromeTab) {
return !chromeTab.url.startsWith('chrome-extension'); return !chromeTab.url.startsWith('chrome-extension');
}, retryFor: const Duration(seconds: 5)) as FutureOr<ChromeTab>); }, retryFor: const Duration(seconds: 5));
if (chromeTab == null) { if (chromeTab == null) {
throwToolExit('Failed to connect to Chrome instance.'); throwToolExit('Failed to connect to Chrome instance.');
} }
......
...@@ -261,14 +261,14 @@ class Placeholder { ...@@ -261,14 +261,14 @@ class Placeholder {
if (value == null) { if (value == null) {
return <OptionalParameter>[]; return <OptionalParameter>[];
} }
if (value is! Map<String, Object>) { if (value is! Map<String, Object?>) {
throw L10nException( throw L10nException(
'The "optionalParameters" value of the "$name" placeholder in message ' 'The "optionalParameters" value of the "$name" placeholder in message '
'$resourceId is not a properly formatted Map. Ensure that it is a map ' '$resourceId is not a properly formatted Map. Ensure that it is a map '
'with keys that are strings.' 'with keys that are strings.'
); );
} }
final Map<String, Object> optionalParameterMap = value; final Map<String, Object?> optionalParameterMap = value;
return optionalParameterMap.keys.map<OptionalParameter>((String parameterName) { return optionalParameterMap.keys.map<OptionalParameter>((String parameterName) {
return OptionalParameter(parameterName, optionalParameterMap[parameterName]!); return OptionalParameter(parameterName, optionalParameterMap[parameterName]!);
}).toList(); }).toList();
......
...@@ -348,7 +348,7 @@ StreamChannel<String> _webSocketToStreamChannel(WebSocket webSocket) { ...@@ -348,7 +348,7 @@ StreamChannel<String> _webSocketToStreamChannel(WebSocket webSocket) {
.pipe(webSocket); .pipe(webSocket);
webSocket webSocket
// We're only communicating with string encoded JSON. // We're only communicating with string encoded JSON.
.map<String?>((dynamic message) => message as String?) .map<String>((dynamic message) => message as String)
.pipe(controller.local.sink); .pipe(controller.local.sink);
return controller.foreign; return controller.foreign;
......
...@@ -344,7 +344,7 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -344,7 +344,7 @@ class FlutterWebPlatform extends PlatformPlugin {
Future<shelf.Response> _goldenFileHandler(shelf.Request request) async { Future<shelf.Response> _goldenFileHandler(shelf.Request request) async {
if (request.url.path.contains('flutter_goldens')) { if (request.url.path.contains('flutter_goldens')) {
final Map<String, Object> body = json.decode(await request.readAsString()) as Map<String, Object>; final Map<String, Object?> body = json.decode(await request.readAsString()) as Map<String, Object?>;
final Uri goldenKey = Uri.parse(body['key']! as String); final Uri goldenKey = Uri.parse(body['key']! as String);
final Uri testUri = Uri.parse(body['testUri']! as String); final Uri testUri = Uri.parse(body['testUri']! as String);
final num width = body['width']! as num; final num width = body['width']! as num;
...@@ -352,9 +352,9 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -352,9 +352,9 @@ class FlutterWebPlatform extends PlatformPlugin {
Uint8List bytes; Uint8List bytes;
try { try {
final ChromeTab chromeTab = await (_browserManager!._browser.chromeConnection.getTab((ChromeTab tab) { final ChromeTab chromeTab = (await _browserManager!._browser.chromeConnection.getTab((ChromeTab tab) {
return tab.url.contains(_browserManager!._browser.url!); return tab.url.contains(_browserManager!._browser.url!);
}) as FutureOr<ChromeTab>); }))!;
final WipConnection connection = await chromeTab.connect(); final WipConnection connection = await chromeTab.connect();
final WipResponse response = await connection.sendCommand('Page.captureScreenshot', <String, Object>{ final WipResponse response = await connection.sendCommand('Page.captureScreenshot', <String, Object>{
// Clip the screenshot to include only the element. // Clip the screenshot to include only the element.
......
...@@ -158,7 +158,7 @@ abstract class ChromiumDevice extends Device { ...@@ -158,7 +158,7 @@ abstract class ChromiumDevice extends Device {
@override @override
Future<bool> stopApp( Future<bool> stopApp(
ApplicationPackage app, { ApplicationPackage? app, {
String? userIdentifier, String? userIdentifier,
}) async { }) async {
await _chrome?.close(); await _chrome?.close();
...@@ -479,7 +479,7 @@ class WebServerDevice extends Device { ...@@ -479,7 +479,7 @@ class WebServerDevice extends Device {
@override @override
Future<bool> stopApp( Future<bool> stopApp(
ApplicationPackage app, { ApplicationPackage? app, {
String? userIdentifier, String? userIdentifier,
}) async { }) async {
return true; return true;
......
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