Unverified Commit ac770423 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] Allow flutter build aar to know the null safety mode ahead of time (#80000)

parent a3e66b39
......@@ -3,12 +3,13 @@
// found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart';
import '../android/android_builder.dart';
import '../android/gradle_utils.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/os.dart';
import '../build_info.dart';
import '../cache.dart';
......@@ -96,7 +97,9 @@ class BuildAarCommand extends BuildSubCommand {
'By default, AARs are built for `release`, `debug` and `profile`.\n'
'The POM file is used to include the dependencies that the AAR was compiled against.\n'
'To learn more about how to use these artifacts, see '
'https://flutter.dev/go/build-aar';
'https://flutter.dev/go/build-aar\n'
'Note: this command builds applications assuming that the entrypoint is lib/main.dart. '
'This cannot currently be configured.';
@override
Future<FlutterCommandResult> runCommand() async {
......@@ -114,11 +117,15 @@ class BuildAarCommand extends BuildSubCommand {
? stringArg('build-number')
: '1.0';
final File targetFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart'));
for (final String buildMode in const <String>['debug', 'profile', 'release']) {
if (boolArg(buildMode)) {
androidBuildInfo.add(
AndroidBuildInfo(
await getBuildInfo(forcedBuildMode: BuildMode.fromName(buildMode)),
await getBuildInfo(
forcedBuildMode: BuildMode.fromName(buildMode),
forcedTargetFile: targetFile,
),
targetArchs: targetArchitectures,
)
);
......@@ -131,7 +138,7 @@ class BuildAarCommand extends BuildSubCommand {
displayNullSafetyMode(androidBuildInfo.first.buildInfo);
await androidBuilder.buildAar(
project: _getProject(),
target: '', // Not needed because this command only builds Android's code.
target: targetFile.path,
androidBuildInfo: androidBuildInfo,
outputDirectoryPath: stringArg('output-dir'),
buildNumber: buildNumber,
......
......@@ -841,7 +841,7 @@ abstract class FlutterCommand extends Command<void> {
///
/// Throws a [ToolExit] if the current set of options is not compatible with
/// each other.
Future<BuildInfo> getBuildInfo({ BuildMode forcedBuildMode }) async {
Future<BuildInfo> getBuildInfo({ BuildMode forcedBuildMode, File forcedTargetFile }) async {
final bool trackWidgetCreation = argParser.options.containsKey('track-widget-creation') &&
boolArg('track-widget-creation');
......@@ -891,8 +891,8 @@ abstract class FlutterCommand extends Command<void> {
// passing a flag. Examine the entrypoint file to determine if it
// is opted in or out.
final bool wasNullSafetyFlagParsed = argResults.wasParsed(FlutterOptions.kNullSafety);
if (!wasNullSafetyFlagParsed && argParser.options.containsKey('target')) {
final File entrypointFile = globals.fs.file(targetFile);
if (!wasNullSafetyFlagParsed && (argParser.options.containsKey('target') || forcedTargetFile != null)) {
final File entrypointFile = forcedTargetFile ?? globals.fs.file(targetFile);
final LanguageVersion languageVersion = determineLanguageVersion(
entrypointFile,
packageConfig.packageOf(entrypointFile.absolute.uri),
......
......@@ -185,6 +185,7 @@ void main() {
expect(buildInfo.splitDebugInfoPath, '/project-name/v1.2.3/');
expect(buildInfo.dartObfuscation, isTrue);
expect(buildInfo.dartDefines.contains('foo=bar'), isTrue);
expect(buildInfo.nullSafetyMode, NullSafetyMode.sound);
}, overrides: <Type, Generator>{
AndroidBuilder: () => fakeAndroidBuilder,
});
......
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