From c4a2a3e92d9b076cbcb7b76e7017410ddbc3bb5f Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 2 Jun 2021 18:41:12 -0700 Subject: [PATCH] Migrate project.dart and all dependencies to null safety (#83817) --- .../bin/fuchsia_asset_builder.dart | 1 + .../lib/src/android/android_builder.dart | 28 ++- .../flutter_tools/lib/src/android/gradle.dart | 119 ++++++------ .../lib/src/android/gradle_errors.dart | 113 ++++++----- .../lib/src/android/gradle_utils.dart | 42 ++--- packages/flutter_tools/lib/src/bundle.dart | 178 +----------------- .../flutter_tools/lib/src/bundle_builder.dart | 171 +++++++++++++++++ packages/flutter_tools/lib/src/cmake.dart | 10 +- .../lib/src/commands/build_bundle.dart | 1 + .../flutter_tools/lib/src/commands/test.dart | 2 +- .../lib/src/custom_devices/custom_device.dart | 1 + .../lib/src/flutter_plugins.dart | 162 ++++++++-------- .../lib/src/fuchsia/fuchsia_build.dart | 2 +- packages/flutter_tools/lib/src/globals.dart | 16 -- .../lib/src/globals_null_migrated.dart | 15 ++ .../lib/src/ios/xcode_build_settings.dart | 50 +++-- .../lib/src/isolated/devfs_web.dart | 2 +- .../lib/src/macos/cocoapods.dart | 35 ++-- packages/flutter_tools/lib/src/project.dart | 133 +++++++------ .../lib/src/tester/flutter_tester.dart | 1 + .../permeable/build_bundle_test.dart | 1 + .../android/gradle_find_bundle_test.dart | 4 +- .../android/gradle_utils_test.dart | 8 +- .../general.shard/android_plugin_test.dart | 3 - .../test/general.shard/asset_bundle_test.dart | 2 +- .../general.shard/bundle_builder_test.dart | 2 +- .../custom_devices/custom_device_test.dart | 1 + .../test/src/android_common.dart | 26 ++- 28 files changed, 557 insertions(+), 572 deletions(-) create mode 100644 packages/flutter_tools/lib/src/bundle_builder.dart diff --git a/packages/flutter_tools/bin/fuchsia_asset_builder.dart b/packages/flutter_tools/bin/fuchsia_asset_builder.dart index 574daa0a8bd..1884823bf25 100644 --- a/packages/flutter_tools/bin/fuchsia_asset_builder.dart +++ b/packages/flutter_tools/bin/fuchsia_asset_builder.dart @@ -12,6 +12,7 @@ import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_system/depfile.dart'; import 'package:flutter_tools/src/bundle.dart'; +import 'package:flutter_tools/src/bundle_builder.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/context_runner.dart'; import 'package:flutter_tools/src/devfs.dart'; diff --git a/packages/flutter_tools/lib/src/android/android_builder.dart b/packages/flutter_tools/lib/src/android/android_builder.dart index dfac543e1f9..0e9a9b8327a 100644 --- a/packages/flutter_tools/lib/src/android/android_builder.dart +++ b/packages/flutter_tools/lib/src/android/android_builder.dart @@ -2,16 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - -import 'package:meta/meta.dart'; - import '../base/context.dart'; import '../build_info.dart'; import '../project.dart'; /// The builder in the current context. -AndroidBuilder get androidBuilder { +AndroidBuilder? get androidBuilder { return context.get(); } @@ -19,25 +15,25 @@ abstract class AndroidBuilder { const AndroidBuilder(); /// Builds an AAR artifact. Future buildAar({ - @required FlutterProject project, - @required Set androidBuildInfo, - @required String target, - @required String outputDirectoryPath, - @required String buildNumber, + required FlutterProject project, + required Set androidBuildInfo, + required String target, + String? outputDirectoryPath, + required String buildNumber, }); /// Builds an APK artifact. Future buildApk({ - @required FlutterProject project, - @required AndroidBuildInfo androidBuildInfo, - @required String target, + required FlutterProject project, + required AndroidBuildInfo androidBuildInfo, + required String target, }); /// Builds an App Bundle artifact. Future buildAab({ - @required FlutterProject project, - @required AndroidBuildInfo androidBuildInfo, - @required String target, + required FlutterProject project, + required AndroidBuildInfo androidBuildInfo, + required String target, bool validateDeferredComponents = true, bool deferredComponentsEnabled = false, }); diff --git a/packages/flutter_tools/lib/src/android/gradle.dart b/packages/flutter_tools/lib/src/android/gradle.dart index 43b7a04e6eb..988fd02232a 100644 --- a/packages/flutter_tools/lib/src/android/gradle.dart +++ b/packages/flutter_tools/lib/src/android/gradle.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:crypto/crypto.dart'; import 'package:meta/meta.dart'; import 'package:process/process.dart'; @@ -126,7 +124,7 @@ void createSettingsAarGradle(Directory androidDirectory, Logger logger) { final String newSettingsRelativeFile = fileSystem.path.relative(newSettingsFile.path); final Status status = logger.startProgress('✏️ Creating `$newSettingsRelativeFile`...'); - final String flutterRoot = fileSystem.path.absolute(Cache.flutterRoot); + final String flutterRoot = fileSystem.path.absolute(Cache.flutterRoot!); final File legacySettingsDotGradleFiles = fileSystem.file(fileSystem.path.join(flutterRoot, 'packages','flutter_tools', 'gradle', 'settings.gradle.legacy_versions')); assert(legacySettingsDotGradleFiles.existsSync()); @@ -161,13 +159,13 @@ void createSettingsAarGradle(Directory androidDirectory, Logger logger) { /// An implementation of the [AndroidBuilder] that delegates to gradle. class AndroidGradleBuilder implements AndroidBuilder { AndroidGradleBuilder({ - @required Logger logger, - @required ProcessManager processManager, - @required FileSystem fileSystem, - @required Artifacts artifacts, - @required Usage usage, - @required GradleUtils gradleUtils, - @required Platform platform, + required Logger logger, + required ProcessManager processManager, + required FileSystem fileSystem, + required Artifacts artifacts, + required Usage usage, + required GradleUtils gradleUtils, + required Platform platform, }) : _logger = logger, _fileSystem = fileSystem, _artifacts = artifacts, @@ -187,11 +185,11 @@ class AndroidGradleBuilder implements AndroidBuilder { /// Builds the AAR and POM files for the current Flutter module or plugin. @override Future buildAar({ - @required FlutterProject project, - @required Set androidBuildInfo, - @required String target, - String outputDirectoryPath, - @required String buildNumber, + required FlutterProject project, + required Set androidBuildInfo, + required String target, + String? outputDirectoryPath, + required String buildNumber, }) async { Directory outputDirectory = _fileSystem.directory(outputDirectoryPath ?? project.android.buildDirectory); @@ -224,9 +222,9 @@ class AndroidGradleBuilder implements AndroidBuilder { /// Builds the APK. @override Future buildApk({ - @required FlutterProject project, - @required AndroidBuildInfo androidBuildInfo, - @required String target, + required FlutterProject project, + required AndroidBuildInfo androidBuildInfo, + required String target, }) async { await buildGradleApp( project: project, @@ -240,9 +238,9 @@ class AndroidGradleBuilder implements AndroidBuilder { /// Builds the App Bundle. @override Future buildAab({ - @required FlutterProject project, - @required AndroidBuildInfo androidBuildInfo, - @required String target, + required FlutterProject project, + required AndroidBuildInfo androidBuildInfo, + required String target, bool validateDeferredComponents = true, bool deferredComponentsEnabled = false, }) async { @@ -269,11 +267,11 @@ class AndroidGradleBuilder implements AndroidBuilder { /// * [retries] is the max number of build retries in case one of the [GradleHandledError] handler /// returns [GradleBuildStatus.retry] or [GradleBuildStatus.retryWithAarPlugins]. Future buildGradleApp({ - @required FlutterProject project, - @required AndroidBuildInfo androidBuildInfo, - @required String target, - @required bool isBuildingBundle, - @required List localGradleErrors, + required FlutterProject project, + required AndroidBuildInfo androidBuildInfo, + required String target, + required bool isBuildingBundle, + required List localGradleErrors, bool shouldBuildPluginAsAar = false, bool validateDeferredComponents = true, bool deferredComponentsEnabled = false, @@ -361,7 +359,7 @@ class AndroidGradleBuilder implements AndroidBuilder { if (target != null) { command.add('-Ptarget=$target'); } - final List deferredComponents = project.manifest.deferredComponents; + final List? deferredComponents = project.manifest.deferredComponents; if (deferredComponents != null) { if (deferredComponentsEnabled) { command.add('-Pdeferred-components=true'); @@ -406,9 +404,9 @@ class AndroidGradleBuilder implements AndroidBuilder { } command.add(assembleTask); - GradleHandledError detectedGradleError; - String detectedGradleErrorLine; - String consumeLog(String line) { + GradleHandledError? detectedGradleError; + String? detectedGradleErrorLine; + String? consumeLog(String line) { // This message was removed from first-party plugins, // but older plugin versions still display this message. if (androidXPluginWarningRegex.hasMatch(line)) { @@ -441,7 +439,7 @@ class AndroidGradleBuilder implements AndroidBuilder { allowReentrantFlutter: true, environment: { if (javaPath != null) - 'JAVA_HOME': javaPath, + 'JAVA_HOME': javaPath!, }, mapFunction: consumeLog, ); @@ -466,15 +464,15 @@ class AndroidGradleBuilder implements AndroidBuilder { exitCode: exitCode, ); } else { - final GradleBuildStatus status = await detectedGradleError.handler( - line: detectedGradleErrorLine, + final GradleBuildStatus status = await detectedGradleError!.handler( + line: detectedGradleErrorLine!, project: project, usesAndroidX: usesAndroidX, shouldBuildPluginAsAar: shouldBuildPluginAsAar, ); if (retries >= 1) { - final String successEventLabel = 'gradle-${detectedGradleError.eventLabel}-success'; + final String successEventLabel = 'gradle-${detectedGradleError!.eventLabel}-success'; switch (status) { case GradleBuildStatus.retry: await buildGradleApp( @@ -504,7 +502,7 @@ class AndroidGradleBuilder implements AndroidBuilder { // noop. } } - BuildEvent('gradle-${detectedGradleError.eventLabel}-failure', type: 'gradle', flutterUsage: _usage).send(); + BuildEvent('gradle-${detectedGradleError?.eventLabel}-failure', type: 'gradle', flutterUsage: _usage).send(); throwToolExit( 'Gradle task $assembleTask failed with exit code $exitCode', exitCode: exitCode, @@ -580,7 +578,7 @@ class AndroidGradleBuilder implements AndroidBuilder { .childFile('snapshot.$archName.json'); final File precompilerTrace = _fileSystem.directory(buildInfo.codeSizeDirectory) .childFile('trace.$archName.json'); - final Map output = await sizeAnalyzer.analyzeZipSizeAndAotSnapshot( + final Map output = await sizeAnalyzer.analyzeZipSizeAndAotSnapshot( zipFile: zipFile, aotSnapshot: aotSnapshot, precompilerTrace: precompilerTrace, @@ -616,11 +614,11 @@ class AndroidGradleBuilder implements AndroidBuilder { /// * [outputDir] is the destination of the artifacts, /// * [buildNumber] is the build number of the output aar, Future buildGradleAar({ - @required FlutterProject project, - @required AndroidBuildInfo androidBuildInfo, - @required String target, - @required Directory outputDirectory, - @required String buildNumber, + required FlutterProject project, + required AndroidBuildInfo androidBuildInfo, + required String target, + required Directory outputDirectory, + required String buildNumber, }) async { assert(project != null); assert(target != null); @@ -638,7 +636,7 @@ class AndroidGradleBuilder implements AndroidBuilder { "Running Gradle task '$aarTask'...", ); - final String flutterRoot = _fileSystem.path.absolute(Cache.flutterRoot); + final String flutterRoot = _fileSystem.path.absolute(Cache.flutterRoot!); final String initScript = _fileSystem.path.join( flutterRoot, 'packages', @@ -721,7 +719,7 @@ class AndroidGradleBuilder implements AndroidBuilder { allowReentrantFlutter: true, environment: { if (javaPath != null) - 'JAVA_HOME': javaPath, + 'JAVA_HOME': javaPath!, }, ); } finally { @@ -757,7 +755,7 @@ class AndroidGradleBuilder implements AndroidBuilder { Future buildPluginsAsAar( FlutterProject flutterProject, AndroidBuildInfo androidBuildInfo, { - @required Directory buildDirectory, + required Directory buildDirectory, }) async { final File flutterPluginFile = flutterProject.flutterPluginsFile; if (!flutterPluginFile.existsSync()) { @@ -806,12 +804,12 @@ class AndroidGradleBuilder implements AndroidBuilder { /// Prints how to consume the AAR from a host app. void printHowToConsumeAar({ - @required Set buildModes, - String androidPackage = 'unknown', - @required Directory repoDirectory, - @required Logger logger, - @required FileSystem fileSystem, - String buildNumber, + required Set buildModes, + String? androidPackage = 'unknown', + required Directory repoDirectory, + required Logger logger, + required FileSystem fileSystem, + String? buildNumber, }) { assert(buildModes != null && buildModes.isNotEmpty); assert(repoDirectory != null); @@ -919,7 +917,7 @@ Iterable findApkFilesModule( if (apkFile.existsSync()) { return [apkFile]; } - final String flavor = buildInfo.flavor; + final String? flavor = buildInfo.flavor; if (flavor != null) { // Android Studio Gradle plugin v3 adds flavor to path. apkFile = apkDirectory @@ -954,7 +952,7 @@ Iterable listApkPaths( final String buildType = camelCase(androidBuildInfo.buildInfo.modeName); final List apkPartialName = [ if (androidBuildInfo.buildInfo.flavor?.isNotEmpty ?? false) - androidBuildInfo.buildInfo.lowerCasedFlavor, + androidBuildInfo.buildInfo.lowerCasedFlavor!, '$buildType.apk', ]; if (androidBuildInfo.splitPerAbi) { @@ -1013,15 +1011,14 @@ File findBundleFile(FlutterProject project, BuildInfo buildInfo, Logger logger, logger: logger, usage: usage, ); - return null; } /// Throws a [ToolExit] exception and logs the event. -void _exitWithExpectedFileNotFound({ - @required FlutterProject project, - @required String fileExtension, - @required Logger logger, - @required Usage usage, +Never _exitWithExpectedFileNotFound({ + required FlutterProject project, + required String fileExtension, + required Logger logger, + required Usage usage, }) { assert(project != null); assert(fileExtension != null); @@ -1090,9 +1087,9 @@ String _getLocalArtifactVersion(String pomPath, FileSystem fileSystem) { /// This method generates symlinks in the temp directory to the engine artifacts /// following the convention specified on https://maven.apache.org/pom.html#Repositories Directory _getLocalEngineRepo({ - @required String engineOutPath, - @required AndroidBuildInfo androidBuildInfo, - @required FileSystem fileSystem, + required String engineOutPath, + required AndroidBuildInfo androidBuildInfo, + required FileSystem fileSystem, }) { assert(engineOutPath != null); assert(androidBuildInfo != null); diff --git a/packages/flutter_tools/lib/src/android/gradle_errors.dart b/packages/flutter_tools/lib/src/android/gradle_errors.dart index 2075c391be3..08b85bd71c0 100644 --- a/packages/flutter_tools/lib/src/android/gradle_errors.dart +++ b/packages/flutter_tools/lib/src/android/gradle_errors.dart @@ -2,13 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 import 'package:meta/meta.dart'; import '../base/error_handling_io.dart'; import '../base/file_system.dart'; import '../base/process.dart'; -import '../globals.dart' as globals; +import '../globals_null_migrated.dart' as globals; import '../project.dart'; import '../reporting/reporting.dart'; import 'android_studio.dart'; @@ -18,8 +17,8 @@ typedef GradleErrorTest = bool Function(String); /// A Gradle error handled by the tool. class GradleHandledError { const GradleHandledError({ - @required this.test, - @required this.handler, + required this.test, + required this.handler, this.eventLabel, }); @@ -29,16 +28,16 @@ class GradleHandledError { /// The handler function. final Future Function({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) handler; /// The [BuildEvent] label is named gradle-[eventLabel]. /// If not empty, the build event is logged along with /// additional metadata such as the attempt number. - final String eventLabel; + final String? eventLabel; } /// The status of the Gradle build. @@ -85,10 +84,10 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError( 'Permission denied', ]), handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { globals.printStatus('${globals.logger.terminal.warningMark} Gradle does not have execution permission.', emphasis: true); globals.printStatus( @@ -122,17 +121,17 @@ final GradleHandledError networkErrorHandler = GradleHandledError( 'Gateway Time-out' ]), handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { globals.printError( '${globals.logger.terminal.warningMark} Gradle threw an error while downloading artifacts from the network. ' 'Retrying to download...' ); try { - final String homeDir = globals.platform.environment['HOME']; + final String? homeDir = globals.platform.environment['HOME']; if (homeDir != null) { final Directory directory = globals.fs.directory(globals.fs.path.join(homeDir, '.gradle')); ErrorHandlingFileSystem.deleteIfExists(directory, recursive: true); @@ -152,10 +151,10 @@ final GradleHandledError r8FailureHandler = GradleHandledError( 'com.android.tools.r8', ]), handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { globals.printStatus('${globals.logger.terminal.warningMark} The shrinker may have failed to optimize the Java bytecode.', emphasis: true); globals.printStatus('To disable the shrinker, pass the `--no-shrink` flag to this command.', indent: 4); @@ -191,10 +190,10 @@ final GradleHandledError androidXFailureHandler = GradleHandledError( _androidXFailureRegex.hasMatch(line); }, handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { final bool hasPlugins = project.flutterPluginsFile.existsSync(); if (!hasPlugins) { @@ -259,21 +258,21 @@ final GradleHandledError licenseNotAcceptedHandler = GradleHandledError( 'You have not accepted the license agreements of the following SDK components', ]), handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { const String licenseNotAcceptedMatcher = r'You have not accepted the license agreements of the following SDK components:\s*\[(.+)\]'; final RegExp licenseFailure = RegExp(licenseNotAcceptedMatcher, multiLine: true); assert(licenseFailure != null); - final Match licenseMatch = licenseFailure.firstMatch(line); + final Match? licenseMatch = licenseFailure.firstMatch(line); globals.printStatus( '${globals.logger.terminal.warningMark} Unable to download needed Android SDK components, as the ' 'following licenses have not been accepted:\n' - '${licenseMatch.group(1)}\n\n' + '${licenseMatch?.group(1)}\n\n' 'To resolve this, please run the following command in a Terminal:\n' 'flutter doctor --android-licenses' ); @@ -293,14 +292,14 @@ final GradleHandledError flavorUndefinedHandler = GradleHandledError( return _undefinedTaskPattern.hasMatch(line); }, handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { final RunResult tasksRunResult = await globals.processUtils.run( [ - globals.gradleUtils.getExecutable(project), + globals.gradleUtils!.getExecutable(project), 'app:tasks' , '--all', '--console=auto', @@ -309,15 +308,15 @@ final GradleHandledError flavorUndefinedHandler = GradleHandledError( workingDirectory: project.android.hostAppGradleRoot.path, environment: { if (javaPath != null) - 'JAVA_HOME': javaPath, + 'JAVA_HOME': javaPath!, }, ); // Extract build types and product flavors. final Set variants = {}; for (final String task in tasksRunResult.stdout.split('\n')) { - final Match match = _assembleTaskPattern.matchAsPrefix(task); + final Match? match = _assembleTaskPattern.matchAsPrefix(task); if (match != null) { - final String variant = match.group(1).toLowerCase(); + final String variant = match.group(1)!.toLowerCase(); if (!variant.endsWith('test')) { variants.add(variant); } @@ -366,32 +365,32 @@ final GradleHandledError minSdkVersion = GradleHandledError( return _minSdkVersionPattern.hasMatch(line); }, handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { final File gradleFile = project.directory .childDirectory('android') .childDirectory('app') .childFile('build.gradle'); - final Match minSdkVersionMatch = _minSdkVersionPattern.firstMatch(line); - assert(minSdkVersionMatch.groupCount == 3); + final Match? minSdkVersionMatch = _minSdkVersionPattern.firstMatch(line); + assert(minSdkVersionMatch?.groupCount == 3); final String bold = globals.logger.terminal.bolden( 'Fix this issue by adding the following to the file ${gradleFile.path}:\n' 'android {\n' ' defaultConfig {\n' - ' minSdkVersion ${minSdkVersionMatch.group(2)}\n' + ' minSdkVersion ${minSdkVersionMatch?.group(2)}\n' ' }\n' '}\n' ); globals.printStatus( '\n' - 'The plugin ${minSdkVersionMatch.group(3)} requires a higher Android SDK version.\n' + 'The plugin ${minSdkVersionMatch?.group(3)} requires a higher Android SDK version.\n' '$bold\n' - "Note that your app won't be available to users running Android SDKs below ${minSdkVersionMatch.group(2)}.\n" + "Note that your app won't be available to users running Android SDKs below ${minSdkVersionMatch?.group(2)}.\n" 'Alternatively, try to find a version of this plugin that supports these lower versions of the Android SDK.' ); return GradleBuildStatus.exit; @@ -407,10 +406,10 @@ final GradleHandledError transformInputIssue = GradleHandledError( return line.contains('https://issuetracker.google.com/issues/158753935'); }, handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { final File gradleFile = project.directory .childDirectory('android') @@ -441,10 +440,10 @@ final GradleHandledError lockFileDepMissing = GradleHandledError( return line.contains('which is not part of the dependency lock state'); }, handler: ({ - @required String line, - @required FlutterProject project, - @required bool usesAndroidX, - @required bool shouldBuildPluginAsAar, + required String line, + required FlutterProject project, + required bool usesAndroidX, + required bool shouldBuildPluginAsAar, }) async { final File gradleFile = project.directory .childDirectory('android') diff --git a/packages/flutter_tools/lib/src/android/gradle_utils.dart b/packages/flutter_tools/lib/src/android/gradle_utils.dart index 670505e9df4..9f5d7680ed5 100644 --- a/packages/flutter_tools/lib/src/android/gradle_utils.dart +++ b/packages/flutter_tools/lib/src/android/gradle_utils.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:meta/meta.dart'; import '../base/common.dart'; @@ -29,11 +27,11 @@ final RegExp _androidPluginRegExp = RegExp(r'com\.android\.tools\.build:gradle:( /// or constructing a Gradle project. class GradleUtils { GradleUtils({ - @required Platform platform, - @required Logger logger, - @required FileSystem fileSystem, - @required Cache cache, - @required OperatingSystemUtils operatingSystemUtils, + required Platform platform, + required Logger logger, + required FileSystem fileSystem, + required Cache cache, + required OperatingSystemUtils operatingSystemUtils, }) : _platform = platform, _logger = logger, _cache = cache, @@ -120,22 +118,22 @@ String getGradleVersionForAndroidPlugin(Directory directory, Logger logger) { logger.printTrace("$buildFile doesn't provide an AGP version, assuming AGP version: $_defaultGradleVersion"); return _defaultGradleVersion; } - final String androidPluginVersion = pluginMatches.first.group(1); + final String? androidPluginVersion = pluginMatches.first.group(1); logger.printTrace('$buildFile provides AGP version: $androidPluginVersion'); - return getGradleVersionFor(androidPluginVersion); + return getGradleVersionFor(androidPluginVersion ?? 'unknown'); } /// Returns true if [targetVersion] is within the range [min] and [max] inclusive. bool _isWithinVersionRange( String targetVersion, { - @required String min, - @required String max, + required String min, + required String max, }) { assert(min != null); assert(max != null); - final Version parsedTargetVersion = Version.parse(targetVersion); - final Version minVersion = Version.parse(min); - final Version maxVersion = Version.parse(max); + final Version? parsedTargetVersion = Version.parse(targetVersion); + final Version? minVersion = Version.parse(min); + final Version? maxVersion = Version.parse(max); return minVersion != null && maxVersion != null && parsedTargetVersion != null && @@ -193,8 +191,8 @@ String getGradleVersionFor(String androidPluginVersion) { /// If [requireAndroidSdk] is true (the default) and no Android SDK is found, /// this will fail with a [ToolExit]. void updateLocalProperties({ - @required FlutterProject project, - BuildInfo buildInfo, + required FlutterProject project, + BuildInfo? buildInfo, bool requireAndroidSdk = true, }) { if (requireAndroidSdk && globals.androidSdk == null) { @@ -211,7 +209,7 @@ void updateLocalProperties({ changed = true; } - void changeIfNecessary(String key, String value) { + void changeIfNecessary(String key, String? value) { if (settings.values[key] == value) { return; } @@ -223,21 +221,21 @@ void updateLocalProperties({ changed = true; } - final AndroidSdk androidSdk = globals.androidSdk; + final AndroidSdk? androidSdk = globals.androidSdk; if (androidSdk != null) { changeIfNecessary('sdk.dir', globals.fsUtils.escapePath(androidSdk.directory.path)); } - changeIfNecessary('flutter.sdk', globals.fsUtils.escapePath(Cache.flutterRoot)); + changeIfNecessary('flutter.sdk', globals.fsUtils.escapePath(Cache.flutterRoot!)); if (buildInfo != null) { changeIfNecessary('flutter.buildMode', buildInfo.modeName); - final String buildName = validatedBuildNameForPlatform( + final String? buildName = validatedBuildNameForPlatform( TargetPlatform.android_arm, buildInfo.buildName ?? project.manifest.buildName, globals.logger, ); changeIfNecessary('flutter.versionName', buildName); - final String buildNumber = validatedBuildNumberForPlatform( + final String? buildNumber = validatedBuildNumberForPlatform( TargetPlatform.android_arm, buildInfo.buildNumber ?? project.manifest.buildNumber, globals.logger, @@ -255,7 +253,7 @@ void updateLocalProperties({ /// Writes the path to the Android SDK, if known. void writeLocalProperties(File properties) { final SettingsFile settings = SettingsFile(); - final AndroidSdk androidSdk = globals.androidSdk; + final AndroidSdk? androidSdk = globals.androidSdk; if (androidSdk != null) { settings.values['sdk.dir'] = globals.fsUtils.escapePath(androidSdk.directory.path); } diff --git a/packages/flutter_tools/lib/src/bundle.dart b/packages/flutter_tools/lib/src/bundle.dart index 3a8cc5def1d..bde49c5a7db 100644 --- a/packages/flutter_tools/lib/src/bundle.dart +++ b/packages/flutter_tools/lib/src/bundle.dart @@ -2,35 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:convert/convert.dart'; import 'package:crypto/crypto.dart'; -import 'package:meta/meta.dart'; -import 'package:pool/pool.dart'; -import 'asset.dart'; -import 'base/common.dart'; import 'base/config.dart'; import 'base/file_system.dart'; -import 'base/logger.dart'; import 'build_info.dart'; -import 'build_system/build_system.dart'; -import 'build_system/depfile.dart'; -import 'build_system/targets/common.dart'; -import 'cache.dart'; import 'convert.dart'; -import 'devfs.dart'; import 'globals_null_migrated.dart' as globals; -import 'project.dart'; String get defaultMainPath => globals.fs.path.join('lib', 'main.dart'); -const String defaultAssetBasePath = '.'; const String defaultManifestPath = 'pubspec.yaml'; String get defaultDepfilePath => globals.fs.path.join(getBuildDirectory(), 'snapshot_blob.bin.d'); String getDefaultApplicationKernelPath({ - @required bool trackWidgetCreation, + required bool trackWidgetCreation, }) { return getKernelPathForTransformerOptions( globals.fs.path.join(getBuildDirectory(), 'app.dill'), @@ -39,15 +25,15 @@ String getDefaultApplicationKernelPath({ } String getDefaultCachedKernelPath({ - @required bool trackWidgetCreation, - @required List dartDefines, - @required List extraFrontEndOptions, - FileSystem fileSystem, - Config config, + required bool trackWidgetCreation, + required List dartDefines, + List extraFrontEndOptions = const [], + FileSystem? fileSystem, + Config? config, }) { final StringBuffer buffer = StringBuffer(); buffer.writeAll(dartDefines); - buffer.writeAll(extraFrontEndOptions ?? []); + buffer.writeAll(extraFrontEndOptions); String buildPrefix = ''; if (buffer.isNotEmpty) { final String output = buffer.toString(); @@ -65,7 +51,7 @@ String getDefaultCachedKernelPath({ String getKernelPathForTransformerOptions( String path, { - @required bool trackWidgetCreation, + required bool trackWidgetCreation, }) { if (trackWidgetCreation) { path += '.track.dill'; @@ -74,151 +60,3 @@ String getKernelPathForTransformerOptions( } const String defaultPrivateKeyPath = 'privatekey.der'; - -/// Provides a `build` method that builds the bundle. -class BundleBuilder { - /// Builds the bundle for the given target platform. - /// - /// The default `mainPath` is `lib/main.dart`. - /// The default `manifestPath` is `pubspec.yaml` - Future build({ - @required TargetPlatform platform, - @required BuildInfo buildInfo, - FlutterProject project, - String mainPath, - String manifestPath = defaultManifestPath, - String applicationKernelFilePath, - String depfilePath, - String assetDirPath, - @visibleForTesting BuildSystem buildSystem - }) async { - project ??= FlutterProject.current(); - mainPath ??= defaultMainPath; - depfilePath ??= defaultDepfilePath; - assetDirPath ??= getAssetBuildDirectory(); - buildSystem ??= globals.buildSystem; - - // If the precompiled flag was not passed, force us into debug mode. - final Environment environment = Environment( - projectDir: project.directory, - outputDir: globals.fs.directory(assetDirPath), - buildDir: project.dartTool.childDirectory('flutter_build'), - cacheDir: globals.cache.getRoot(), - flutterRootDir: globals.fs.directory(Cache.flutterRoot), - engineVersion: globals.artifacts.isLocalEngine - ? null - : globals.flutterVersion.engineRevision, - defines: { - // used by the KernelSnapshot target - kTargetPlatform: getNameForTargetPlatform(platform), - kTargetFile: mainPath, - kDeferredComponents: 'false', - ...buildInfo.toBuildSystemEnvironment(), - }, - artifacts: globals.artifacts, - fileSystem: globals.fs, - logger: globals.logger, - processManager: globals.processManager, - platform: globals.platform, - generateDartPluginRegistry: true, - ); - final Target target = buildInfo.mode == BuildMode.debug - ? const CopyFlutterBundle() - : const ReleaseCopyFlutterBundle(); - final BuildResult result = await buildSystem.build(target, environment); - - if (!result.success) { - for (final ExceptionMeasurement measurement in result.exceptions.values) { - globals.printError('Target ${measurement.target} failed: ${measurement.exception}', - stackTrace: measurement.fatal - ? measurement.stackTrace - : null, - ); - } - throwToolExit('Failed to build bundle.'); - } - if (depfilePath != null) { - final Depfile depfile = Depfile(result.inputFiles, result.outputFiles); - final File outputDepfile = globals.fs.file(depfilePath); - if (!outputDepfile.parent.existsSync()) { - outputDepfile.parent.createSync(recursive: true); - } - final DepfileService depfileService = DepfileService( - fileSystem: globals.fs, - logger: globals.logger, - ); - depfileService.writeToFile(depfile, outputDepfile); - } - - // Work around for flutter_tester placing kernel artifacts in odd places. - if (applicationKernelFilePath != null) { - final File outputDill = globals.fs.directory(assetDirPath).childFile('kernel_blob.bin'); - if (outputDill.existsSync()) { - outputDill.copySync(applicationKernelFilePath); - } - } - return; - } -} - -Future buildAssets({ - String manifestPath, - String assetDirPath, - @required String packagesPath, - TargetPlatform targetPlatform, -}) async { - assetDirPath ??= getAssetBuildDirectory(); - packagesPath ??= globals.fs.path.absolute(packagesPath); - - // Build the asset bundle. - final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle(); - final int result = await assetBundle.build( - manifestPath: manifestPath, - assetDirPath: assetDirPath, - packagesPath: packagesPath, - targetPlatform: targetPlatform, - ); - if (result != 0) { - return null; - } - - return assetBundle; -} - -Future writeBundle( - Directory bundleDir, - Map assetEntries, - { Logger loggerOverride } -) async { - loggerOverride ??= globals.logger; - if (bundleDir.existsSync()) { - try { - bundleDir.deleteSync(recursive: true); - } on FileSystemException catch (err) { - loggerOverride.printError( - 'Failed to clean up asset directory ${bundleDir.path}: $err\n' - 'To clean build artifacts, use the command "flutter clean".' - ); - } - } - bundleDir.createSync(recursive: true); - - // Limit number of open files to avoid running out of file descriptors. - final Pool pool = Pool(64); - await Future.wait( - assetEntries.entries.map>((MapEntry entry) async { - final PoolResource resource = await pool.request(); - try { - // This will result in strange looking files, for example files with `/` - // on Windows or files that end up getting URI encoded such as `#.ext` - // to `%23.ext`. However, we have to keep it this way since the - // platform channels in the framework will URI encode these values, - // and the native APIs will look for files this way. - final File file = globals.fs.file(globals.fs.path.join(bundleDir.path, entry.key)); - file.parent.createSync(recursive: true); - await file.writeAsBytes(await entry.value.contentsAsBytes()); - } finally { - resource.release(); - } - })); -} diff --git a/packages/flutter_tools/lib/src/bundle_builder.dart b/packages/flutter_tools/lib/src/bundle_builder.dart new file mode 100644 index 00000000000..86a7fa83a8e --- /dev/null +++ b/packages/flutter_tools/lib/src/bundle_builder.dart @@ -0,0 +1,171 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// @dart = 2.8 + +import 'package:meta/meta.dart'; +import 'package:pool/pool.dart'; + +import 'asset.dart' hide defaultManifestPath; +import 'base/common.dart'; +import 'base/file_system.dart'; +import 'base/logger.dart'; +import 'build_info.dart'; +import 'build_system/build_system.dart'; +import 'build_system/depfile.dart'; +import 'build_system/targets/common.dart'; +import 'bundle.dart'; +import 'cache.dart'; +import 'devfs.dart'; +import 'globals_null_migrated.dart' as globals; +import 'project.dart'; + + +/// Provides a `build` method that builds the bundle. +class BundleBuilder { + /// Builds the bundle for the given target platform. + /// + /// The default `mainPath` is `lib/main.dart`. + /// The default `manifestPath` is `pubspec.yaml` + Future build({ + @required TargetPlatform platform, + @required BuildInfo buildInfo, + FlutterProject project, + String mainPath, + String manifestPath = defaultManifestPath, + String applicationKernelFilePath, + String depfilePath, + String assetDirPath, + @visibleForTesting BuildSystem buildSystem + }) async { + project ??= FlutterProject.current(); + mainPath ??= defaultMainPath; + depfilePath ??= defaultDepfilePath; + assetDirPath ??= getAssetBuildDirectory(); + buildSystem ??= globals.buildSystem; + + // If the precompiled flag was not passed, force us into debug mode. + final Environment environment = Environment( + projectDir: project.directory, + outputDir: globals.fs.directory(assetDirPath), + buildDir: project.dartTool.childDirectory('flutter_build'), + cacheDir: globals.cache.getRoot(), + flutterRootDir: globals.fs.directory(Cache.flutterRoot), + engineVersion: globals.artifacts.isLocalEngine + ? null + : globals.flutterVersion.engineRevision, + defines: { + // used by the KernelSnapshot target + kTargetPlatform: getNameForTargetPlatform(platform), + kTargetFile: mainPath, + kDeferredComponents: 'false', + ...buildInfo.toBuildSystemEnvironment(), + }, + artifacts: globals.artifacts, + fileSystem: globals.fs, + logger: globals.logger, + processManager: globals.processManager, + platform: globals.platform, + generateDartPluginRegistry: true, + ); + final Target target = buildInfo.mode == BuildMode.debug + ? const CopyFlutterBundle() + : const ReleaseCopyFlutterBundle(); + final BuildResult result = await buildSystem.build(target, environment); + + if (!result.success) { + for (final ExceptionMeasurement measurement in result.exceptions.values) { + globals.printError('Target ${measurement.target} failed: ${measurement.exception}', + stackTrace: measurement.fatal + ? measurement.stackTrace + : null, + ); + } + throwToolExit('Failed to build bundle.'); + } + if (depfilePath != null) { + final Depfile depfile = Depfile(result.inputFiles, result.outputFiles); + final File outputDepfile = globals.fs.file(depfilePath); + if (!outputDepfile.parent.existsSync()) { + outputDepfile.parent.createSync(recursive: true); + } + final DepfileService depfileService = DepfileService( + fileSystem: globals.fs, + logger: globals.logger, + ); + depfileService.writeToFile(depfile, outputDepfile); + } + + // Work around for flutter_tester placing kernel artifacts in odd places. + if (applicationKernelFilePath != null) { + final File outputDill = globals.fs.directory(assetDirPath).childFile('kernel_blob.bin'); + if (outputDill.existsSync()) { + outputDill.copySync(applicationKernelFilePath); + } + } + return; + } +} + +Future buildAssets({ + String manifestPath, + String assetDirPath, + @required String packagesPath, + TargetPlatform targetPlatform, +}) async { + assetDirPath ??= getAssetBuildDirectory(); + packagesPath ??= globals.fs.path.absolute(packagesPath); + + // Build the asset bundle. + final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle(); + final int result = await assetBundle.build( + manifestPath: manifestPath, + assetDirPath: assetDirPath, + packagesPath: packagesPath, + targetPlatform: targetPlatform, + ); + if (result != 0) { + return null; + } + + return assetBundle; +} + +Future writeBundle( + Directory bundleDir, + Map assetEntries, + { Logger loggerOverride } +) async { + loggerOverride ??= globals.logger; + if (bundleDir.existsSync()) { + try { + bundleDir.deleteSync(recursive: true); + } on FileSystemException catch (err) { + loggerOverride.printError( + 'Failed to clean up asset directory ${bundleDir.path}: $err\n' + 'To clean build artifacts, use the command "flutter clean".' + ); + } + } + bundleDir.createSync(recursive: true); + + // Limit number of open files to avoid running out of file descriptors. + final Pool pool = Pool(64); + await Future.wait( + assetEntries.entries.map>((MapEntry entry) async { + final PoolResource resource = await pool.request(); + try { + // This will result in strange looking files, for example files with `/` + // on Windows or files that end up getting URI encoded such as `#.ext` + // to `%23.ext`. However, we have to keep it this way since the + // platform channels in the framework will URI encode these values, + // and the native APIs will look for files this way. + final File file = globals.fs.file(globals.fs.path.join(bundleDir.path, entry.key)); + file.parent.createSync(recursive: true); + await file.writeAsBytes(await entry.value.contentsAsBytes()); + } finally { + resource.release(); + } + })); +} diff --git a/packages/flutter_tools/lib/src/cmake.dart b/packages/flutter_tools/lib/src/cmake.dart index 63b8b7a6891..1ea1846030c 100644 --- a/packages/flutter_tools/lib/src/cmake.dart +++ b/packages/flutter_tools/lib/src/cmake.dart @@ -2,21 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'base/file_system.dart'; import 'project.dart'; /// Extracts the `BINARY_NAME` from a project's CMake file. /// /// Returns `null` if it cannot be found. -String getCmakeExecutableName(CmakeBasedProject project) { +String? getCmakeExecutableName(CmakeBasedProject project) { if (!project.cmakeFile.existsSync()) { return null; } final RegExp nameSetPattern = RegExp(r'^\s*set\(BINARY_NAME\s*"(.*)"\s*\)\s*$'); for (final String line in project.cmakeFile.readAsLinesSync()) { - final RegExpMatch match = nameSetPattern.firstMatch(line); + final RegExpMatch? match = nameSetPattern.firstMatch(line); if (match != null) { return match.group(1); } @@ -27,13 +25,13 @@ String getCmakeExecutableName(CmakeBasedProject project) { /// Extracts the `PACKAGE_GUID` from a project's CMake file. /// /// Returns `null` if it cannot be found. -String getCmakePackageGuid(File cmakeFile) { +String? getCmakePackageGuid(File cmakeFile) { if (!cmakeFile.existsSync()) { return null; } final RegExp nameSetPattern = RegExp(r'^\s*set\(PACKAGE_GUID\s*"(.*)"\s*\)\s*$'); for (final String line in cmakeFile.readAsLinesSync()) { - final RegExpMatch match = nameSetPattern.firstMatch(line); + final RegExpMatch? match = nameSetPattern.firstMatch(line); if (match != null) { return match.group(1); } diff --git a/packages/flutter_tools/lib/src/commands/build_bundle.dart b/packages/flutter_tools/lib/src/commands/build_bundle.dart index f693cfb194c..f8fa4ad0406 100644 --- a/packages/flutter_tools/lib/src/commands/build_bundle.dart +++ b/packages/flutter_tools/lib/src/commands/build_bundle.dart @@ -7,6 +7,7 @@ import '../base/common.dart'; import '../build_info.dart'; import '../bundle.dart'; +import '../bundle_builder.dart'; import '../features.dart'; import '../globals_null_migrated.dart' as globals; import '../project.dart'; diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index 27c04d2e42e..b4ebdd7b5a5 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -12,7 +12,7 @@ import '../asset.dart'; import '../base/common.dart'; import '../base/file_system.dart'; import '../build_info.dart'; -import '../bundle.dart'; +import '../bundle_builder.dart'; import '../devfs.dart'; import '../device.dart'; import '../globals_null_migrated.dart' as globals; diff --git a/packages/flutter_tools/lib/src/custom_devices/custom_device.dart b/packages/flutter_tools/lib/src/custom_devices/custom_device.dart index 31f00b1778f..a8d535e5d1e 100644 --- a/packages/flutter_tools/lib/src/custom_devices/custom_device.dart +++ b/packages/flutter_tools/lib/src/custom_devices/custom_device.dart @@ -18,6 +18,7 @@ import '../base/process.dart'; import '../base/utils.dart'; import '../build_info.dart'; import '../bundle.dart'; +import '../bundle_builder.dart'; import '../convert.dart'; import '../device.dart'; import '../device_port_forwarder.dart'; diff --git a/packages/flutter_tools/lib/src/flutter_plugins.dart b/packages/flutter_tools/lib/src/flutter_plugins.dart index 416aaf8efb6..ee2b35368a1 100644 --- a/packages/flutter_tools/lib/src/flutter_plugins.dart +++ b/packages/flutter_tools/lib/src/flutter_plugins.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:meta/meta.dart'; import 'package:package_config/package_config.dart'; import 'package:path/path.dart' as path; // flutter_ignore: package_path_import @@ -22,25 +20,25 @@ import 'convert.dart'; import 'dart/language_version.dart'; import 'dart/package_map.dart'; import 'features.dart'; -import 'globals.dart' as globals; +import 'globals_null_migrated.dart' as globals; import 'platform_plugins.dart'; import 'plugins.dart'; import 'project.dart'; -void _renderTemplateToFile(String template, dynamic context, File file, TemplateRenderer templateRenderer) { +void _renderTemplateToFile(String template, Object? context, File file, TemplateRenderer templateRenderer) { final String renderedTemplate = templateRenderer .renderString(template, context, htmlEscapeValues: false); file.createSync(recursive: true); file.writeAsStringSync(renderedTemplate); } -Plugin _pluginFromPackage(String name, Uri packageRoot, Set appDependencies, {FileSystem fileSystem}) { +Plugin? _pluginFromPackage(String name, Uri packageRoot, Set appDependencies, {FileSystem? fileSystem}) { final FileSystem fs = fileSystem ?? globals.fs; final File pubspecFile = fs.file(packageRoot.resolve('pubspec.yaml')); if (!pubspecFile.existsSync()) { return null; } - dynamic pubspec; + Object? pubspec; try { pubspec = loadYaml(pubspecFile.readAsStringSync()); @@ -48,20 +46,20 @@ Plugin _pluginFromPackage(String name, Uri packageRoot, Set appDependenc globals.printTrace('Failed to parse plugin manifest for $name: $err'); // Do nothing, potentially not a plugin. } - if (pubspec == null) { + if (pubspec == null || pubspec is! YamlMap) { return null; } - final dynamic flutterConfig = pubspec['flutter']; - if (flutterConfig == null || !(flutterConfig.containsKey('plugin') as bool)) { + final Object? flutterConfig = pubspec['flutter']; + if (flutterConfig == null || flutterConfig is! YamlMap || !flutterConfig.containsKey('plugin')) { return null; } final String packageRootPath = fs.path.fromUri(packageRoot); - final YamlMap dependencies = pubspec['dependencies'] as YamlMap; + final YamlMap? dependencies = pubspec['dependencies'] as YamlMap?; globals.printTrace('Found plugin $name at $packageRootPath'); return Plugin.fromYaml( name, packageRootPath, - flutterConfig['plugin'] as YamlMap, + flutterConfig['plugin'] as YamlMap?, dependencies == null ? [] : [...dependencies.keys.cast()], fileSystem: fs, appDependencies: appDependencies, @@ -82,7 +80,7 @@ Future> findPlugins(FlutterProject project, { bool throwOnError = t ); for (final Package package in packageConfig.packages) { final Uri packageRoot = package.packageUriRoot.resolve('..'); - final Plugin plugin = _pluginFromPackage( + final Plugin? plugin = _pluginFromPackage( package.name, packageRoot, project.manifest.dependencies, @@ -102,15 +100,15 @@ const String _kFlutterPluginsPathKey = 'path'; const String _kFlutterPluginsDependenciesKey = 'dependencies'; /// Filters [plugins] to those supported by [platformKey]. -List> _filterPluginsByPlatform(List plugins, String platformKey) { +List> _filterPluginsByPlatform(List plugins, String platformKey) { final Iterable platformPlugins = plugins.where((Plugin p) { return p.platforms.containsKey(platformKey); }); final Set pluginNames = platformPlugins.map((Plugin plugin) => plugin.name).toSet(); - final List> pluginInfo = >[]; + final List> pluginInfo = >[]; for (final Plugin plugin in platformPlugins) { - pluginInfo.add({ + pluginInfo.add({ _kFlutterPluginsNameKey: plugin.name, _kFlutterPluginsPathKey: globals.fsUtils.escapePath(plugin.path), _kFlutterPluginsDependenciesKey: [...plugin.dependencies.where(pluginNames.contains)], @@ -179,7 +177,7 @@ bool _writeFlutterPluginsList(FlutterProject project, List plugins) { final String windowsKey = project.windows.pluginConfigKey; final String webKey = project.web.pluginConfigKey; - final Map pluginsMap = {}; + final Map pluginsMap = {}; pluginsMap[iosKey] = _filterPluginsByPlatform(plugins, iosKey); pluginsMap[androidKey] = _filterPluginsByPlatform(plugins, androidKey); pluginsMap[macosKey] = _filterPluginsByPlatform(plugins, macosKey); @@ -187,7 +185,7 @@ bool _writeFlutterPluginsList(FlutterProject project, List plugins) { pluginsMap[windowsKey] = _filterPluginsByPlatform(plugins, windowsKey); pluginsMap[webKey] = _filterPluginsByPlatform(plugins, webKey); - final Map result = {}; + final Map result = {}; result['info'] = 'This is a generated file; do not edit or check into version control.'; result[_kFlutterPluginsPluginListKey] = pluginsMap; @@ -200,7 +198,7 @@ bool _writeFlutterPluginsList(FlutterProject project, List plugins) { // Only notify if the plugins list has changed. [date_created] will always be different, // [version] is not relevant for this check. - final String oldPluginsFileStringContent = _readFileContent(pluginsFile); + final String? oldPluginsFileStringContent = _readFileContent(pluginsFile); bool pluginsChanged = true; if (oldPluginsFileStringContent != null) { pluginsChanged = oldPluginsFileStringContent.contains(pluginsMap.toString()); @@ -211,12 +209,12 @@ bool _writeFlutterPluginsList(FlutterProject project, List plugins) { return pluginsChanged; } -List _createPluginLegacyDependencyGraph(List plugins) { - final List directAppDependencies = []; +List _createPluginLegacyDependencyGraph(List plugins) { + final List directAppDependencies = []; final Set pluginNames = plugins.map((Plugin plugin) => plugin.name).toSet(); for (final Plugin plugin in plugins) { - directAppDependencies.add({ + directAppDependencies.add({ 'name': plugin.name, // Extract the plugin dependencies which happen to be plugins. 'dependencies': [...plugin.dependencies.where(pluginNames.contains)], @@ -245,7 +243,7 @@ bool _writeFlutterPluginsListLegacy(FlutterProject project, List plugins for (final Plugin plugin in plugins) { flutterPluginsBuffer.write('${plugin.name}=${globals.fsUtils.escapePath(plugin.path)}\n'); } - final String oldPluginFileContent = _readFileContent(pluginsFile); + final String? oldPluginFileContent = _readFileContent(pluginsFile); final String pluginFileContent = flutterPluginsBuffer.toString(); pluginsFile.writeAsStringSync(pluginFileContent, flush: true); @@ -253,7 +251,7 @@ bool _writeFlutterPluginsListLegacy(FlutterProject project, List plugins } /// Returns the contents of [File] or [null] if that file does not exist. -String _readFileContent(File file) { +String? _readFileContent(File file) { return file.existsSync() ? file.readAsStringSync() : null; } @@ -335,10 +333,10 @@ public final class GeneratedPluginRegistrant { } '''; -List> _extractPlatformMaps(List plugins, String type) { - final List> pluginConfigs = >[]; +List> _extractPlatformMaps(List plugins, String type) { + final List> pluginConfigs = >[]; for (final Plugin p in plugins) { - final PluginPlatform platformPlugin = p.platforms[type]; + final PluginPlatform? platformPlugin = p.platforms[type]; if (platformPlugin != null) { pluginConfigs.add(platformPlugin.toMap()); } @@ -355,10 +353,10 @@ AndroidEmbeddingVersion _getAndroidEmbeddingVersion(FlutterProject project) { } Future _writeAndroidPluginRegistrant(FlutterProject project, List plugins) async { - final List> androidPlugins = + final List> androidPlugins = _extractPlatformMaps(plugins, AndroidPlugin.kConfigKey); - final Map templateContext = { + final Map templateContext = { 'plugins': androidPlugins, 'androidX': isAppUsingAndroidX(project.android.hostAppGradleRoot), }; @@ -382,8 +380,10 @@ Future _writeAndroidPluginRegistrant(FlutterProject project, List templateContext['needsShim'] = false; // If a plugin is using an embedding version older than 2.0 and the app is using 2.0, // then add shim for the old plugins. - for (final Map plugin in androidPlugins) { - if (plugin['supportsEmbeddingV1'] as bool && !(plugin['supportsEmbeddingV2'] as bool)) { + for (final Map plugin in androidPlugins) { + final bool supportsEmbeddingV1 = (plugin['supportsEmbeddingV1'] as bool?) == true; + final bool supportsEmbeddingV2 = (plugin['supportsEmbeddingV2'] as bool?) == true; + if (supportsEmbeddingV1 && !supportsEmbeddingV2) { templateContext['needsShim'] = true; if (project.isModule) { globals.printStatus( @@ -401,8 +401,10 @@ Future _writeAndroidPluginRegistrant(FlutterProject project, List break; case AndroidEmbeddingVersion.v1: default: - for (final Map plugin in androidPlugins) { - if (!(plugin['supportsEmbeddingV1'] as bool) && plugin['supportsEmbeddingV2'] as bool) { + for (final Map plugin in androidPlugins) { + final bool supportsEmbeddingV1 = (plugin['supportsEmbeddingV1'] as bool?) == true; + final bool supportsEmbeddingV2 = (plugin['supportsEmbeddingV2'] as bool?) == true; + if (!supportsEmbeddingV1 && supportsEmbeddingV2) { throwToolExit( 'The plugin `${plugin['name']}` requires your app to be migrated to ' 'the Android embedding v2. Follow the steps on https://flutter.dev/go/android-project-migration ' @@ -711,8 +713,8 @@ void main(List args) { '''; Future _writeIOSPluginRegistrant(FlutterProject project, List plugins) async { - final List> iosPlugins = _extractPlatformMaps(plugins, IOSPlugin.kConfigKey); - final Map context = { + final List> iosPlugins = _extractPlatformMaps(plugins, IOSPlugin.kConfigKey); + final Map context = { 'os': 'ios', 'deploymentTarget': '9.0', 'framework': 'Flutter', @@ -761,8 +763,8 @@ String _cmakeRelativePluginSymlinkDirectoryPath(CmakeBasedProject project) { Future _writeLinuxPluginFiles(FlutterProject project, List plugins) async { final ListnativePlugins = _filterNativePlugins(plugins, LinuxPlugin.kConfigKey); - final List> linuxPlugins = _extractPlatformMaps(nativePlugins, LinuxPlugin.kConfigKey); - final Map context = { + final List> linuxPlugins = _extractPlatformMaps(nativePlugins, LinuxPlugin.kConfigKey); + final Map context = { 'os': 'linux', 'plugins': linuxPlugins, 'pluginsDir': _cmakeRelativePluginSymlinkDirectoryPath(project.linux), @@ -771,7 +773,7 @@ Future _writeLinuxPluginFiles(FlutterProject project, List plugins await _writePluginCmakefile(project.linux.generatedPluginCmakeFile, context, globals.templateRenderer); } -Future _writeLinuxPluginRegistrant(Directory destination, Map templateContext) async { +Future _writeLinuxPluginRegistrant(Directory destination, Map templateContext) async { _renderTemplateToFile( _linuxPluginRegistryHeaderTemplate, templateContext, @@ -786,7 +788,7 @@ Future _writeLinuxPluginRegistrant(Directory destination, Map _writePluginCmakefile(File destinationFile, Map templateContext, TemplateRenderer templateRenderer) async { +Future _writePluginCmakefile(File destinationFile, Map templateContext, TemplateRenderer templateRenderer) async { _renderTemplateToFile( _pluginCmakefileTemplate, templateContext, @@ -797,8 +799,8 @@ Future _writePluginCmakefile(File destinationFile, Map te Future _writeMacOSPluginRegistrant(FlutterProject project, List plugins) async { final ListnativePlugins = _filterNativePlugins(plugins, MacOSPlugin.kConfigKey); - final List> macosPlugins = _extractPlatformMaps(nativePlugins, MacOSPlugin.kConfigKey); - final Map context = { + final List> macosPlugins = _extractPlatformMaps(nativePlugins, MacOSPlugin.kConfigKey); + final Map context = { 'os': 'macos', 'framework': 'FlutterMacOS', 'plugins': macosPlugins, @@ -814,7 +816,7 @@ Future _writeMacOSPluginRegistrant(FlutterProject project, List pl /// Filters out Dart-only plugins, which shouldn't be added to the native generated registrants. List _filterNativePlugins(List plugins, String platformKey) { return plugins.where((Plugin element) { - final PluginPlatform plugin = element.platforms[platformKey]; + final PluginPlatform? plugin = element.platforms[platformKey]; if (plugin == null) { return false; } @@ -830,7 +832,7 @@ List _filterNativePlugins(List plugins, String platformKey) { /// Returns only the plugins with the given platform variant. List _filterPluginsByVariant(List plugins, String platformKey, PluginPlatformVariant variant) { return plugins.where((Plugin element) { - final PluginPlatform platformPlugin = element.platforms[platformKey]; + final PluginPlatform? platformPlugin = element.platforms[platformKey]; if (platformPlugin == null) { return false; } @@ -844,8 +846,8 @@ List _filterPluginsByVariant(List plugins, String platformKey, P Future writeWindowsPluginFiles(FlutterProject project, List plugins, TemplateRenderer templateRenderer) async { final List nativePlugins = _filterNativePlugins(plugins, WindowsPlugin.kConfigKey); final List win32Plugins = _filterPluginsByVariant(nativePlugins, WindowsPlugin.kConfigKey, PluginPlatformVariant.win32); - final List> pluginInfo = _extractPlatformMaps(win32Plugins, WindowsPlugin.kConfigKey); - final Map context = { + final List> pluginInfo = _extractPlatformMaps(win32Plugins, WindowsPlugin.kConfigKey); + final Map context = { 'os': 'windows', 'plugins': pluginInfo, 'pluginsDir': _cmakeRelativePluginSymlinkDirectoryPath(project.windows), @@ -860,8 +862,8 @@ Future writeWindowsPluginFiles(FlutterProject project, List plugin Future writeWindowsUwpPluginFiles(FlutterProject project, List plugins, TemplateRenderer templateRenderer) async { final List nativePlugins = _filterNativePlugins(plugins, WindowsPlugin.kConfigKey); final List uwpPlugins = _filterPluginsByVariant(nativePlugins, WindowsPlugin.kConfigKey, PluginPlatformVariant.winuwp); - final List> pluginInfo = _extractPlatformMaps(uwpPlugins, WindowsPlugin.kConfigKey); - final Map context = { + final List> pluginInfo = _extractPlatformMaps(uwpPlugins, WindowsPlugin.kConfigKey); + final Map context = { 'os': 'windows', 'plugins': pluginInfo, 'pluginsDir': _cmakeRelativePluginSymlinkDirectoryPath(project.windowsUwp), @@ -870,7 +872,7 @@ Future writeWindowsUwpPluginFiles(FlutterProject project, List plu await _writePluginCmakefile(project.windowsUwp.generatedPluginCmakeFile, context, templateRenderer); } -Future _writeCppPluginRegistrant(Directory destination, Map templateContext, TemplateRenderer templateRenderer) async { +Future _writeCppPluginRegistrant(Directory destination, Map templateContext, TemplateRenderer templateRenderer) async { _renderTemplateToFile( _cppPluginRegistryHeaderTemplate, templateContext, @@ -886,13 +888,13 @@ Future _writeCppPluginRegistrant(Directory destination, Map _writeWebPluginRegistrant(FlutterProject project, List plugins) async { - final List> webPlugins = _extractPlatformMaps(plugins, WebPlugin.kConfigKey); - final Map context = { + final List> webPlugins = _extractPlatformMaps(plugins, WebPlugin.kConfigKey); + final Map context = { 'plugins': webPlugins, }; final File pluginFile = project.web.libDirectory.childFile('generated_plugin_registrant.dart'); if (webPlugins.isEmpty) { - return ErrorHandlingFileSystem.deleteIfExists(pluginFile); + ErrorHandlingFileSystem.deleteIfExists(pluginFile); } else { _renderTemplateToFile( _dartPluginRegistryTemplate, @@ -911,34 +913,34 @@ Future _writeWebPluginRegistrant(FlutterProject project, List plug /// /// This uses [project.flutterPluginsDependenciesFile], so it should only be /// run after refreshPluginList has been run since the last plugin change. -void createPluginSymlinks(FlutterProject project, {bool force = false, @visibleForTesting FeatureFlags featureFlagsOverride}) { +void createPluginSymlinks(FlutterProject project, {bool force = false, @visibleForTesting FeatureFlags? featureFlagsOverride}) { final FeatureFlags localFeatureFlags = featureFlagsOverride ?? featureFlags; - Map platformPlugins; - final String pluginFileContent = _readFileContent(project.flutterPluginsDependenciesFile); + Map? platformPlugins; + final String? pluginFileContent = _readFileContent(project.flutterPluginsDependenciesFile); if (pluginFileContent != null) { - final Map pluginInfo = json.decode(pluginFileContent) as Map; - platformPlugins = pluginInfo[_kFlutterPluginsPluginListKey] as Map; + final Map? pluginInfo = json.decode(pluginFileContent) as Map?; + platformPlugins = pluginInfo?[_kFlutterPluginsPluginListKey] as Map?; } - platformPlugins ??= {}; + platformPlugins ??= {}; if (localFeatureFlags.isWindowsEnabled && project.windows.existsSync()) { _createPlatformPluginSymlinks( project.windows.pluginSymlinkDirectory, - platformPlugins[project.windows.pluginConfigKey] as List, + platformPlugins[project.windows.pluginConfigKey] as List?, force: force, ); } if (localFeatureFlags.isLinuxEnabled && project.linux.existsSync()) { _createPlatformPluginSymlinks( project.linux.pluginSymlinkDirectory, - platformPlugins[project.linux.pluginConfigKey] as List, + platformPlugins[project.linux.pluginConfigKey] as List?, force: force, ); } if (localFeatureFlags.isWindowsUwpEnabled && project.windowsUwp.existsSync()) { _createPlatformPluginSymlinks( project.windowsUwp.pluginSymlinkDirectory, - platformPlugins[project.windows.pluginConfigKey] as List, + platformPlugins[project.windows.pluginConfigKey] as List?, force: force, ); } @@ -948,12 +950,12 @@ void createPluginSymlinks(FlutterProject project, {bool force = false, @visibleF /// failure cases. @visibleForTesting void handleSymlinkException(FileSystemException e, { - @required Platform platform, - @required OperatingSystemUtils os, + required Platform platform, + required OperatingSystemUtils os, }) { if (platform.isWindows && (e.osError?.errorCode ?? 0) == 1314) { - final String versionString = RegExp(r'[\d.]+').firstMatch(os.name)?.group(0); - final Version version = Version.parse(versionString); + final String? versionString = RegExp(r'[\d.]+').firstMatch(os.name)?.group(0); + final Version? version = Version.parse(versionString); // Windows 10 14972 is the oldest version that allows creating symlinks // just by enabling developer mode; before that it requires running the // terminal as Administrator. @@ -970,7 +972,7 @@ void handleSymlinkException(FileSystemException e, { /// Creates [symlinkDirectory] containing symlinks to each plugin listed in [platformPlugins]. /// /// If [force] is true, the directory will be created only if missing. -void _createPlatformPluginSymlinks(Directory symlinkDirectory, List platformPlugins, {bool force = false}) { +void _createPlatformPluginSymlinks(Directory symlinkDirectory, List? platformPlugins, {bool force = false}) { if (force && symlinkDirectory.existsSync()) { // Start fresh to avoid stale links. symlinkDirectory.deleteSync(recursive: true); @@ -979,9 +981,9 @@ void _createPlatformPluginSymlinks(Directory symlinkDirectory, List pla if (platformPlugins == null) { return; } - for (final Map pluginInfo in platformPlugins.cast>()) { - final String name = pluginInfo[_kFlutterPluginsNameKey] as String; - final String path = pluginInfo[_kFlutterPluginsPathKey] as String; + for (final Map pluginInfo in platformPlugins.cast>()) { + final String name = pluginInfo[_kFlutterPluginsNameKey]! as String; + final String path = pluginInfo[_kFlutterPluginsPathKey]! as String; final Link link = symlinkDirectory.childLink(name); if (link.existsSync()) { continue; @@ -1015,10 +1017,10 @@ Future refreshPluginsList( if (changed || legacyChanged) { createPluginSymlinks(project, force: true); if (iosPlatform) { - globals.cocoaPods.invalidatePodInstallOutput(project.ios); + globals.cocoaPods?.invalidatePodInstallOutput(project.ios); } if (macOSPlatform) { - globals.cocoaPods.invalidatePodInstallOutput(project.macos); + globals.cocoaPods?.invalidatePodInstallOutput(project.macos); } } } @@ -1064,12 +1066,12 @@ Future injectPlugins( ]; for (final XcodeBasedProject subproject in darwinProjects) { if (plugins.isNotEmpty) { - await globals.cocoaPods.setupPodfile(subproject); + await globals.cocoaPods?.setupPodfile(subproject); } /// The user may have a custom maintained Podfile that they're running `pod install` /// on themselves. else if (subproject.podfile.existsSync() && subproject.podfileLock.existsSync()) { - globals.cocoaPods.addPodsDependencyToFlutterXcconfig(subproject); + globals.cocoaPods?.addPodsDependencyToFlutterXcconfig(subproject); } } } @@ -1119,9 +1121,9 @@ List resolvePlatformImplementation( continue; } // The plugin doesn't implement an interface, verify that it has a default implementation. - final String implementsPackage = plugin.implementsPackage; + final String? implementsPackage = plugin.implementsPackage; if (implementsPackage == null || implementsPackage.isEmpty) { - final String defaultImplementation = plugin.defaultPackagePlatforms[platform]; + final String? defaultImplementation = plugin.defaultPackagePlatforms[platform]; if (defaultImplementation == null) { if (throwOnPluginPubspecError) { globals.printError( @@ -1153,7 +1155,7 @@ List resolvePlatformImplementation( } final String resolutionKey = '$platform/$implementsPackage'; if (directDependencyResolutions.containsKey(resolutionKey)) { - final PluginInterfaceResolution currResolution = directDependencyResolutions[resolutionKey]; + final PluginInterfaceResolution? currResolution = directDependencyResolutions[resolutionKey]; if (currResolution != null && currResolution.plugin.isDirectDependency) { if (plugin.isDirectDependency) { if (throwOnPluginPubspecError) { @@ -1223,14 +1225,14 @@ Future generateMainDartWithPluginRegistrant( final LanguageVersion entrypointVersion = determineLanguageVersion( mainFile, packageConfig.packageOf(mainFile.absolute.uri), - Cache.flutterRoot, + Cache.flutterRoot!, ); - final Map templateContext = { + final Map templateContext = { 'mainEntrypoint': currentMainUri, 'dartLanguageVersion': entrypointVersion.toString(), - LinuxPlugin.kConfigKey: [], - MacOSPlugin.kConfigKey: [], - WindowsPlugin.kConfigKey: [], + LinuxPlugin.kConfigKey: [], + MacOSPlugin.kConfigKey: [], + WindowsPlugin.kConfigKey: [], }; if (resolutions.isEmpty) { try { @@ -1248,7 +1250,7 @@ Future generateMainDartWithPluginRegistrant( } for (final PluginInterfaceResolution resolution in resolutions) { assert(templateContext.containsKey(resolution.platform)); - (templateContext[resolution.platform] as List).add(resolution.toMap()); + (templateContext[resolution.platform] as List?)?.add(resolution.toMap()); } try { _renderTemplateToFile( diff --git a/packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart b/packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart index 663e322e0a4..e92b93642fa 100644 --- a/packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart +++ b/packages/flutter_tools/lib/src/fuchsia/fuchsia_build.dart @@ -13,7 +13,7 @@ import '../base/file_system.dart'; import '../base/logger.dart'; import '../base/utils.dart'; import '../build_info.dart'; -import '../bundle.dart'; +import '../bundle_builder.dart'; import '../convert.dart'; import '../devfs.dart'; import '../globals_null_migrated.dart' as globals; diff --git a/packages/flutter_tools/lib/src/globals.dart b/packages/flutter_tools/lib/src/globals.dart index b168ac95cdf..3806e9c065b 100644 --- a/packages/flutter_tools/lib/src/globals.dart +++ b/packages/flutter_tools/lib/src/globals.dart @@ -4,17 +4,13 @@ // @dart = 2.8 -import 'android/gradle_utils.dart'; import 'base/context.dart'; import 'device.dart'; import 'doctor.dart'; import 'fuchsia/fuchsia_sdk.dart'; -import 'globals_null_migrated.dart' as globals; import 'ios/simulators.dart'; -import 'macos/cocoapods.dart'; import 'macos/cocoapods_validator.dart'; import 'macos/xcdevice.dart'; -import 'project.dart'; import 'reporting/crash_reporting.dart'; import 'runner/local_engine.dart'; @@ -24,22 +20,10 @@ CrashReporter get crashReporter => context.get(); Doctor get doctor => context.get(); DeviceManager get deviceManager => context.get(); -FlutterProjectFactory get projectFactory { - return context.get() ?? FlutterProjectFactory( - logger: globals.logger, - fileSystem: globals.fs, - ); -} - CocoaPodsValidator get cocoapodsValidator => context.get(); LocalEngineLocator get localEngineLocator => context.get(); - -CocoaPods get cocoaPods => context.get(); FuchsiaArtifacts get fuchsiaArtifacts => context.get(); IOSSimulatorUtils get iosSimulatorUtils => context.get(); XCDevice get xcdevice => context.get(); - -/// Gradle utils in the current [AppContext]. -GradleUtils get gradleUtils => context.get(); diff --git a/packages/flutter_tools/lib/src/globals_null_migrated.dart b/packages/flutter_tools/lib/src/globals_null_migrated.dart index 9f9c29614dd..633acfcf3f1 100644 --- a/packages/flutter_tools/lib/src/globals_null_migrated.dart +++ b/packages/flutter_tools/lib/src/globals_null_migrated.dart @@ -6,6 +6,7 @@ import 'package:process/process.dart'; import 'android/android_sdk.dart'; import 'android/android_studio.dart'; +import 'android/gradle_utils.dart'; import 'artifacts.dart'; import 'base/bot_detector.dart'; import 'base/config.dart'; @@ -28,8 +29,10 @@ import 'cache.dart'; import 'ios/ios_workflow.dart'; import 'ios/plist_parser.dart'; import 'ios/xcodeproj.dart'; +import 'macos/cocoapods.dart'; import 'macos/xcode.dart'; import 'persistent_tool_state.dart'; +import 'project.dart'; import 'reporting/reporting.dart'; import 'version.dart'; @@ -196,3 +199,15 @@ LocalFileSystem get localFileSystem => _instance ??= LocalFileSystem( Signals.defaultExitSignals, shutdownHooks, ); + +/// Gradle utils in the current [AppContext]. +GradleUtils? get gradleUtils => context.get(); + +CocoaPods? get cocoaPods => context.get(); + +FlutterProjectFactory get projectFactory { + return context.get() ?? FlutterProjectFactory( + logger: logger, + fileSystem: fs, + ); +} diff --git a/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart b/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart index f35aa8d7bb6..28b0ccc1d05 100644 --- a/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart +++ b/packages/flutter_tools/lib/src/ios/xcode_build_settings.dart @@ -2,10 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - -import 'package:meta/meta.dart'; - import '../artifacts.dart'; import '../base/file_system.dart'; import '../build_info.dart'; @@ -33,11 +29,11 @@ String flutterMacOSFrameworkDir(BuildMode mode, FileSystem fileSystem, /// targetOverride: Optional parameter, if null or unspecified the default value /// from xcode_backend.sh is used 'lib/main.dart'. Future updateGeneratedXcodeProperties({ - @required FlutterProject project, - @required BuildInfo buildInfo, - String targetOverride, + required FlutterProject project, + required BuildInfo buildInfo, + String? targetOverride, bool useMacOSConfig = false, - String buildDirOverride, + String? buildDirOverride, }) async { final List xcodeBuildSettings = _xcodeBuildSettingsLines( project: project, @@ -64,8 +60,8 @@ Future updateGeneratedXcodeProperties({ /// for Xcode targets that need them. /// See [XcodeBasedProject.generatedXcodePropertiesFile]. void _updateGeneratedXcodePropertiesFile({ - @required FlutterProject project, - @required List xcodeBuildSettings, + required FlutterProject project, + required List xcodeBuildSettings, bool useMacOSConfig = false, }) { final StringBuffer localsBuffer = StringBuffer(); @@ -84,8 +80,8 @@ void _updateGeneratedXcodePropertiesFile({ /// as flags for Flutter tools. /// See [XcodeBasedProject.generatedEnvironmentVariableExportScript]. void _updateGeneratedEnvironmentVariablesScript({ - @required FlutterProject project, - @required List xcodeBuildSettings, + required FlutterProject project, + required List xcodeBuildSettings, bool useMacOSConfig = false, }) { final StringBuffer localsBuffer = StringBuffer(); @@ -107,21 +103,21 @@ void _updateGeneratedEnvironmentVariablesScript({ } /// Build name parsed and validated from build info and manifest. Used for CFBundleShortVersionString. -String parsedBuildName({ - @required FlutterManifest manifest, - BuildInfo buildInfo, +String? parsedBuildName({ + required FlutterManifest manifest, + BuildInfo? buildInfo, }) { - final String buildNameToParse = buildInfo?.buildName ?? manifest.buildName; + final String? buildNameToParse = buildInfo?.buildName ?? manifest.buildName; return validatedBuildNameForPlatform(TargetPlatform.ios, buildNameToParse, globals.logger); } /// Build number parsed and validated from build info and manifest. Used for CFBundleVersion. -String parsedBuildNumber({ - @required FlutterManifest manifest, - BuildInfo buildInfo, +String? parsedBuildNumber({ + required FlutterManifest manifest, + BuildInfo? buildInfo, }) { - String buildNumberToParse = buildInfo?.buildNumber ?? manifest.buildNumber; - final String buildNumber = validatedBuildNumberForPlatform( + String? buildNumberToParse = buildInfo?.buildNumber ?? manifest.buildNumber; + final String? buildNumber = validatedBuildNumberForPlatform( TargetPlatform.ios, buildNumberToParse, globals.logger, @@ -141,15 +137,15 @@ String parsedBuildNumber({ /// List of lines of build settings. Example: 'FLUTTER_BUILD_DIR=build' List _xcodeBuildSettingsLines({ - @required FlutterProject project, - @required BuildInfo buildInfo, - String targetOverride, + required FlutterProject project, + required BuildInfo buildInfo, + String? targetOverride, bool useMacOSConfig = false, - String buildDirOverride, + String? buildDirOverride, }) { final List xcodeBuildSettings = []; - final String flutterRoot = globals.fs.path.normalize(Cache.flutterRoot); + final String flutterRoot = globals.fs.path.normalize(Cache.flutterRoot!); xcodeBuildSettings.add('FLUTTER_ROOT=$flutterRoot'); // This holds because requiresProjectRoot is true for this command @@ -173,7 +169,7 @@ List _xcodeBuildSettingsLines({ final String buildNumber = parsedBuildNumber(manifest: project.manifest, buildInfo: buildInfo) ?? '1'; xcodeBuildSettings.add('FLUTTER_BUILD_NUMBER=$buildNumber'); - final Artifacts artifacts = globals.artifacts; + final Artifacts? artifacts = globals.artifacts; if (artifacts is LocalEngineArtifacts) { final LocalEngineArtifacts localEngineArtifacts = artifacts; final String engineOutPath = localEngineArtifacts.engineOutPath; diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index 6cac27f9bf3..24176f24c83 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -29,7 +29,7 @@ import '../base/net.dart'; import '../base/platform.dart'; import '../build_info.dart'; import '../build_system/targets/web.dart'; -import '../bundle.dart'; +import '../bundle_builder.dart'; import '../cache.dart'; import '../compile.dart'; import '../convert.dart'; diff --git a/packages/flutter_tools/lib/src/macos/cocoapods.dart b/packages/flutter_tools/lib/src/macos/cocoapods.dart index 048ba6e89cf..771935aabef 100644 --- a/packages/flutter_tools/lib/src/macos/cocoapods.dart +++ b/packages/flutter_tools/lib/src/macos/cocoapods.dart @@ -2,10 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:file/file.dart'; -import 'package:meta/meta.dart'; import 'package:process/process.dart'; import '../base/common.dart'; @@ -85,12 +82,12 @@ const Version cocoaPodsRecommendedVersion = Version.withText(1, 10, 0, '1.10.0') /// installing iOS/macOS dependencies. class CocoaPods { CocoaPods({ - @required FileSystem fileSystem, - @required ProcessManager processManager, - @required XcodeProjectInterpreter xcodeProjectInterpreter, - @required Logger logger, - @required Platform platform, - @required Usage usage, + required FileSystem fileSystem, + required ProcessManager processManager, + required XcodeProjectInterpreter xcodeProjectInterpreter, + required Logger logger, + required Platform platform, + required Usage usage, }) : _fileSystem = fileSystem, _processManager = processManager, _xcodeProjectInterpreter = xcodeProjectInterpreter, @@ -112,33 +109,33 @@ class CocoaPods { final Logger _logger; final Usage _usage; - Future _versionText; + Future? _versionText; Future get isInstalled => _processUtils.exitsHappy(['which', 'pod']); - Future get cocoaPodsVersionText { + Future get cocoaPodsVersionText { _versionText ??= _processUtils.run( ['pod', '--version'], environment: { 'LANG': 'en_US.UTF-8', }, - ).then((RunResult result) { + ).then((RunResult result) { return result.exitCode == 0 ? result.stdout.trim() : null; }, onError: (dynamic _) => null); - return _versionText; + return _versionText!; } Future get evaluateCocoaPodsInstallation async { if (!(await isInstalled)) { return CocoaPodsStatus.notInstalled; } - final String versionText = await cocoaPodsVersionText; + final String? versionText = await cocoaPodsVersionText; if (versionText == null) { return CocoaPodsStatus.brokenInstall; } try { - final Version installedVersion = Version.parse(versionText); + final Version? installedVersion = Version.parse(versionText); if (installedVersion == null) { return CocoaPodsStatus.unknownVersion; } @@ -155,8 +152,8 @@ class CocoaPods { } Future processPods({ - @required XcodeBasedProject xcodeProject, - @required BuildMode buildMode, + required XcodeBasedProject xcodeProject, + required BuildMode buildMode, bool dependenciesChanged = true, }) async { if (!xcodeProject.podfile.existsSync()) { @@ -253,7 +250,7 @@ class CocoaPods { podfileTemplateName = isSwift ? 'Podfile-ios-swift' : 'Podfile-ios-objc'; } final File podfileTemplate = _fileSystem.file(_fileSystem.path.join( - Cache.flutterRoot, + Cache.flutterRoot!, 'packages', 'flutter_tools', 'templates', @@ -391,7 +388,7 @@ class CocoaPods { // // Warn the user if they are still symlinking to the framework. final Link flutterSymlink = _fileSystem.link(_fileSystem.path.join( - (xcodeProject as IosProject).symlinks.path, + xcodeProject.symlinks.path, 'flutter', )); if (flutterSymlink.existsSync()) { diff --git a/packages/flutter_tools/lib/src/project.dart b/packages/flutter_tools/lib/src/project.dart index 064905a908a..f4e403f1480 100644 --- a/packages/flutter_tools/lib/src/project.dart +++ b/packages/flutter_tools/lib/src/project.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:meta/meta.dart'; import 'package:xml/xml.dart'; import 'package:yaml/yaml.dart'; @@ -20,7 +18,7 @@ import 'cmake.dart'; import 'features.dart'; import 'flutter_manifest.dart'; import 'flutter_plugins.dart'; -import 'globals.dart' as globals; +import 'globals_null_migrated.dart' as globals; import 'ios/plist_parser.dart'; import 'ios/xcode_build_settings.dart' as xcode; import 'ios/xcodeproj.dart'; @@ -29,8 +27,8 @@ import 'template.dart'; class FlutterProjectFactory { FlutterProjectFactory({ - @required Logger logger, - @required FileSystem fileSystem, + required Logger logger, + required FileSystem fileSystem, }) : _logger = logger, _fileSystem = fileSystem; @@ -89,7 +87,7 @@ class FlutterProject { /// Create a [FlutterProject] and bypass the project caching. @visibleForTesting - static FlutterProject fromDirectoryTest(Directory directory, [Logger logger]) { + static FlutterProject fromDirectoryTest(Directory directory, [Logger? logger]) { final FileSystem fileSystem = directory.fileSystem; logger ??= BufferLogger.test(); final FlutterManifest manifest = FlutterProject._readManifest( @@ -126,14 +124,14 @@ class FlutterProject { // Don't require iOS build info, this method is only // used during create as best-effort, use the // default target bundle identifier. - final String bundleIdentifier = await ios.productBundleIdentifier(null); + final String? bundleIdentifier = await ios.productBundleIdentifier(null); if (bundleIdentifier != null) { candidates.add(bundleIdentifier); } } if (android.existsSync()) { - final String applicationId = android.applicationId; - final String group = android.group; + final String? applicationId = android.applicationId; + final String? group = android.group; candidates.addAll([ if (applicationId != null) applicationId, @@ -142,21 +140,21 @@ class FlutterProject { ]); } if (example.android.existsSync()) { - final String applicationId = example.android.applicationId; + final String? applicationId = example.android.applicationId; if (applicationId != null) { candidates.add(applicationId); } } if (example.ios.existsSync()) { - final String bundleIdentifier = await example.ios.productBundleIdentifier(null); + final String? bundleIdentifier = await example.ios.productBundleIdentifier(null); if (bundleIdentifier != null) { candidates.add(bundleIdentifier); } } - return Set.of(candidates.map(_organizationNameFromPackageName).whereType()); + return Set.of(candidates.map(_organizationNameFromPackageName).whereType()); } - String _organizationNameFromPackageName(String packageName) { + String? _organizationNameFromPackageName(String packageName) { if (packageName != null && 0 <= packageName.lastIndexOf('.')) { return packageName.substring(0, packageName.lastIndexOf('.')); } @@ -164,35 +162,35 @@ class FlutterProject { } /// The iOS sub project of this project. - IosProject _ios; + IosProject? _ios; IosProject get ios => _ios ??= IosProject.fromFlutter(this); /// The Android sub project of this project. - AndroidProject _android; + AndroidProject? _android; AndroidProject get android => _android ??= AndroidProject._(this); /// The web sub project of this project. - WebProject _web; + WebProject? _web; WebProject get web => _web ??= WebProject._(this); /// The MacOS sub project of this project. - MacOSProject _macos; + MacOSProject? _macos; MacOSProject get macos => _macos ??= MacOSProject._(this); /// The Linux sub project of this project. - LinuxProject _linux; + LinuxProject? _linux; LinuxProject get linux => _linux ??= LinuxProject._(this); /// The Windows sub project of this project. - WindowsProject _windows; + WindowsProject? _windows; WindowsProject get windows => _windows ??= WindowsProject._(this); /// The Windows UWP sub project of this project. - WindowsUwpProject _windowUwp; + WindowsUwpProject? _windowUwp; WindowsUwpProject get windowsUwp => _windowUwp ??= WindowsUwpProject._(this); /// The Fuchsia sub project of this project. - FuchsiaProject _fuchsia; + FuchsiaProject? _fuchsia; FuchsiaProject get fuchsia => _fuchsia ??= FuchsiaProject._(this); /// The `pubspec.yaml` file of this project. @@ -256,10 +254,10 @@ class FlutterProject { /// Completes with an empty [FlutterManifest], if the file does not exist. /// Completes with a ToolExit on validation error. static FlutterManifest _readManifest(String path, { - @required Logger logger, - @required FileSystem fileSystem, + required Logger logger, + required FileSystem fileSystem, }) { - FlutterManifest manifest; + FlutterManifest? manifest; try { manifest = FlutterManifest.createFromPath( path, @@ -350,8 +348,8 @@ class FlutterProject { /// Returns a json encoded string containing the [appName], [version], and [buildNumber] that is used to generate version.json String getVersionInfo() { - final String buildName = manifest.buildName; - final String buildNumber = manifest.buildNumber; + final String? buildName = manifest.buildName; + final String? buildNumber = manifest.buildNumber; final Map versionFileJson = { 'app_name': manifest.appName, if (buildName != null) @@ -534,16 +532,16 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { /// The product bundle identifier of the host app, or null if not set or if /// iOS tooling needed to read it is not installed. - Future productBundleIdentifier(BuildInfo buildInfo) async { + Future productBundleIdentifier(BuildInfo? buildInfo) async { if (!existsSync()) { return null; } return _productBundleIdentifier ??= await _parseProductBundleIdentifier(buildInfo); } - String _productBundleIdentifier; + String? _productBundleIdentifier; - Future _parseProductBundleIdentifier(BuildInfo buildInfo) async { - String fromPlist; + Future _parseProductBundleIdentifier(BuildInfo? buildInfo) async { + String? fromPlist; final File defaultInfoPlist = defaultHostInfoPlist; // Users can change the location of the Info.plist. // Try parsing the default, first. @@ -561,7 +559,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { return fromPlist; } } - final Map allBuildSettings = await buildSettingsForBuildInfo(buildInfo); + final Map? allBuildSettings = await buildSettingsForBuildInfo(buildInfo); if (allBuildSettings != null) { if (fromPlist != null) { // Perform variable substitution using build settings. @@ -576,7 +574,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { // or companion watchOS projects. However, on non-macOS platforms this is // only used for display purposes and to regenerate organization names, so // best-effort is probably fine. - final String fromPbxproj = _firstMatchInFile(xcodeProjectInfoFile, _productBundleIdPattern)?.group(2); + final String? fromPbxproj = _firstMatchInFile(xcodeProjectInfoFile, _productBundleIdPattern)?.group(2); if (fromPbxproj != null && (fromPlist == null || fromPlist == _productBundleIdVariable)) { return fromPbxproj; } @@ -585,22 +583,22 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { } /// The bundle name of the host app, `My App.app`. - Future hostAppBundleName(BuildInfo buildInfo) async { + Future hostAppBundleName(BuildInfo buildInfo) async { if (!existsSync()) { return null; } return _hostAppBundleName ??= await _parseHostAppBundleName(buildInfo); } - String _hostAppBundleName; + String? _hostAppBundleName; Future _parseHostAppBundleName(BuildInfo buildInfo) async { // The product name and bundle name are derived from the display name, which the user // is instructed to change in Xcode as part of deploying to the App Store. // https://flutter.dev/docs/deployment/ios#review-xcode-project-settings // The only source of truth for the name is Xcode's interpretation of the build settings. - String productName; - if (globals.xcodeProjectInterpreter.isInstalled) { - final Map xcodeBuildSettings = await buildSettingsForBuildInfo(buildInfo); + String? productName; + if (globals.xcodeProjectInterpreter?.isInstalled == true) { + final Map? xcodeBuildSettings = await buildSettingsForBuildInfo(buildInfo); if (xcodeBuildSettings != null) { productName = xcodeBuildSettings['FULL_PRODUCT_NAME']; } @@ -614,27 +612,28 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { /// The build settings for the host app of this project, as a detached map. /// /// Returns null, if iOS tooling is unavailable. - Future> buildSettingsForBuildInfo(BuildInfo buildInfo, { EnvironmentType environmentType = EnvironmentType.physical }) async { + Future?> buildSettingsForBuildInfo(BuildInfo? buildInfo, { EnvironmentType environmentType = EnvironmentType.physical }) async { if (!existsSync()) { return null; } - final XcodeProjectInfo info = await projectInfo(); + final XcodeProjectInfo? info = await projectInfo(); if (info == null) { return null; } - final String scheme = info.schemeFor(buildInfo); + final String? scheme = info.schemeFor(buildInfo); if (scheme == null) { info.reportFlavorNotFoundAndExit(); } - final String configuration = (await projectInfo()).buildConfigurationFor( + final String? configuration = (await projectInfo())?.buildConfigurationFor( buildInfo, scheme, ); final XcodeProjectBuildContext buildContext = XcodeProjectBuildContext(environmentType: environmentType, scheme: scheme, configuration: configuration); - if (_buildSettingsByBuildContext[buildContext] == null) { - final Map calculatedBuildSettings = await _xcodeProjectBuildSettings(buildContext); + final Map? currentBuildSettings = _buildSettingsByBuildContext[buildContext]; + if (currentBuildSettings == null) { + final Map? calculatedBuildSettings = await _xcodeProjectBuildSettings(buildContext); if (calculatedBuildSettings != null) { _buildSettingsByBuildContext[buildContext] = calculatedBuildSettings; } @@ -644,17 +643,17 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { final Map> _buildSettingsByBuildContext = >{}; - Future projectInfo() async { - final XcodeProjectInterpreter xcodeProjectInterpreter = globals.xcodeProjectInterpreter; + Future projectInfo() async { + final XcodeProjectInterpreter? xcodeProjectInterpreter = globals.xcodeProjectInterpreter; if (!xcodeProject.existsSync() || xcodeProjectInterpreter == null || !xcodeProjectInterpreter.isInstalled) { return null; } return _projectInfo ??= await xcodeProjectInterpreter.getInfo(hostAppRoot.path); } - XcodeProjectInfo _projectInfo; + XcodeProjectInfo? _projectInfo; - Future> _xcodeProjectBuildSettings(XcodeProjectBuildContext buildContext) async { - final XcodeProjectInterpreter xcodeProjectInterpreter = globals.xcodeProjectInterpreter; + Future?> _xcodeProjectBuildSettings(XcodeProjectBuildContext buildContext) async { + final XcodeProjectInterpreter? xcodeProjectInterpreter = globals.xcodeProjectInterpreter; if (xcodeProjectInterpreter == null || !xcodeProjectInterpreter.isInstalled) { return null; } @@ -680,7 +679,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { /// Check if one the [targets] of the project is a watchOS companion app target. Future containsWatchCompanion(List targets, BuildInfo buildInfo) async { - final String bundleIdentifier = await productBundleIdentifier(buildInfo); + final String? bundleIdentifier = await productBundleIdentifier(buildInfo); // A bundle identifier is required for a companion app. if (bundleIdentifier == null) { return false; @@ -748,7 +747,7 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject { // However, cocoapods will run before that script and requires something // to be in this location. final Directory framework = globals.fs.directory( - globals.artifacts.getArtifactPath( + globals.artifacts?.getArtifactPath( Artifact.flutterXcframework, platform: TargetPlatform.ios, mode: mode, @@ -876,7 +875,7 @@ class AndroidProject extends FlutterProjectPlatform { /// Returns true if the current version of the Gradle plugin is supported. bool get isSupportedVersion => _isSupportedVersion ??= _computeSupportedVersion(); - bool _isSupportedVersion; + bool? _isSupportedVersion; bool _computeSupportedVersion() { final FileSystem fileSystem = hostAppGradleRoot.fileSystem; @@ -927,12 +926,12 @@ class AndroidProject extends FlutterProjectPlatform { return hostAppGradleRoot.childFile('build.gradle').existsSync(); } - String get applicationId { + String? get applicationId { final File gradleFile = hostAppGradleRoot.childDirectory('app').childFile('build.gradle'); return _firstMatchInFile(gradleFile, _applicationIdPattern)?.group(1); } - String get group { + String? get group { final File gradleFile = hostAppGradleRoot.childFile('build.gradle'); return _firstMatchInFile(gradleFile, _groupPattern)?.group(1); } @@ -993,7 +992,7 @@ to migrate your project. 'library_new_embedding', ), ephemeralDirectory); await _overwriteFromTemplate(globals.fs.path.join('module', 'android', 'gradle'), ephemeralDirectory); - globals.gradleUtils.injectGradleWrapperIfNeeded(ephemeralDirectory); + globals.gradleUtils?.injectGradleWrapperIfNeeded(ephemeralDirectory); } Future _overwriteFromTemplate(String path, Directory target) async { @@ -1038,9 +1037,9 @@ to migrate your project. 'Please ensure that you have read permission to this file and try again.'); } for (final XmlElement metaData in document.findAllElements('meta-data')) { - final String name = metaData.getAttribute('android:name'); + final String? name = metaData.getAttribute('android:name'); if (name == 'flutterEmbedding') { - final String embeddingVersionString = metaData.getAttribute('android:value'); + final String? embeddingVersionString = metaData.getAttribute('android:value'); if (embeddingVersionString == '1') { return AndroidEmbeddingVersion.v1; } @@ -1102,12 +1101,12 @@ void _deleteIfExistsSync(Directory directory) { /// Returns the first line-based match for [regExp] in [file]. /// /// Assumes UTF8 encoding. -Match _firstMatchInFile(File file, RegExp regExp) { +Match? _firstMatchInFile(File file, RegExp regExp) { if (!file.existsSync()) { return null; } for (final String line in file.readAsLinesSync()) { - final Match match = regExp.firstMatch(line); + final Match? match = regExp.firstMatch(line); if (match != null) { return match; } @@ -1254,20 +1253,20 @@ class WindowsUwpProject extends WindowsProject { File get runnerCmakeFile => _editableDirectory.childDirectory('runner_uwp').childFile('CMakeLists.txt'); /// Eventually this will be used to check if the user's unstable project needs to be regenerated. - int get projectVersion => int.tryParse(_editableDirectory.childFile('project_version').readAsStringSync()); + int? get projectVersion => int.tryParse(_editableDirectory.childFile('project_version').readAsStringSync()); /// Retrieve the GUID of the UWP package. - String get packageGuid => _packageGuid ??= getCmakePackageGuid(runnerCmakeFile); - String _packageGuid; + String? get packageGuid => _packageGuid ??= getCmakePackageGuid(runnerCmakeFile); + String? _packageGuid; File get appManifest => _editableDirectory.childDirectory('runner_uwp').childFile('appxmanifest.in'); - String get packageVersion => _packageVersion ??= parseAppVersion(this); - String _packageVersion; + String? get packageVersion => _packageVersion ??= parseAppVersion(this); + String? _packageVersion; } @visibleForTesting -String parseAppVersion(WindowsUwpProject project) { +String? parseAppVersion(WindowsUwpProject project) { final File appManifestFile = project.appManifest; if (!appManifestFile.existsSync()) { return null; @@ -1329,7 +1328,7 @@ class LinuxProject extends FlutterProjectPlatform implements CmakeBasedProject { Future ensureReadyForPlatformSpecificTooling() async {} - String get applicationId { + String? get applicationId { return _firstMatchInFile(cmakeFile, _applicationIdPattern)?.group(1); } } @@ -1340,13 +1339,13 @@ class FuchsiaProject { final FlutterProject project; - Directory _editableHostAppDirectory; + Directory? _editableHostAppDirectory; Directory get editableHostAppDirectory => _editableHostAppDirectory ??= project.directory.childDirectory('fuchsia'); bool existsSync() => editableHostAppDirectory.existsSync(); - Directory _meta; + Directory? _meta; Directory get meta => _meta ??= editableHostAppDirectory.childDirectory('meta'); } diff --git a/packages/flutter_tools/lib/src/tester/flutter_tester.dart b/packages/flutter_tools/lib/src/tester/flutter_tester.dart index c69b2c89ce1..6d4a74ffee1 100644 --- a/packages/flutter_tools/lib/src/tester/flutter_tester.dart +++ b/packages/flutter_tools/lib/src/tester/flutter_tester.dart @@ -18,6 +18,7 @@ import '../base/logger.dart'; import '../base/os.dart'; import '../build_info.dart'; import '../bundle.dart'; +import '../bundle_builder.dart'; import '../desktop_device.dart'; import '../devfs.dart'; import '../device.dart'; diff --git a/packages/flutter_tools/test/commands.shard/permeable/build_bundle_test.dart b/packages/flutter_tools/test/commands.shard/permeable/build_bundle_test.dart index a36014fa46b..e5d90df27fa 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/build_bundle_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/build_bundle_test.dart @@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/bundle.dart'; +import 'package:flutter_tools/src/bundle_builder.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/commands/build_bundle.dart'; import 'package:flutter_tools/src/features.dart'; diff --git a/packages/flutter_tools/test/general.shard/android/gradle_find_bundle_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_find_bundle_test.dart index b69c729512d..8f2eb4a855d 100644 --- a/packages/flutter_tools/test/general.shard/android/gradle_find_bundle_test.dart +++ b/packages/flutter_tools/test/general.shard/android/gradle_find_bundle_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:file/memory.dart'; import 'package:flutter_tools/src/android/gradle.dart'; import 'package:flutter_tools/src/base/file_system.dart'; @@ -15,7 +13,7 @@ import 'package:flutter_tools/src/reporting/reporting.dart'; import '../../src/common.dart'; void main() { - FileSystem fileSystem; + late FileSystem fileSystem; setUp(() { fileSystem = MemoryFileSystem.test(); diff --git a/packages/flutter_tools/test/general.shard/android/gradle_utils_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_utils_test.dart index 64ae07c324a..acdc11d90e8 100644 --- a/packages/flutter_tools/test/general.shard/android/gradle_utils_test.dart +++ b/packages/flutter_tools/test/general.shard/android/gradle_utils_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:file/memory.dart'; import 'package:flutter_tools/src/android/gradle_utils.dart'; import 'package:flutter_tools/src/base/file_system.dart'; @@ -17,9 +15,9 @@ import '../../src/fakes.dart'; void main() { group('injectGradleWrapperIfNeeded', () { - MemoryFileSystem fileSystem; - Directory gradleWrapperDirectory; - GradleUtils gradleUtils; + late MemoryFileSystem fileSystem; + late Directory gradleWrapperDirectory; + late GradleUtils gradleUtils; setUp(() { fileSystem = MemoryFileSystem.test(); diff --git a/packages/flutter_tools/test/general.shard/android_plugin_test.dart b/packages/flutter_tools/test/general.shard/android_plugin_test.dart index b3855fb4d16..699271f2e8c 100644 --- a/packages/flutter_tools/test/general.shard/android_plugin_test.dart +++ b/packages/flutter_tools/test/general.shard/android_plugin_test.dart @@ -2,13 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:file/file.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/platform_plugins.dart'; - import '../src/common.dart'; void main() { diff --git a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart index 12451212d96..692f4d7b605 100644 --- a/packages/flutter_tools/test/general.shard/asset_bundle_test.dart +++ b/packages/flutter_tools/test/general.shard/asset_bundle_test.dart @@ -11,7 +11,7 @@ import 'package:file/memory.dart'; import 'package:flutter_tools/src/asset.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/platform.dart'; -import 'package:flutter_tools/src/bundle.dart'; +import 'package:flutter_tools/src/bundle_builder.dart'; import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals; diff --git a/packages/flutter_tools/test/general.shard/bundle_builder_test.dart b/packages/flutter_tools/test/general.shard/bundle_builder_test.dart index 8f9044e490f..bdee9b650a8 100644 --- a/packages/flutter_tools/test/general.shard/bundle_builder_test.dart +++ b/packages/flutter_tools/test/general.shard/bundle_builder_test.dart @@ -8,7 +8,7 @@ import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_system/build_system.dart'; -import 'package:flutter_tools/src/bundle.dart'; +import 'package:flutter_tools/src/bundle_builder.dart'; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals; import 'package:flutter_tools/src/project.dart'; diff --git a/packages/flutter_tools/test/general.shard/custom_devices/custom_device_test.dart b/packages/flutter_tools/test/general.shard/custom_devices/custom_device_test.dart index 813dd12e08f..b2372b68146 100644 --- a/packages/flutter_tools/test/general.shard/custom_devices/custom_device_test.dart +++ b/packages/flutter_tools/test/general.shard/custom_devices/custom_device_test.dart @@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_system/build_system.dart'; import 'package:flutter_tools/src/bundle.dart'; +import 'package:flutter_tools/src/bundle_builder.dart'; import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/custom_devices/custom_device.dart'; import 'package:flutter_tools/src/custom_devices/custom_device_config.dart'; diff --git a/packages/flutter_tools/test/src/android_common.dart b/packages/flutter_tools/test/src/android_common.dart index 4300d2e76db..11bec7727a1 100644 --- a/packages/flutter_tools/test/src/android_common.dart +++ b/packages/flutter_tools/test/src/android_common.dart @@ -2,39 +2,35 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:flutter_tools/src/android/android_builder.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals; import 'package:flutter_tools/src/project.dart'; -import 'package:meta/meta.dart'; - /// A fake implementation of [AndroidBuilder]. class FakeAndroidBuilder implements AndroidBuilder { @override Future buildAar({ - @required FlutterProject project, - @required Set androidBuildInfo, - @required String target, - @required String outputDirectoryPath, - @required String buildNumber, + required FlutterProject project, + required Set androidBuildInfo, + required String target, + String? outputDirectoryPath, + required String buildNumber, }) async {} @override Future buildApk({ - @required FlutterProject project, - @required AndroidBuildInfo androidBuildInfo, - @required String target, + required FlutterProject project, + required AndroidBuildInfo androidBuildInfo, + required String target, }) async {} @override Future buildAab({ - @required FlutterProject project, - @required AndroidBuildInfo androidBuildInfo, - @required String target, + required FlutterProject project, + required AndroidBuildInfo androidBuildInfo, + required String target, bool validateDeferredComponents = true, bool deferredComponentsEnabled = false, }) async {}