Make releaseMode explicit, inform determineDevDependencies entirely on the flag (#163780)

Closes https://github.com/flutter/flutter/issues/163770.

This simplifies understanding "when I called function X, how is it
determining release mode and/or dev-dependencies?"

AFAICT, at HEAD, this is a NOP (will let integration tests run), but
would have avoided cases such as
https://github.com/flutter/flutter/issues/163706.
This commit is contained in:
Matan Lurey
2025-02-20 16:07:48 -08:00
committed by GitHub
parent 0f586af401
commit f6543c3d45
10 changed files with 101 additions and 72 deletions

View File

@@ -522,7 +522,16 @@ class CreateCommand extends FlutterCommand with CreateBase {
// TODO(dacoharkes): Uncouple the app and parent project platforms. https://github.com/flutter/flutter/issues/133874
// Then this if can be removed.
if (!generateFfiPackage) {
// TODO(matanlurey): https://github.com/flutter/flutter/issues/163774.
//
// `flutter packages get` inherently is neither a debug or release build,
// and since a future build (`flutter build apk`) will regenerate tooling
// anyway, we assume this is fine.
//
// It won't be if they do `flutter build --no-pub`, though.
const bool ignoreReleaseModeSinceItsNotABuildAndHopeItWorks = false;
await project.ensureReadyForPlatformSpecificTooling(
releaseMode: ignoreReleaseModeSinceItsNotABuildAndHopeItWorks,
androidPlatform: includeAndroid,
iosPlatform: includeIos,
linuxPlatform: includeLinux,

View File

@@ -370,12 +370,25 @@ class PackagesGetCommand extends FlutterCommand {
}
if (rootProject != null) {
// TODO(matanlurey): https://github.com/flutter/flutter/issues/163774.
//
// `flutter packages get` inherently is neither a debug or release build,
// and since a future build (`flutter build apk`) will regenerate tooling
// anyway, we assume this is fine.
//
// It won't be if they do `flutter build --no-pub`, though.
const bool ignoreReleaseModeSinceItsNotABuildAndHopeItWorks = false;
// We need to regenerate the platform specific tooling for both the project
// itself and example(if present).
await rootProject.regeneratePlatformSpecificTooling();
await rootProject.regeneratePlatformSpecificTooling(
releaseMode: ignoreReleaseModeSinceItsNotABuildAndHopeItWorks,
);
if (example && rootProject.hasExampleApp && rootProject.example.pubspecFile.existsSync()) {
final FlutterProject exampleProject = rootProject.example;
await exampleProject.regeneratePlatformSpecificTooling();
await exampleProject.regeneratePlatformSpecificTooling(
releaseMode: ignoreReleaseModeSinceItsNotABuildAndHopeItWorks,
);
}
}

View File

@@ -300,6 +300,7 @@ final class WidgetPreviewStartCommand extends WidgetPreviewSubCommandBase with C
Future<void> initialBuild({required FlutterProject widgetPreviewScaffoldProject}) async {
// TODO(bkonyi): handle error case where desktop device isn't enabled.
await widgetPreviewScaffoldProject.ensureReadyForPlatformSpecificTooling(
releaseMode: false,
linuxPlatform: platform.isLinux && !isWeb,
macOSPlatform: platform.isMacOS && !isWeb,
windowsPlatform: platform.isWindows && !isWeb,

View File

@@ -89,12 +89,7 @@ Future<Plugin?> _pluginFromPackage(
/// Returns a list of all plugins to be registered with the provided [project].
///
/// If [throwOnError] is `true`, an empty package configuration is an error.
Future<List<Plugin>> findPlugins(
FlutterProject project, {
bool throwOnError = true,
bool? determineDevDependencies,
}) async {
determineDevDependencies ??= featureFlags.isExplicitPackageDependenciesEnabled;
Future<List<Plugin>> findPlugins(FlutterProject project, {bool throwOnError = true}) async {
final List<Plugin> plugins = <Plugin>[];
final FileSystem fs = project.directory.fileSystem;
final File packageConfigFile = findPackageConfigFileOrDefault(project.directory);
@@ -104,7 +99,7 @@ Future<List<Plugin>> findPlugins(
throwOnError: throwOnError,
);
final Set<String> devDependencies;
if (!determineDevDependencies) {
if (!featureFlags.isExplicitPackageDependenciesEnabled) {
devDependencies = <String>{};
} else {
devDependencies = await computeExclusiveDevDependencies(
@@ -1105,13 +1100,9 @@ Future<void> refreshPluginsList(
bool iosPlatform = false,
bool macOSPlatform = false,
bool forceCocoaPodsOnly = false,
bool? determineDevDependencies,
bool? generateLegacyPlugins,
}) async {
final List<Plugin> plugins = await findPlugins(
project,
determineDevDependencies: determineDevDependencies,
);
final List<Plugin> plugins = await findPlugins(project);
// Sort the plugins by name to keep ordering stable in generated files.
plugins.sort((Plugin left, Plugin right) => left.name.compareTo(right.name));
// TODO(matanlurey): Remove once migration is complete.
@@ -1188,19 +1179,23 @@ Future<void> injectBuildTimePluginFilesForWebPlatform(
/// current build (temp) directory, and doesn't modify the users' working copy.
///
/// Assumes [refreshPluginsList] has been called since last change to `pubspec.yaml`.
///
/// If [releaseMode] is `true`, platform-specific tooling and metadata generated
/// may apply optimizations or changes that are only specific to release builds,
/// such as not including dev-only dependencies.
Future<void> injectPlugins(
FlutterProject project, {
required bool releaseMode,
bool androidPlatform = false,
bool iosPlatform = false,
bool linuxPlatform = false,
bool macOSPlatform = false,
bool windowsPlatform = false,
DarwinDependencyManagement? darwinDependencyManagement,
bool? releaseMode,
}) async {
List<Plugin> plugins = await findPlugins(project);
if (releaseMode ?? false) {
if (releaseMode) {
plugins = plugins.where((Plugin p) => !p.isDevDependency).toList();
}

View File

@@ -5,7 +5,6 @@
import '../base/fingerprint.dart';
import '../build_info.dart';
import '../cache.dart';
import '../features.dart';
import '../flutter_plugins.dart';
import '../globals.dart' as globals;
import '../plugins.dart';
@@ -36,13 +35,6 @@ Future<void> processPodsIfNeeded(
macOSPlatform: project.macos.existsSync(),
forceCocoaPodsOnly: forceCocoaPodsOnly,
// TODO(matanlurey): Ideally processPodsIfNeeded would not be used at all, and it would definitely
// not call refreshPluginsList, but until that happens (https://github.com/flutter/flutter/issues/157391)
// we have to reproduce some of the work that otherwise would be handled by underlying commands, otherwise
// this call to refreshPluginsList would overwrite the correct plugins list generated elsewhere.
determineDevDependencies:
featureFlags.isExplicitPackageDependenciesEnabled && buildMode.isRelease,
// TODO(matanlurey): As-per discussion on https://github.com/flutter/flutter/pull/157393
// we'll assume that iOS/MacOS builds do not use or rely on the `.flutter-plugins` legacy
// file being generated. A better long-term fix would be not to have a call to refreshPluginsList

View File

@@ -325,9 +325,13 @@ class FlutterProject {
/// registrants for app and module projects only.
///
/// Will not create project platform directories if they do not already exist.
///
/// If [releaseMode] is `true`, platform-specific tooling and metadata generated
/// may apply optimizations or changes that are only specific to release builds,
/// such as not including dev-only dependencies.
Future<void> regeneratePlatformSpecificTooling({
DeprecationBehavior deprecationBehavior = DeprecationBehavior.none,
bool? releaseMode,
required bool releaseMode,
}) async {
return ensureReadyForPlatformSpecificTooling(
androidPlatform: android.existsSync(),
@@ -345,7 +349,12 @@ class FlutterProject {
/// Applies template files and generates project files and plugin
/// registrants for app and module projects only for the specified platforms.
///
/// If [releaseMode] is `true`, platform-specific tooling and metadata generated
/// may apply optimizations or changes that are only specific to release builds,
/// such as not including dev-only dependencies.
Future<void> ensureReadyForPlatformSpecificTooling({
required bool releaseMode,
bool androidPlatform = false,
bool iosPlatform = false,
bool linuxPlatform = false,
@@ -353,7 +362,6 @@ class FlutterProject {
bool windowsPlatform = false,
bool webPlatform = false,
DeprecationBehavior deprecationBehavior = DeprecationBehavior.none,
bool? releaseMode,
}) async {
if (!directory.existsSync() || isPlugin) {
return;

View File

@@ -1851,7 +1851,10 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
}
if (regeneratePlatformSpecificToolingDuringVerify) {
await regeneratePlatformSpecificToolingIfApplicable(project);
await regeneratePlatformSpecificToolingIfApplicable(
project,
releaseMode: getBuildMode().isRelease,
);
}
setupApplicationPackages();
@@ -1873,10 +1876,6 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
/// Runs [FlutterProject.regeneratePlatformSpecificTooling] for [project] with appropriate configuration.
///
/// By default, this uses [getBuildMode] to determine and provide whether a release build is being made,
/// but sub-commands (such as commands that do _meta_ builds, or builds that make multiple different builds
/// sequentially in one-go) may choose to overide this and make the call at a different point in time.
///
/// This method should only be called when [shouldRunPub] is `true`:
/// ```dart
/// if (shouldRunPub) {
@@ -1891,13 +1890,11 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
@nonVirtual
Future<void> regeneratePlatformSpecificToolingIfApplicable(
FlutterProject project, {
bool? releaseMode,
required bool releaseMode,
}) async {
if (!shouldRunPub) {
return;
}
releaseMode ??= getBuildMode().isRelease;
await project.regeneratePlatformSpecificTooling(
releaseMode: featureFlags.isExplicitPackageDependenciesEnabled && releaseMode,
);