Skip to content

Commit 0e59f0f

Browse files
authored
flutter build aar regenerates tooling between each build-mode step (#162705)
Closes flutter/flutter#162703. I still need to do a similar change for `ios|macos`-`framework` in flutter/flutter#162704. I added two unit tests, as well as opted in an integration test to the flag (it will become the default in flutter/flutter#160289). /cc @reidbaker @gmackall.
1 parent f219bba commit 0e59f0f

File tree

9 files changed

+363
-89
lines changed

9 files changed

+363
-89
lines changed

dev/devicelab/bin/tasks/build_aar_module_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ Future<void> main() async {
2121
}
2222
print('\nUsing JAVA_HOME=$javaHome');
2323

24+
// TODO(matanlurey): Remove after default.
25+
// https://github.com/flutter/flutter/issues/160257
26+
section('Opt-in to --explicit-package-dependencies');
27+
await flutter('config', options: <String>['--explicit-package-dependencies']);
28+
2429
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.');
2530
final Directory projectDir = Directory(path.join(tempDir.path, 'hello'));
2631
try {

packages/flutter_tools/lib/src/android/android_builder.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ abstract class AndroidBuilder {
1919
required FlutterProject project,
2020
required Set<AndroidBuildInfo> androidBuildInfo,
2121
required String target,
22+
required Future<void> Function(FlutterProject, {required bool releaseMode}) generateTooling,
2223
String? outputDirectoryPath,
2324
required String buildNumber,
2425
});

packages/flutter_tools/lib/src/android/gradle.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
191191
required FlutterProject project,
192192
required Set<AndroidBuildInfo> androidBuildInfo,
193193
required String target,
194+
required Future<void> Function(FlutterProject, {required bool releaseMode}) generateTooling,
194195
String? outputDirectoryPath,
195196
required String buildNumber,
196197
}) async {
@@ -208,6 +209,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
208209
_logger.printWarning(androidX86DeprecationWarning);
209210
}
210211
for (final AndroidBuildInfo androidBuildInfo in androidBuildInfo) {
212+
await generateTooling(project, releaseMode: androidBuildInfo.buildInfo.isRelease);
211213
await buildGradleAar(
212214
project: project,
213215
androidBuildInfo: androidBuildInfo,

packages/flutter_tools/lib/src/commands/build_aar.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ class BuildAarCommand extends BuildSubCommand {
111111
await super.validateCommand();
112112
}
113113

114+
@override
115+
bool get regeneratePlatformSpecificToolingDurifyVerify => false;
116+
114117
@override
115118
Future<FlutterCommandResult> runCommand() async {
116119
if (_androidSdk == null) {
@@ -149,10 +152,12 @@ class BuildAarCommand extends BuildSubCommand {
149152
}
150153

151154
displayNullSafetyMode(androidBuildInfo.first.buildInfo);
155+
152156
await androidBuilder?.buildAar(
153157
project: project,
154158
target: targetFile.path,
155159
androidBuildInfo: androidBuildInfo,
160+
generateTooling: regeneratePlatformSpecificToolingIfApplicable,
156161
outputDirectoryPath: stringArg('output'),
157162
buildNumber: buildNumber,
158163
);

packages/flutter_tools/lib/src/runner/flutter_command.dart

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,22 +1893,15 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
18931893
buildSystem: globals.buildSystem,
18941894
buildTargets: globals.buildTargets,
18951895
);
1896-
1897-
// null implicitly means all plugins are allowed
1898-
List<String>? allowedPlugins;
1899-
if (stringArg(FlutterGlobalOptions.kDeviceIdOption, global: true) == 'preview') {
1900-
// The preview device does not currently support any plugins.
1901-
allowedPlugins = PreviewDevice.supportedPubPlugins;
1902-
}
1903-
await project.regeneratePlatformSpecificTooling(
1904-
allowedPlugins: allowedPlugins,
1905-
releaseMode: featureFlags.isExplicitPackageDependenciesEnabled && getBuildMode().isRelease,
1906-
);
19071896
if (reportNullSafety) {
19081897
await _sendNullSafetyAnalyticsEvents(project);
19091898
}
19101899
}
19111900

1901+
if (regeneratePlatformSpecificToolingDurifyVerify) {
1902+
await regeneratePlatformSpecificToolingIfApplicable(project);
1903+
}
1904+
19121905
setupApplicationPackages();
19131906

19141907
if (commandPath != null) {
@@ -1918,6 +1911,66 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
19181911
return runCommand();
19191912
}
19201913

1914+
/// Whether to run [regeneratePlatformSpecificTooling] in [verifyThenRunCommand].
1915+
///
1916+
/// By default `true`, but sub-commands that do _meta_ builds (make multiple different
1917+
/// builds sequentially in one-go) may choose to override this and provide `false`, instead
1918+
/// calling [regeneratePlatformSpecificTooling] manually when applicable.
1919+
@visibleForOverriding
1920+
bool get regeneratePlatformSpecificToolingDurifyVerify => true;
1921+
1922+
/// Runs [FlutterProject.regeneratePlatformSpecificTooling] for [project] with appropriate configuration.
1923+
///
1924+
/// By default, this uses [getBuildMode] to determine and provide whether a release build is being made,
1925+
/// but sub-commands (such as commands that do _meta_ builds, or builds that make multiple different builds
1926+
/// sequentially in one-go) may choose to overide this and make the call at a different point in time.
1927+
///
1928+
/// This method should only be called when [shouldRunPub] is `true`:
1929+
/// ```dart
1930+
/// if (shouldRunPub) {
1931+
/// await regeneratePlatformSpecificTooling(project);
1932+
/// }
1933+
/// ```
1934+
///
1935+
/// See also:
1936+
///
1937+
/// - <https://github.com/flutter/flutter/issues/162649>.
1938+
@protected
1939+
@nonVirtual
1940+
Future<void> regeneratePlatformSpecificToolingIfApplicable(
1941+
FlutterProject project, {
1942+
bool? releaseMode,
1943+
}) async {
1944+
if (!shouldRunPub) {
1945+
return;
1946+
}
1947+
1948+
// TODO(matanlurey): Determine if PreviewDevice should be kept.
1949+
// https://github.com/flutter/flutter/issues/162693
1950+
final List<String>? allowedPlugins;
1951+
if (stringArg(FlutterGlobalOptions.kDeviceIdOption, global: true) == 'preview') {
1952+
// The preview device does not currently support any plugins.
1953+
allowedPlugins = PreviewDevice.supportedPubPlugins;
1954+
} else {
1955+
// null means all plugins are allowed
1956+
allowedPlugins = null;
1957+
}
1958+
1959+
await project.regeneratePlatformSpecificTooling(
1960+
allowedPlugins: allowedPlugins,
1961+
// TODO(matanlurey): Move this up, i.e. releaseMode ??= getBuildMode().release.
1962+
//
1963+
// As it stands, this is a breaking change until https://github.com/flutter/flutter/issues/162704 is
1964+
// implemented, as the build_ios_framework command (and similar) will start querying
1965+
// for getBuildMode(), causing an error (meta-build commands like build ios-framework do not have
1966+
// a single build mode). Once ios-framework and macos-framework are migrated, then this can be
1967+
// cleaned up.
1968+
releaseMode:
1969+
featureFlags.isExplicitPackageDependenciesEnabled &&
1970+
(releaseMode ?? getBuildMode().isRelease),
1971+
);
1972+
}
1973+
19211974
Future<void> _sendNullSafetyAnalyticsEvents(FlutterProject project) async {
19221975
final BuildInfo buildInfo = await getBuildInfo();
19231976
NullSafetyAnalysisEvent(

0 commit comments

Comments
 (0)