Unverified Commit 18c59cdb authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate build commands to null safety (#95649)

parent b3393914
...@@ -70,7 +70,7 @@ class BundleBuilder { ...@@ -70,7 +70,7 @@ class BundleBuilder {
final Target target = buildInfo.mode == BuildMode.debug final Target target = buildInfo.mode == BuildMode.debug
? const CopyFlutterBundle() ? const CopyFlutterBundle()
: const ReleaseCopyFlutterBundle(); : const ReleaseCopyFlutterBundle();
final BuildResult result = await buildSystem!.build(target, environment); final BuildResult result = await buildSystem.build(target, environment);
if (!result.success) { if (!result.success) {
for (final ExceptionMeasurement measurement in result.exceptions.values) { for (final ExceptionMeasurement measurement in result.exceptions.values) {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../build_info.dart'; import '../build_info.dart';
...@@ -61,11 +59,11 @@ class BuildCommand extends FlutterCommand { ...@@ -61,11 +59,11 @@ class BuildCommand extends FlutterCommand {
String get category => FlutterCommandCategory.project; String get category => FlutterCommandCategory.project;
@override @override
Future<FlutterCommandResult> runCommand() async => null; Future<FlutterCommandResult> runCommand() async => FlutterCommandResult.fail();
} }
abstract class BuildSubCommand extends FlutterCommand { abstract class BuildSubCommand extends FlutterCommand {
BuildSubCommand({@required bool verboseHelp}) { BuildSubCommand({required bool verboseHelp}) {
requiresPubspecYaml(); requiresPubspecYaml();
usesFatalWarningsOption(verboseHelp: verboseHelp); usesFatalWarningsOption(verboseHelp: verboseHelp);
} }
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../android/android_builder.dart'; import '../android/android_builder.dart';
import '../android/gradle_utils.dart'; import '../android/gradle_utils.dart';
import '../base/common.dart'; import '../base/common.dart';
...@@ -20,7 +17,7 @@ import '../runner/flutter_command.dart' show FlutterCommandResult; ...@@ -20,7 +17,7 @@ import '../runner/flutter_command.dart' show FlutterCommandResult;
import 'build.dart'; import 'build.dart';
class BuildAarCommand extends BuildSubCommand { class BuildAarCommand extends BuildSubCommand {
BuildAarCommand({ @required bool verboseHelp }) : super(verboseHelp: verboseHelp) { BuildAarCommand({ required bool verboseHelp }) : super(verboseHelp: verboseHelp) {
argParser argParser
..addFlag( ..addFlag(
'debug', 'debug',
...@@ -52,7 +49,6 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -52,7 +49,6 @@ class BuildAarCommand extends BuildSubCommand {
argParser argParser
..addMultiOption( ..addMultiOption(
'target-platform', 'target-platform',
splitCommas: true,
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'], defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'], allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'],
help: 'The target platform for which the project is compiled.', help: 'The target platform for which the project is compiled.',
...@@ -116,10 +112,11 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -116,10 +112,11 @@ class BuildAarCommand extends BuildSubCommand {
final Iterable<AndroidArch> targetArchitectures = final Iterable<AndroidArch> targetArchitectures =
stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName); stringsArg('target-platform').map<AndroidArch>(getAndroidArchForName);
final String? buildNumberArg = stringArg('build-number');
final String buildNumber = argParser.options.containsKey('build-number') final String buildNumber = argParser.options.containsKey('build-number')
&& stringArg('build-number') != null && buildNumberArg != null
&& stringArg('build-number').isNotEmpty && buildNumberArg.isNotEmpty
? stringArg('build-number') ? buildNumberArg
: '1.0'; : '1.0';
final File targetFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart')); final File targetFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'));
...@@ -141,7 +138,7 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -141,7 +138,7 @@ class BuildAarCommand extends BuildSubCommand {
} }
displayNullSafetyMode(androidBuildInfo.first.buildInfo); displayNullSafetyMode(androidBuildInfo.first.buildInfo);
await androidBuilder.buildAar( await androidBuilder?.buildAar(
project: _getProject(), project: _getProject(),
target: targetFile.path, target: targetFile.path,
androidBuildInfo: androidBuildInfo, androidBuildInfo: androidBuildInfo,
...@@ -154,9 +151,10 @@ class BuildAarCommand extends BuildSubCommand { ...@@ -154,9 +151,10 @@ class BuildAarCommand extends BuildSubCommand {
/// Returns the [FlutterProject] which is determined from the remaining command-line /// Returns the [FlutterProject] which is determined from the remaining command-line
/// argument if any or the current working directory. /// argument if any or the current working directory.
FlutterProject _getProject() { FlutterProject _getProject() {
if (argResults.rest.isEmpty) { final List<String> remainingArguments = argResults!.rest;
if (remainingArguments.isEmpty) {
return FlutterProject.current(); return FlutterProject.current();
} }
return FlutterProject.fromDirectory(globals.fs.directory(findProjectRoot(globals.fs, argResults.rest.first))); return FlutterProject.fromDirectory(globals.fs.directory(findProjectRoot(globals.fs, remainingArguments.first)));
} }
} }
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import '../android/android_builder.dart'; import '../android/android_builder.dart';
import '../android/build_validation.dart'; import '../android/build_validation.dart';
import '../android/gradle_utils.dart'; import '../android/gradle_utils.dart';
...@@ -44,7 +42,6 @@ class BuildApkCommand extends BuildSubCommand { ...@@ -44,7 +42,6 @@ class BuildApkCommand extends BuildSubCommand {
'To learn more, see: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split', 'To learn more, see: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split',
) )
..addMultiOption('target-platform', ..addMultiOption('target-platform',
splitCommas: true,
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'], defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'], allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'],
help: 'The target platform for which the app is compiled.', help: 'The target platform for which the app is compiled.',
...@@ -109,7 +106,7 @@ class BuildApkCommand extends BuildSubCommand { ...@@ -109,7 +106,7 @@ class BuildApkCommand extends BuildSubCommand {
validateBuild(androidBuildInfo); validateBuild(androidBuildInfo);
displayNullSafetyMode(androidBuildInfo.buildInfo); displayNullSafetyMode(androidBuildInfo.buildInfo);
globals.terminal.usesTerminalUi = true; globals.terminal.usesTerminalUi = true;
await androidBuilder.buildApk( await androidBuilder?.buildApk(
project: FlutterProject.current(), project: FlutterProject.current(),
target: targetFile, target: targetFile,
androidBuildInfo: androidBuildInfo, androidBuildInfo: androidBuildInfo,
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import '../android/android_builder.dart'; import '../android/android_builder.dart';
import '../android/build_validation.dart'; import '../android/build_validation.dart';
import '../android/deferred_components_prebuild_validator.dart'; import '../android/deferred_components_prebuild_validator.dart';
...@@ -44,13 +42,11 @@ class BuildAppBundleCommand extends BuildSubCommand { ...@@ -44,13 +42,11 @@ class BuildAppBundleCommand extends BuildSubCommand {
addMultidexOption(); addMultidexOption();
addIgnoreDeprecationOption(); addIgnoreDeprecationOption();
argParser.addMultiOption('target-platform', argParser.addMultiOption('target-platform',
splitCommas: true,
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'], defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
allowed: <String>['android-arm', 'android-arm64', 'android-x64'], allowed: <String>['android-arm', 'android-arm64', 'android-x64'],
help: 'The target platform for which the app is compiled.', help: 'The target platform for which the app is compiled.',
); );
argParser.addFlag('deferred-components', argParser.addFlag('deferred-components',
negatable: true,
defaultsTo: true, defaultsTo: true,
help: 'Setting to false disables building with deferred components. All deferred code ' help: 'Setting to false disables building with deferred components. All deferred code '
'will be compiled into the base app, and assets act as if they were defined under' 'will be compiled into the base app, and assets act as if they were defined under'
...@@ -58,7 +54,6 @@ class BuildAppBundleCommand extends BuildSubCommand { ...@@ -58,7 +54,6 @@ class BuildAppBundleCommand extends BuildSubCommand {
'non-deferred components apps.', 'non-deferred components apps.',
); );
argParser.addFlag('validate-deferred-components', argParser.addFlag('validate-deferred-components',
negatable: true,
defaultsTo: true, defaultsTo: true,
help: 'When enabled, deferred component apps will fail to build if setup problems are ' help: 'When enabled, deferred component apps will fail to build if setup problems are '
'detected that would prevent deferred components from functioning properly. The ' 'detected that would prevent deferred components from functioning properly. The '
...@@ -121,7 +116,8 @@ class BuildAppBundleCommand extends BuildSubCommand { ...@@ -121,7 +116,8 @@ class BuildAppBundleCommand extends BuildSubCommand {
); );
// Do all setup verification that doesn't involve loading units. Checks that // Do all setup verification that doesn't involve loading units. Checks that
// require generated loading units are done after gen_snapshot in assemble. // require generated loading units are done after gen_snapshot in assemble.
if (FlutterProject.current().manifest.deferredComponents != null && boolArg('deferred-components') && boolArg('validate-deferred-components') && !boolArg('debug')) { final List<DeferredComponent>? deferredComponents = FlutterProject.current().manifest.deferredComponents;
if (deferredComponents != null && boolArg('deferred-components') && boolArg('validate-deferred-components') && !boolArg('debug')) {
final DeferredComponentsPrebuildValidator validator = DeferredComponentsPrebuildValidator( final DeferredComponentsPrebuildValidator validator = DeferredComponentsPrebuildValidator(
FlutterProject.current().directory, FlutterProject.current().directory,
globals.logger, globals.logger,
...@@ -129,14 +125,14 @@ class BuildAppBundleCommand extends BuildSubCommand { ...@@ -129,14 +125,14 @@ class BuildAppBundleCommand extends BuildSubCommand {
title: 'Deferred components prebuild validation', title: 'Deferred components prebuild validation',
); );
validator.clearOutputDir(); validator.clearOutputDir();
await validator.checkAndroidDynamicFeature(FlutterProject.current().manifest.deferredComponents); await validator.checkAndroidDynamicFeature(deferredComponents);
validator.checkAndroidResourcesStrings(FlutterProject.current().manifest.deferredComponents); validator.checkAndroidResourcesStrings(deferredComponents);
validator.handleResults(); validator.handleResults();
// Delete intermediates libs dir for components to resolve mismatching // Delete intermediates libs dir for components to resolve mismatching
// abis supported by base and dynamic feature modules. // abis supported by base and dynamic feature modules.
for (final DeferredComponent component in FlutterProject.current().manifest.deferredComponents) { for (final DeferredComponent component in deferredComponents) {
final Directory deferredLibsIntermediate = FlutterProject.current().directory final Directory deferredLibsIntermediate = FlutterProject.current().directory
.childDirectory('build') .childDirectory('build')
.childDirectory(component.name) .childDirectory(component.name)
...@@ -153,7 +149,7 @@ class BuildAppBundleCommand extends BuildSubCommand { ...@@ -153,7 +149,7 @@ class BuildAppBundleCommand extends BuildSubCommand {
validateBuild(androidBuildInfo); validateBuild(androidBuildInfo);
displayNullSafetyMode(androidBuildInfo.buildInfo); displayNullSafetyMode(androidBuildInfo.buildInfo);
globals.terminal.usesTerminalUi = true; globals.terminal.usesTerminalUi = true;
await androidBuilder.buildAab( await androidBuilder?.buildAab(
project: FlutterProject.current(), project: FlutterProject.current(),
target: targetFile, target: targetFile,
androidBuildInfo: androidBuildInfo, androidBuildInfo: androidBuildInfo,
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import '../base/common.dart'; import '../base/common.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../bundle.dart'; import '../bundle.dart';
...@@ -18,8 +16,8 @@ import 'build.dart'; ...@@ -18,8 +16,8 @@ import 'build.dart';
class BuildBundleCommand extends BuildSubCommand { class BuildBundleCommand extends BuildSubCommand {
BuildBundleCommand({ BuildBundleCommand({
bool verboseHelp = false, bool verboseHelp = false,
this.bundleBuilder, BundleBuilder? bundleBuilder,
}) : super(verboseHelp: verboseHelp) { }) : _bundleBuilder = bundleBuilder ?? BundleBuilder(), super(verboseHelp: verboseHelp) {
usesTargetOption(); usesTargetOption();
usesFilesystemOptions(hide: !verboseHelp); usesFilesystemOptions(hide: !verboseHelp);
usesBuildNumberOption(); usesBuildNumberOption();
...@@ -54,18 +52,14 @@ class BuildBundleCommand extends BuildSubCommand { ...@@ -54,18 +52,14 @@ class BuildBundleCommand extends BuildSubCommand {
) )
..addFlag( ..addFlag(
'tree-shake-icons', 'tree-shake-icons',
negatable: true,
defaultsTo: false,
hide: !verboseHelp, hide: !verboseHelp,
help: '(deprecated) Icon font tree shaking is not supported by this command.', help: '(deprecated) Icon font tree shaking is not supported by this command.',
); );
usesPubOption(); usesPubOption();
usesTrackWidgetCreation(verboseHelp: verboseHelp); usesTrackWidgetCreation(verboseHelp: verboseHelp);
bundleBuilder ??= BundleBuilder();
} }
BundleBuilder bundleBuilder; final BundleBuilder _bundleBuilder;
@override @override
final String name = 'bundle'; final String name = 'bundle';
...@@ -93,7 +87,7 @@ class BuildBundleCommand extends BuildSubCommand { ...@@ -93,7 +87,7 @@ class BuildBundleCommand extends BuildSubCommand {
@override @override
Future<void> validateCommand() async { Future<void> validateCommand() async {
if (argResults['tree-shake-icons'] as bool) { if (boolArg('tree-shake-icons')) {
throwToolExit('The "--tree-shake-icons" flag is deprecated for "build bundle" and will be removed in a future version of Flutter.'); throwToolExit('The "--tree-shake-icons" flag is deprecated for "build bundle" and will be removed in a future version of Flutter.');
} }
return super.validateCommand(); return super.validateCommand();
...@@ -101,7 +95,7 @@ class BuildBundleCommand extends BuildSubCommand { ...@@ -101,7 +95,7 @@ class BuildBundleCommand extends BuildSubCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
final String targetPlatform = stringArg('target-platform'); final String targetPlatform = stringArg('target-platform')!;
final TargetPlatform platform = getTargetPlatformForName(targetPlatform); final TargetPlatform platform = getTargetPlatformForName(targetPlatform);
if (platform == null) { if (platform == null) {
throwToolExit('Unknown platform: $targetPlatform'); throwToolExit('Unknown platform: $targetPlatform');
...@@ -141,7 +135,7 @@ class BuildBundleCommand extends BuildSubCommand { ...@@ -141,7 +135,7 @@ class BuildBundleCommand extends BuildSubCommand {
final BuildInfo buildInfo = await getBuildInfo(); final BuildInfo buildInfo = await getBuildInfo();
displayNullSafetyMode(buildInfo); displayNullSafetyMode(buildInfo);
await bundleBuilder.build( await _bundleBuilder.build(
platform: platform, platform: platform,
buildInfo: buildInfo, buildInfo: buildInfo,
mainPath: targetFile, mainPath: targetFile,
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
...@@ -20,7 +16,7 @@ import 'build.dart'; ...@@ -20,7 +16,7 @@ import 'build.dart';
/// A command to build a Fuchsia target. /// A command to build a Fuchsia target.
class BuildFuchsiaCommand extends BuildSubCommand { class BuildFuchsiaCommand extends BuildSubCommand {
BuildFuchsiaCommand({ BuildFuchsiaCommand({
@required bool verboseHelp, required bool verboseHelp,
}) : super(verboseHelp: verboseHelp) { }) : super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag(); addTreeShakeIconsFlag();
usesTargetOption(); usesTargetOption();
...@@ -83,9 +79,9 @@ class BuildFuchsiaCommand extends BuildSubCommand { ...@@ -83,9 +79,9 @@ class BuildFuchsiaCommand extends BuildSubCommand {
await buildFuchsia( await buildFuchsia(
fuchsiaProject: flutterProject.fuchsia, fuchsiaProject: flutterProject.fuchsia,
target: targetFile, target: targetFile,
targetPlatform: getTargetPlatformForName(stringArg('target-platform')), targetPlatform: getTargetPlatformForName(stringArg('target-platform')!),
buildInfo: buildInfo, buildInfo: buildInfo,
runnerPackageSource: stringArg('runner-source'), runnerPackageSource: stringArg('runner-source')!,
); );
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
......
...@@ -2,10 +2,7 @@ ...@@ -2,10 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:meta/meta.dart';
import '../base/analyze_size.dart'; import '../base/analyze_size.dart';
import '../base/common.dart'; import '../base/common.dart';
...@@ -23,7 +20,7 @@ import 'build.dart'; ...@@ -23,7 +20,7 @@ import 'build.dart';
/// Builds an .app for an iOS app to be used for local testing on an iOS device /// Builds an .app for an iOS app to be used for local testing on an iOS device
/// or simulator. Can only be run on a macOS host. /// or simulator. Can only be run on a macOS host.
class BuildIOSCommand extends _BuildIOSSubCommand { class BuildIOSCommand extends _BuildIOSSubCommand {
BuildIOSCommand({ @required bool verboseHelp }) : super(verboseHelp: verboseHelp) { BuildIOSCommand({ required bool verboseHelp }) : super(verboseHelp: verboseHelp) {
argParser argParser
..addFlag('config-only', ..addFlag('config-only',
help: 'Update the project configuration without performing a build. ' help: 'Update the project configuration without performing a build. '
...@@ -67,7 +64,7 @@ class BuildIOSCommand extends _BuildIOSSubCommand { ...@@ -67,7 +64,7 @@ class BuildIOSCommand extends _BuildIOSSubCommand {
/// ///
/// Can only be run on a macOS host. /// Can only be run on a macOS host.
class BuildIOSArchiveCommand extends _BuildIOSSubCommand { class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
BuildIOSArchiveCommand({@required bool verboseHelp}) BuildIOSArchiveCommand({required bool verboseHelp})
: super(verboseHelp: verboseHelp) { : super(verboseHelp: verboseHelp) {
argParser.addOption( argParser.addOption(
'export-options-plist', 'export-options-plist',
...@@ -99,7 +96,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { ...@@ -99,7 +96,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
@override @override
final bool shouldCodesign = true; final bool shouldCodesign = true;
String get exportOptionsPlist => stringArg('export-options-plist'); String? get exportOptionsPlist => stringArg('export-options-plist');
@override @override
Directory _outputAppDirectory(String xcodeResultOutput) => globals.fs Directory _outputAppDirectory(String xcodeResultOutput) => globals.fs
...@@ -109,21 +106,22 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { ...@@ -109,21 +106,22 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
if (exportOptionsPlist != null) { final String? exportOptions = exportOptionsPlist;
final FileSystemEntityType type = globals.fs.typeSync(exportOptionsPlist); if (exportOptions != null) {
final FileSystemEntityType type = globals.fs.typeSync(exportOptions);
if (type == FileSystemEntityType.notFound) { if (type == FileSystemEntityType.notFound) {
throwToolExit( throwToolExit(
'"$exportOptionsPlist" property list does not exist.'); '"$exportOptions" property list does not exist.');
} else if (type != FileSystemEntityType.file) { } else if (type != FileSystemEntityType.file) {
throwToolExit( throwToolExit(
'"$exportOptionsPlist" is not a file. See "xcodebuild -h" for available keys.'); '"$exportOptions" is not a file. See "xcodebuild -h" for available keys.');
} }
} }
final FlutterCommandResult xcarchiveResult = await super.runCommand(); final FlutterCommandResult xcarchiveResult = await super.runCommand();
final BuildInfo buildInfo = await getBuildInfo(); final BuildInfo buildInfo = await getBuildInfo();
displayNullSafetyMode(buildInfo); displayNullSafetyMode(buildInfo);
if (exportOptionsPlist == null) { if (exportOptions == null) {
return xcarchiveResult; return xcarchiveResult;
} }
...@@ -134,16 +132,16 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { ...@@ -134,16 +132,16 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
} }
// Build IPA from generated xcarchive. // Build IPA from generated xcarchive.
final BuildableIOSApp app = await buildableIOSApp(buildInfo); final BuildableIOSApp app = await buildableIOSApp;
Status status; Status? status;
RunResult result; RunResult? result;
final String outputPath = globals.fs.path.absolute(app.ipaOutputPath); final String outputPath = globals.fs.path.absolute(app.ipaOutputPath);
try { try {
status = globals.logger.startProgress('Building IPA...'); status = globals.logger.startProgress('Building IPA...');
result = await globals.processUtils.run( result = await globals.processUtils.run(
<String>[ <String>[
...globals.xcode.xcrunCommand(), ...globals.xcode!.xcrunCommand(),
'xcodebuild', 'xcodebuild',
'-exportArchive', '-exportArchive',
if (shouldCodesign) ...<String>[ if (shouldCodesign) ...<String>[
...@@ -155,11 +153,11 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { ...@@ -155,11 +153,11 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
'-exportPath', '-exportPath',
outputPath, outputPath,
'-exportOptionsPlist', '-exportOptionsPlist',
globals.fs.path.absolute(exportOptionsPlist), globals.fs.path.absolute(exportOptions),
], ],
); );
} finally { } finally {
status.stop(); status?.stop();
} }
if (result.exitCode != 0) { if (result.exitCode != 0) {
...@@ -184,7 +182,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { ...@@ -184,7 +182,7 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand {
abstract class _BuildIOSSubCommand extends BuildSubCommand { abstract class _BuildIOSSubCommand extends BuildSubCommand {
_BuildIOSSubCommand({ _BuildIOSSubCommand({
@required bool verboseHelp required bool verboseHelp
}) : super(verboseHelp: verboseHelp) { }) : super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag(); addTreeShakeIconsFlag();
addSplitDebugInfoOption(); addSplitDebugInfoOption();
...@@ -214,15 +212,19 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -214,15 +212,19 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
bool get configOnly; bool get configOnly;
bool get shouldCodesign; bool get shouldCodesign;
Future<BuildableIOSApp> buildableIOSApp(BuildInfo buildInfo) async { late final Future<BuildInfo> cachedBuildInfo = getBuildInfo();
_buildableIOSApp ??= await applicationPackages.getPackageForPlatform(
late final Future<BuildableIOSApp> buildableIOSApp = () async {
final BuildableIOSApp? app = await applicationPackages?.getPackageForPlatform(
TargetPlatform.ios, TargetPlatform.ios,
buildInfo: buildInfo, buildInfo: await cachedBuildInfo,
) as BuildableIOSApp; ) as BuildableIOSApp?;
return _buildableIOSApp;
}
BuildableIOSApp _buildableIOSApp; if (app == null) {
throwToolExit('Application not configured for iOS');
}
return app;
}();
Directory _outputAppDirectory(String xcodeResultOutput); Directory _outputAppDirectory(String xcodeResultOutput);
...@@ -232,7 +234,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -232,7 +234,7 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
defaultBuildMode = environmentType == EnvironmentType.simulator ? BuildMode.debug : BuildMode.release; defaultBuildMode = environmentType == EnvironmentType.simulator ? BuildMode.debug : BuildMode.release;
final BuildInfo buildInfo = await getBuildInfo(); final BuildInfo buildInfo = await cachedBuildInfo;
if (!supported) { if (!supported) {
throwToolExit('Building for iOS is only supported on macOS.'); throwToolExit('Building for iOS is only supported on macOS.');
...@@ -250,14 +252,10 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -250,14 +252,10 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
); );
} }
final BuildableIOSApp app = await buildableIOSApp(buildInfo); final BuildableIOSApp app = await buildableIOSApp;
if (app == null) {
throwToolExit('Application not configured for iOS');
}
final String logTarget = environmentType == EnvironmentType.simulator ? 'simulator' : 'device'; final String logTarget = environmentType == EnvironmentType.simulator ? 'simulator' : 'device';
final String typeName = globals.artifacts.getEngineType(TargetPlatform.ios, buildInfo.mode); final String typeName = globals.artifacts!.getEngineType(TargetPlatform.ios, buildInfo.mode);
if (xcodeBuildAction == XcodeBuildAction.build) { if (xcodeBuildAction == XcodeBuildAction.build) {
globals.printStatus('Building $app for $logTarget ($typeName)...'); globals.printStatus('Building $app for $logTarget ($typeName)...');
} else { } else {
...@@ -293,20 +291,24 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { ...@@ -293,20 +291,24 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
final File precompilerTrace = globals.fs.directory(buildInfo.codeSizeDirectory) final File precompilerTrace = globals.fs.directory(buildInfo.codeSizeDirectory)
.childFile('trace.$arch.json'); .childFile('trace.$arch.json');
final Directory outputAppDirectoryCandidate = _outputAppDirectory(result.output); final String? resultOutput = result.output;
if (resultOutput == null) {
throwToolExit('Could not find app to analyze code size');
}
final Directory outputAppDirectoryCandidate = _outputAppDirectory(resultOutput);
Directory appDirectory; Directory? appDirectory;
if (outputAppDirectoryCandidate.existsSync()) { if (outputAppDirectoryCandidate.existsSync()) {
appDirectory = outputAppDirectoryCandidate.listSync() appDirectory = outputAppDirectoryCandidate.listSync()
.whereType<Directory>() .whereType<Directory>()
.firstWhere((Directory directory) { .where((Directory directory) {
return globals.fs.path.extension(directory.path) == '.app'; return globals.fs.path.extension(directory.path) == '.app';
}, orElse: () => null); }).first;
} }
if (appDirectory == null) { if (appDirectory == null) {
throwToolExit('Could not find app to analyze code size in ${outputAppDirectoryCandidate.path}'); throwToolExit('Could not find app to analyze code size in ${outputAppDirectoryCandidate.path}');
} }
final Map<String, Object> output = await sizeAnalyzer.analyzeAotSnapshot( final Map<String, Object?> output = await sizeAnalyzer.analyzeAotSnapshot(
aotSnapshot: aotSnapshot, aotSnapshot: aotSnapshot,
precompilerTrace: precompilerTrace, precompilerTrace: precompilerTrace,
outputDirectory: appDirectory, outputDirectory: appDirectory,
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../artifacts.dart'; import '../artifacts.dart';
...@@ -31,12 +29,13 @@ import 'build.dart'; ...@@ -31,12 +29,13 @@ import 'build.dart';
/// managers. /// managers.
class BuildIOSFrameworkCommand extends BuildSubCommand { class BuildIOSFrameworkCommand extends BuildSubCommand {
BuildIOSFrameworkCommand({ BuildIOSFrameworkCommand({
FlutterVersion flutterVersion, // Instantiating FlutterVersion kicks off networking, so delay until it's needed, but allow test injection. // Instantiating FlutterVersion kicks off networking, so delay until it's needed, but allow test injection.
@required BuildSystem buildSystem, @visibleForTesting FlutterVersion? flutterVersion,
@required bool verboseHelp, required BuildSystem buildSystem,
Cache cache, required bool verboseHelp,
Platform platform Cache? cache,
}) : _flutterVersion = flutterVersion, Platform? platform
}) : _injectedFlutterVersion = flutterVersion,
_buildSystem = buildSystem, _buildSystem = buildSystem,
_injectedCache = cache, _injectedCache = cache,
_injectedPlatform = platform, _injectedPlatform = platform,
...@@ -54,26 +53,22 @@ class BuildIOSFrameworkCommand extends BuildSubCommand { ...@@ -54,26 +53,22 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
argParser argParser
..addFlag('debug', ..addFlag('debug',
negatable: true,
defaultsTo: true, defaultsTo: true,
help: 'Whether to produce a framework for the debug build configuration. ' help: 'Whether to produce a framework for the debug build configuration. '
'By default, all build configurations are built.' 'By default, all build configurations are built.'
) )
..addFlag('profile', ..addFlag('profile',
negatable: true,
defaultsTo: true, defaultsTo: true,
help: 'Whether to produce a framework for the profile build configuration. ' help: 'Whether to produce a framework for the profile build configuration. '
'By default, all build configurations are built.' 'By default, all build configurations are built.'
) )
..addFlag('release', ..addFlag('release',
negatable: true,
defaultsTo: true, defaultsTo: true,
help: 'Whether to produce a framework for the release build configuration. ' help: 'Whether to produce a framework for the release build configuration. '
'By default, all build configurations are built.' 'By default, all build configurations are built.'
) )
..addFlag('universal', ..addFlag('universal',
help: '(deprecated) Produce universal frameworks that include all valid architectures.', help: '(deprecated) Produce universal frameworks that include all valid architectures.',
negatable: true,
hide: !verboseHelp, hide: !verboseHelp,
) )
..addFlag('xcframework', ..addFlag('xcframework',
...@@ -97,16 +92,18 @@ class BuildIOSFrameworkCommand extends BuildSubCommand { ...@@ -97,16 +92,18 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
); );
} }
final BuildSystem _buildSystem; final BuildSystem? _buildSystem;
BuildSystem get buildSystem => _buildSystem ?? globals.buildSystem; BuildSystem get buildSystem => _buildSystem ?? globals.buildSystem;
Cache get _cache => _injectedCache ?? globals.cache; Cache get _cache => _injectedCache ?? globals.cache;
final Cache _injectedCache; final Cache? _injectedCache;
Platform get _platform => _injectedPlatform ?? globals.platform; Platform get _platform => _injectedPlatform ?? globals.platform;
final Platform _injectedPlatform; final Platform? _injectedPlatform;
FlutterVersion _flutterVersion; // FlutterVersion.instance kicks off git processing which can sometimes fail, so don't try it until needed.
FlutterVersion get _flutterVersion => _injectedFlutterVersion ?? globals.flutterVersion;
final FlutterVersion? _injectedFlutterVersion;
@override @override
bool get reportNullSafety => false; bool get reportNullSafety => false;
...@@ -124,7 +121,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand { ...@@ -124,7 +121,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
DevelopmentArtifact.iOS, DevelopmentArtifact.iOS,
}; };
FlutterProject _project; late final FlutterProject _project = FlutterProject.current();
Future<List<BuildInfo>> getBuildInfos() async { Future<List<BuildInfo>> getBuildInfos() async {
final List<BuildInfo> buildInfos = <BuildInfo>[]; final List<BuildInfo> buildInfos = <BuildInfo>[];
...@@ -148,7 +145,6 @@ class BuildIOSFrameworkCommand extends BuildSubCommand { ...@@ -148,7 +145,6 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
@override @override
Future<void> validateCommand() async { Future<void> validateCommand() async {
await super.validateCommand(); await super.validateCommand();
_project = FlutterProject.current();
if (!supported) { if (!supported) {
throwToolExit('Building frameworks for iOS is only supported on the Mac.'); throwToolExit('Building frameworks for iOS is only supported on the Mac.');
} }
...@@ -178,7 +174,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand { ...@@ -178,7 +174,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
final List<BuildInfo> buildInfos = await getBuildInfos(); final List<BuildInfo> buildInfos = await getBuildInfos();
displayNullSafetyMode(buildInfos.first); displayNullSafetyMode(buildInfos.first);
for (final BuildInfo buildInfo in buildInfos) { for (final BuildInfo buildInfo in buildInfos) {
final String productBundleIdentifier = await _project.ios.productBundleIdentifier(buildInfo); final String? productBundleIdentifier = await _project.ios.productBundleIdentifier(buildInfo);
globals.printStatus('Building frameworks for $productBundleIdentifier in ${getNameForBuildMode(buildInfo.mode)} mode...'); globals.printStatus('Building frameworks for $productBundleIdentifier in ${getNameForBuildMode(buildInfo.mode)} mode...');
final String xcodeBuildConfiguration = sentenceCase(getNameForBuildMode(buildInfo.mode)); final String xcodeBuildConfiguration = sentenceCase(getNameForBuildMode(buildInfo.mode));
final Directory modeDirectory = outputDirectory.childDirectory(xcodeBuildConfiguration); final Directory modeDirectory = outputDirectory.childDirectory(xcodeBuildConfiguration);
...@@ -188,8 +184,6 @@ class BuildIOSFrameworkCommand extends BuildSubCommand { ...@@ -188,8 +184,6 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
} }
if (boolArg('cocoapods')) { if (boolArg('cocoapods')) {
// FlutterVersion.instance kicks off git processing which can sometimes fail, so don't try it until needed.
_flutterVersion ??= globals.flutterVersion;
produceFlutterPodspec(buildInfo.mode, modeDirectory, force: boolArg('force')); produceFlutterPodspec(buildInfo.mode, modeDirectory, force: boolArg('force'));
} else { } else {
// Copy Flutter.xcframework. // Copy Flutter.xcframework.
...@@ -263,7 +257,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand { ...@@ -263,7 +257,7 @@ class BuildIOSFrameworkCommand extends BuildSubCommand {
// Fake out a semantic version with major.minor.(patch * 100) + hotfix. // Fake out a semantic version with major.minor.(patch * 100) + hotfix.
// A real increasing version is required to prompt CocoaPods to fetch // A real increasing version is required to prompt CocoaPods to fetch
// new artifacts when the source URL changes. // new artifacts when the source URL changes.
final int minorHotfixVersion = gitTagVersion.z * 100 + (gitTagVersion.hotfix ?? 0); final int minorHotfixVersion = (gitTagVersion.z ?? 0) * 100 + (gitTagVersion.hotfix ?? 0);
final File license = _cache.getLicenseFile(); final File license = _cache.getLicenseFile();
if (!license.existsSync()) { if (!license.existsSync()) {
...@@ -309,7 +303,7 @@ end ...@@ -309,7 +303,7 @@ end
final Status status = globals.logger.startProgress( final Status status = globals.logger.startProgress(
' ├─Copying Flutter.xcframework...', ' ├─Copying Flutter.xcframework...',
); );
final String engineCacheFlutterFrameworkDirectory = globals.artifacts.getArtifactPath( final String engineCacheFlutterFrameworkDirectory = globals.artifacts!.getArtifactPath(
Artifact.flutterXcframework, Artifact.flutterXcframework,
platform: TargetPlatform.ios, platform: TargetPlatform.ios,
mode: buildInfo.mode, mode: buildInfo.mode,
...@@ -369,15 +363,15 @@ end ...@@ -369,15 +363,15 @@ end
kIosArchs: defaultIOSArchsForEnvironment(sdkType) kIosArchs: defaultIOSArchsForEnvironment(sdkType)
.map(getNameForDarwinArch) .map(getNameForDarwinArch)
.join(' '), .join(' '),
kSdkRoot: await globals.xcode.sdkLocation(sdkType), kSdkRoot: await globals.xcode!.sdkLocation(sdkType),
...buildInfo.toBuildSystemEnvironment(), ...buildInfo.toBuildSystemEnvironment(),
}, },
artifacts: globals.artifacts, artifacts: globals.artifacts!,
fileSystem: globals.fs, fileSystem: globals.fs,
logger: globals.logger, logger: globals.logger,
processManager: globals.processManager, processManager: globals.processManager,
platform: globals.platform, platform: globals.platform,
engineVersion: globals.artifacts.isLocalEngine engineVersion: globals.artifacts!.isLocalEngine
? null ? null
: globals.flutterVersion.engineRevision, : globals.flutterVersion.engineRevision,
generateDartPluginRegistry: true, generateDartPluginRegistry: true,
...@@ -423,7 +417,7 @@ end ...@@ -423,7 +417,7 @@ end
'bitcode' : 'marker'; // In release, force bitcode embedding without archiving. 'bitcode' : 'marker'; // In release, force bitcode embedding without archiving.
List<String> pluginsBuildCommand = <String>[ List<String> pluginsBuildCommand = <String>[
...globals.xcode.xcrunCommand(), ...globals.xcode!.xcrunCommand(),
'xcodebuild', 'xcodebuild',
'-alltargets', '-alltargets',
'-sdk', '-sdk',
...@@ -439,7 +433,6 @@ end ...@@ -439,7 +433,6 @@ end
RunResult buildPluginsResult = await globals.processUtils.run( RunResult buildPluginsResult = await globals.processUtils.run(
pluginsBuildCommand, pluginsBuildCommand,
workingDirectory: _project.ios.hostAppRoot.childDirectory('Pods').path, workingDirectory: _project.ios.hostAppRoot.childDirectory('Pods').path,
allowReentrantFlutter: false,
); );
if (buildPluginsResult.exitCode != 0) { if (buildPluginsResult.exitCode != 0) {
...@@ -449,7 +442,7 @@ end ...@@ -449,7 +442,7 @@ end
// Always build debug for simulator. // Always build debug for simulator.
final String simulatorConfiguration = sentenceCase(getNameForBuildMode(BuildMode.debug)); final String simulatorConfiguration = sentenceCase(getNameForBuildMode(BuildMode.debug));
pluginsBuildCommand = <String>[ pluginsBuildCommand = <String>[
...globals.xcode.xcrunCommand(), ...globals.xcode!.xcrunCommand(),
'xcodebuild', 'xcodebuild',
'-alltargets', '-alltargets',
'-sdk', '-sdk',
...@@ -467,7 +460,6 @@ end ...@@ -467,7 +460,6 @@ end
workingDirectory: _project.ios.hostAppRoot workingDirectory: _project.ios.hostAppRoot
.childDirectory('Pods') .childDirectory('Pods')
.path, .path,
allowReentrantFlutter: false,
); );
if (buildPluginsResult.exitCode != 0) { if (buildPluginsResult.exitCode != 0) {
...@@ -515,7 +507,7 @@ end ...@@ -515,7 +507,7 @@ end
return; return;
} }
final List<String> xcframeworkCommand = <String>[ final List<String> xcframeworkCommand = <String>[
...globals.xcode.xcrunCommand(), ...globals.xcode!.xcrunCommand(),
'xcodebuild', 'xcodebuild',
'-create-xcframework', '-create-xcframework',
for (Directory framework in frameworks) ...<String>[ for (Directory framework in frameworks) ...<String>[
...@@ -536,7 +528,6 @@ end ...@@ -536,7 +528,6 @@ end
final RunResult xcframeworkResult = await globals.processUtils.run( final RunResult xcframeworkResult = await globals.processUtils.run(
xcframeworkCommand, xcframeworkCommand,
allowReentrantFlutter: false,
); );
if (xcframeworkResult.exitCode != 0) { if (xcframeworkResult.exitCode != 0) {
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../base/analyze_size.dart'; import '../base/analyze_size.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/os.dart'; import '../base/os.dart';
...@@ -21,7 +17,7 @@ import 'build.dart'; ...@@ -21,7 +17,7 @@ import 'build.dart';
/// A command to build a linux desktop target through a build shell script. /// A command to build a linux desktop target through a build shell script.
class BuildLinuxCommand extends BuildSubCommand { class BuildLinuxCommand extends BuildSubCommand {
BuildLinuxCommand({ BuildLinuxCommand({
@required OperatingSystemUtils operatingSystemUtils, required OperatingSystemUtils operatingSystemUtils,
bool verboseHelp = false, bool verboseHelp = false,
}) : _operatingSystemUtils = operatingSystemUtils, }) : _operatingSystemUtils = operatingSystemUtils,
super(verboseHelp: verboseHelp) { super(verboseHelp: verboseHelp) {
...@@ -63,7 +59,7 @@ class BuildLinuxCommand extends BuildSubCommand { ...@@ -63,7 +59,7 @@ class BuildLinuxCommand extends BuildSubCommand {
final BuildInfo buildInfo = await getBuildInfo(); final BuildInfo buildInfo = await getBuildInfo();
final FlutterProject flutterProject = FlutterProject.current(); final FlutterProject flutterProject = FlutterProject.current();
final TargetPlatform targetPlatform = final TargetPlatform targetPlatform =
getTargetPlatformForName(stringArg('target-platform')); getTargetPlatformForName(stringArg('target-platform')!);
final bool needCrossBuild = final bool needCrossBuild =
getNameForHostPlatformArch(_operatingSystemUtils.hostPlatform) getNameForHostPlatformArch(_operatingSystemUtils.hostPlatform)
!= getNameForTargetPlatformArch(targetPlatform); != getNameForTargetPlatformArch(targetPlatform);
...@@ -97,7 +93,7 @@ class BuildLinuxCommand extends BuildSubCommand { ...@@ -97,7 +93,7 @@ class BuildLinuxCommand extends BuildSubCommand {
), ),
needCrossBuild: needCrossBuild, needCrossBuild: needCrossBuild,
targetPlatform: targetPlatform, targetPlatform: targetPlatform,
targetSysroot: stringArg('target-sysroot'), targetSysroot: stringArg('target-sysroot')!,
); );
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../base/analyze_size.dart'; import '../base/analyze_size.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../build_info.dart'; import '../build_info.dart';
...@@ -20,7 +16,7 @@ import 'build.dart'; ...@@ -20,7 +16,7 @@ import 'build.dart';
/// A command to build a macOS desktop target through a build shell script. /// A command to build a macOS desktop target through a build shell script.
class BuildMacosCommand extends BuildSubCommand { class BuildMacosCommand extends BuildSubCommand {
BuildMacosCommand({ BuildMacosCommand({
@required bool verboseHelp, required bool verboseHelp,
}) : super(verboseHelp: verboseHelp) { }) : super(verboseHelp: verboseHelp) {
addCommonDesktopBuildOptions(verboseHelp: verboseHelp); addCommonDesktopBuildOptions(verboseHelp: verboseHelp);
usesBuildNumberOption(); usesBuildNumberOption();
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../build_system/targets/web.dart'; import '../build_system/targets/web.dart';
...@@ -19,7 +15,7 @@ import 'build.dart'; ...@@ -19,7 +15,7 @@ import 'build.dart';
class BuildWebCommand extends BuildSubCommand { class BuildWebCommand extends BuildSubCommand {
BuildWebCommand({ BuildWebCommand({
@required bool verboseHelp, required bool verboseHelp,
}) : super(verboseHelp: verboseHelp) { }) : super(verboseHelp: verboseHelp) {
addTreeShakeIconsFlag(enabledByDefault: false); addTreeShakeIconsFlag(enabledByDefault: false);
usesTargetOption(); usesTargetOption();
...@@ -31,14 +27,12 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -31,14 +27,12 @@ class BuildWebCommand extends BuildSubCommand {
addNullSafetyModeOptions(hide: !verboseHelp); addNullSafetyModeOptions(hide: !verboseHelp);
addNativeNullAssertions(); addNativeNullAssertions();
argParser.addFlag('csp', argParser.addFlag('csp',
defaultsTo: false,
negatable: false, negatable: false,
help: 'Disable dynamic generation of code in the generated output. ' help: 'Disable dynamic generation of code in the generated output. '
'This is necessary to satisfy CSP restrictions (see http://www.w3.org/TR/CSP/).' 'This is necessary to satisfy CSP restrictions (see http://www.w3.org/TR/CSP/).'
); );
argParser.addFlag( argParser.addFlag(
'source-maps', 'source-maps',
defaultsTo: false,
help: 'Generate a sourcemap file. These can be used by browsers ' help: 'Generate a sourcemap file. These can be used by browsers '
'to view and debug the original source code of a compiled and minified Dart ' 'to view and debug the original source code of a compiled and minified Dart '
'application.' 'application.'
...@@ -91,12 +85,13 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -91,12 +85,13 @@ class BuildWebCommand extends BuildSubCommand {
throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".'); throwToolExit('"build web" is not currently supported. To enable, run "flutter config --enable-web".');
} }
final FlutterProject flutterProject = FlutterProject.current(); final FlutterProject flutterProject = FlutterProject.current();
final String target = stringArg('target'); final String target = stringArg('target')!;
final BuildInfo buildInfo = await getBuildInfo(); final BuildInfo buildInfo = await getBuildInfo();
if (buildInfo.isDebug) { if (buildInfo.isDebug) {
throwToolExit('debug builds cannot be built directly for the web. Try using "flutter run"'); throwToolExit('debug builds cannot be built directly for the web. Try using "flutter run"');
} }
if (stringArg('base-href') != null && !(stringArg('base-href').startsWith('/') && stringArg('base-href').endsWith('/'))) { final String? baseHref = stringArg('base-href');
if (baseHref != null && !(baseHref.startsWith('/') && baseHref.endsWith('/'))) {
throwToolExit('base-href should start and end with /'); throwToolExit('base-href should start and end with /');
} }
if (!flutterProject.web.existsSync()) { if (!flutterProject.web.existsSync()) {
...@@ -107,7 +102,7 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -107,7 +102,7 @@ class BuildWebCommand extends BuildSubCommand {
.childFile('index.html') .childFile('index.html')
.readAsStringSync() .readAsStringSync()
.contains(kBaseHrefPlaceholder) && .contains(kBaseHrefPlaceholder) &&
stringArg('base-href') != null) { baseHref != null) {
throwToolExit( throwToolExit(
"Couldn't find the placeholder for base href. " "Couldn't find the placeholder for base href. "
r'Please add `<base href="$FLUTTER_BASE_HREF">` to web/index.html' r'Please add `<base href="$FLUTTER_BASE_HREF">` to web/index.html'
...@@ -119,10 +114,10 @@ class BuildWebCommand extends BuildSubCommand { ...@@ -119,10 +114,10 @@ class BuildWebCommand extends BuildSubCommand {
target, target,
buildInfo, buildInfo,
boolArg('csp'), boolArg('csp'),
stringArg('pwa-strategy'), stringArg('pwa-strategy')!,
boolArg('source-maps'), boolArg('source-maps'),
boolArg('native-null-assertions'), boolArg('native-null-assertions'),
stringArg('base-href'), baseHref,
); );
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../base/analyze_size.dart'; import '../base/analyze_size.dart';
...@@ -41,7 +39,7 @@ class BuildWindowsCommand extends BuildSubCommand { ...@@ -41,7 +39,7 @@ class BuildWindowsCommand extends BuildSubCommand {
String get description => 'Build a Windows desktop application.'; String get description => 'Build a Windows desktop application.';
@visibleForTesting @visibleForTesting
VisualStudio visualStudioOverride; VisualStudio? visualStudioOverride;
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import '../base/common.dart'; import '../base/common.dart';
...@@ -40,7 +38,7 @@ class BuildWindowsUwpCommand extends BuildSubCommand { ...@@ -40,7 +38,7 @@ class BuildWindowsUwpCommand extends BuildSubCommand {
String get description => 'Build a Windows UWP desktop application.'; String get description => 'Build a Windows UWP desktop application.';
@visibleForTesting @visibleForTesting
VisualStudio visualStudioOverride; VisualStudio? visualStudioOverride;
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
......
...@@ -50,7 +50,7 @@ import 'version.dart'; ...@@ -50,7 +50,7 @@ import 'version.dart';
String get flutterGit => platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git'; String get flutterGit => platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
Artifacts? get artifacts => context.get<Artifacts>(); Artifacts? get artifacts => context.get<Artifacts>();
BuildSystem? get buildSystem => context.get<BuildSystem>(); BuildSystem get buildSystem => context.get<BuildSystem>()!;
Cache get cache => context.get<Cache>()!; Cache get cache => context.get<Cache>()!;
CocoaPodsValidator? get cocoapodsValidator => context.get<CocoaPodsValidator>(); CocoaPodsValidator? get cocoapodsValidator => context.get<CocoaPodsValidator>();
Config get config => context.get<Config>()!; Config get config => context.get<Config>()!;
......
...@@ -1295,7 +1295,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -1295,7 +1295,7 @@ abstract class FlutterCommand extends Command<void> {
await generateLocalizationsSyntheticPackage( await generateLocalizationsSyntheticPackage(
environment: environment, environment: environment,
buildSystem: globals.buildSystem!, buildSystem: globals.buildSystem,
); );
await pub.get( await pub.get(
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import '../artifacts.dart'; import '../artifacts.dart';
import '../base/common.dart'; import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
...@@ -26,7 +24,7 @@ Future<void> buildWeb( ...@@ -26,7 +24,7 @@ Future<void> buildWeb(
String serviceWorkerStrategy, String serviceWorkerStrategy,
bool sourceMaps, bool sourceMaps,
bool nativeNullAssertions, bool nativeNullAssertions,
String baseHref, String? baseHref,
) async { ) async {
final bool hasWebPlugins = (await findPlugins(flutterProject)) final bool hasWebPlugins = (await findPlugins(flutterProject))
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey)); .any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
...@@ -47,6 +45,7 @@ Future<void> buildWeb( ...@@ -47,6 +45,7 @@ Future<void> buildWeb(
kTargetFile: target, kTargetFile: target,
kHasWebPlugins: hasWebPlugins.toString(), kHasWebPlugins: hasWebPlugins.toString(),
kCspMode: csp.toString(), kCspMode: csp.toString(),
if (baseHref != null)
kBaseHref : baseHref, kBaseHref : baseHref,
kSourceMapsEnabled: sourceMaps.toString(), kSourceMapsEnabled: sourceMaps.toString(),
kNativeNullAssertions: nativeNullAssertions.toString(), kNativeNullAssertions: nativeNullAssertions.toString(),
...@@ -54,13 +53,13 @@ Future<void> buildWeb( ...@@ -54,13 +53,13 @@ Future<void> buildWeb(
kServiceWorkerStrategy: serviceWorkerStrategy, kServiceWorkerStrategy: serviceWorkerStrategy,
...buildInfo.toBuildSystemEnvironment(), ...buildInfo.toBuildSystemEnvironment(),
}, },
artifacts: globals.artifacts, artifacts: globals.artifacts!,
fileSystem: globals.fs, fileSystem: globals.fs,
logger: globals.logger, logger: globals.logger,
processManager: globals.processManager, processManager: globals.processManager,
platform: globals.platform, platform: globals.platform,
cacheDir: globals.cache.getRoot(), cacheDir: globals.cache.getRoot(),
engineVersion: globals.artifacts.isLocalEngine engineVersion: globals.artifacts!.isLocalEngine
? null ? null
: globals.flutterVersion.engineRevision, : globals.flutterVersion.engineRevision,
flutterRootDir: globals.fs.directory(Cache.flutterRoot), flutterRootDir: globals.fs.directory(Cache.flutterRoot),
......
...@@ -111,7 +111,6 @@ void main() { ...@@ -111,7 +111,6 @@ void main() {
'DartObfuscation': 'false', 'DartObfuscation': 'false',
'TrackWidgetCreation': 'false', 'TrackWidgetCreation': 'false',
'TreeShakeIcons': 'false', 'TreeShakeIcons': 'false',
'baseHref': null,
}); });
}), }),
}); });
......
...@@ -89,8 +89,7 @@ void main() { ...@@ -89,8 +89,7 @@ void main() {
globals.fs.file('lib/main.dart').createSync(recursive: true); globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(recursive: true); globals.fs.file('pubspec.yaml').createSync(recursive: true);
globals.fs.file('.packages').createSync(recursive: true); globals.fs.file('.packages').createSync(recursive: true);
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand() final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
..bundleBuilder = FakeBundleBuilder());
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
...@@ -107,8 +106,7 @@ void main() { ...@@ -107,8 +106,7 @@ void main() {
globals.fs.file('lib/main.dart').createSync(recursive: true); globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand() final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
..bundleBuilder = FakeBundleBuilder());
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
...@@ -125,8 +123,7 @@ void main() { ...@@ -125,8 +123,7 @@ void main() {
globals.fs.file('lib/main.dart').createSync(recursive: true); globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand() final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
..bundleBuilder = FakeBundleBuilder());
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
...@@ -143,8 +140,7 @@ void main() { ...@@ -143,8 +140,7 @@ void main() {
globals.fs.file('lib/main.dart').createSync(recursive: true); globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand() final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
..bundleBuilder = FakeBundleBuilder());
expect(() => runner.run(<String>[ expect(() => runner.run(<String>[
'bundle', 'bundle',
...@@ -161,8 +157,7 @@ void main() { ...@@ -161,8 +157,7 @@ void main() {
globals.fs.file('lib/main.dart').createSync(recursive: true); globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand() final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
..bundleBuilder = FakeBundleBuilder());
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -179,8 +174,7 @@ void main() { ...@@ -179,8 +174,7 @@ void main() {
globals.fs.file('lib/main.dart').createSync(recursive: true); globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand() final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
..bundleBuilder = FakeBundleBuilder());
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
...@@ -197,8 +191,7 @@ void main() { ...@@ -197,8 +191,7 @@ void main() {
globals.fs.file('lib/main.dart').createSync(recursive: true); globals.fs.file('lib/main.dart').createSync(recursive: true);
globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('pubspec.yaml').createSync();
globals.fs.file('.packages').createSync(); globals.fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand() final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(bundleBuilder: FakeBundleBuilder()));
..bundleBuilder = FakeBundleBuilder());
await runner.run(<String>[ await runner.run(<String>[
'bundle', 'bundle',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment