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