Skip to content

Commit d0a2c02

Browse files
authored
Generate a correct .flutter-plugin-dependencies file for iOS/macOS projects (#162834)
Closes flutter/flutter#162704. /cc @loic-sharma. I expect I'll have to update some iOS/macOS unit and possibly integration tests due to this change, but wanted something concrete to talk about during our 1:1. Feel free to leave comments or questions even if this PR is in "draft".
1 parent b728c4c commit d0a2c02

File tree

7 files changed

+53
-4
lines changed

7 files changed

+53
-4
lines changed

dev/devicelab/bin/tasks/build_ios_framework_module_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import 'package:path/path.dart' as path;
1313
/// Tests that iOS and macOS .xcframeworks can be built.
1414
Future<void> main() async {
1515
await task(() async {
16+
// TODO(matanlurey): Remove after default.
17+
// https://github.com/flutter/flutter/issues/160257
18+
section('Opt-in to --explicit-package-dependencies');
19+
await flutter('config', options: <String>['--explicit-package-dependencies']);
20+
1621
section('Create module project');
1722

1823
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.');

dev/devicelab/bin/tasks/module_test_ios.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import 'package:path/path.dart' as path;
1818
/// adding Flutter to an existing iOS app.
1919
Future<void> main() async {
2020
await task(() async {
21+
// TODO(matanlurey): Remove after default.
22+
// https://github.com/flutter/flutter/issues/160257
23+
section('Opt-in to --explicit-package-dependencies');
24+
await flutter('config', options: <String>['--explicit-package-dependencies']);
25+
2126
// Update pod repo.
2227
await eval(
2328
'pod',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class BuildAarCommand extends BuildSubCommand {
112112
}
113113

114114
@override
115-
bool get regeneratePlatformSpecificToolingDurifyVerify => false;
115+
bool get regeneratePlatformSpecificToolingDuringVerify => false;
116116

117117
@override
118118
Future<FlutterCommandResult> runCommand() async {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ class BuildIOSFrameworkCommand extends BuildFrameworkCommand {
238238
}
239239
}
240240

241+
@override
242+
bool get regeneratePlatformSpecificToolingDuringVerify => false;
243+
241244
@override
242245
Future<FlutterCommandResult> runCommand() async {
243246
final String outputArgument =
@@ -258,10 +261,23 @@ class BuildIOSFrameworkCommand extends BuildFrameworkCommand {
258261
final List<BuildInfo> buildInfos = await getBuildInfos();
259262
displayNullSafetyMode(buildInfos.first);
260263
for (final BuildInfo buildInfo in buildInfos) {
264+
// Create the build-mode specific metadata.
265+
//
266+
// This normally would be done in the verifyAndRun step of FlutterCommand, but special "meta"
267+
// build commands (like flutter build ios-framework) make multiple builds, and do not have a
268+
// single "buildInfo", so the step has to be done manually for each build.
269+
//
270+
// See regeneratePlatformSpecificToolingDurifyVerify.
271+
await regeneratePlatformSpecificToolingIfApplicable(
272+
project,
273+
releaseMode: buildInfo.mode.isRelease,
274+
);
275+
261276
final String? productBundleIdentifier = await project.ios.productBundleIdentifier(buildInfo);
262277
globals.printStatus(
263278
'Building frameworks for $productBundleIdentifier in ${buildInfo.mode.cliName} mode...',
264279
);
280+
265281
final String xcodeBuildConfiguration = sentenceCase(buildInfo.mode.cliName);
266282
final Directory modeDirectory = outputDirectory.childDirectory(xcodeBuildConfiguration);
267283

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class BuildMacOSFrameworkCommand extends BuildFrameworkCommand {
5050
DevelopmentArtifact.macOS,
5151
};
5252

53+
@override
54+
bool get regeneratePlatformSpecificToolingDuringVerify => false;
55+
5356
@override
5457
Future<FlutterCommandResult> runCommand() async {
5558
final String outputArgument =
@@ -73,6 +76,18 @@ class BuildMacOSFrameworkCommand extends BuildFrameworkCommand {
7376

7477
for (final BuildInfo buildInfo in buildInfos) {
7578
globals.printStatus('Building macOS frameworks in ${buildInfo.mode.cliName} mode...');
79+
// Create the build-mode specific metadata.
80+
//
81+
// This normally would be done in the verifyAndRun step of FlutterCommand, but special "meta"
82+
// build commands (like flutter build ios-framework) make multiple builds, and do not have a
83+
// single "buildInfo", so the step has to be done manually for each build.
84+
//
85+
// See regeneratePlatformSpecificToolingDurifyVerify.
86+
await regeneratePlatformSpecificToolingIfApplicable(
87+
project,
88+
releaseMode: buildInfo.mode.isRelease,
89+
);
90+
7691
final String xcodeBuildConfiguration = sentenceCase(buildInfo.mode.cliName);
7792
final Directory modeDirectory = outputDirectory.childDirectory(xcodeBuildConfiguration);
7893

packages/flutter_tools/lib/src/macos/cocoapod_utils.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import '../base/fingerprint.dart';
66
import '../build_info.dart';
77
import '../cache.dart';
8+
import '../features.dart';
89
import '../flutter_plugins.dart';
910
import '../globals.dart' as globals;
1011
import '../plugins.dart';
@@ -34,12 +35,19 @@ Future<void> processPodsIfNeeded(
3435
iosPlatform: project.ios.existsSync(),
3536
macOSPlatform: project.macos.existsSync(),
3637
forceCocoaPodsOnly: forceCocoaPodsOnly,
38+
39+
// TODO(matanlurey): Ideally processPodsIfNeeded would not be used at all, and it would definitely
40+
// not call refreshPluginsList, but until that happens (https://github.com/flutter/flutter/issues/157391)
41+
// we have to reproduce some of the work that otherwise would be handled by underlying commands, otherwise
42+
// this call to refreshPluginsList would overwrite the correct plugins list generated elsewhere.
43+
determineDevDependencies:
44+
featureFlags.isExplicitPackageDependenciesEnabled && buildMode.isRelease,
45+
3746
// TODO(matanlurey): As-per discussion on https://github.com/flutter/flutter/pull/157393
3847
// we'll assume that iOS/MacOS builds do not use or rely on the `.flutter-plugins` legacy
3948
// file being generated. A better long-term fix would be not to have a call to refreshPluginsList
4049
// at all, and instead have it implicitly run by the FlutterCommand instead. See
4150
// https://github.com/flutter/flutter/issues/157391 for details.
42-
determineDevDependencies: false,
4351
generateLegacyPlugins: false,
4452
);
4553

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
18851885
}
18861886
}
18871887

1888-
if (regeneratePlatformSpecificToolingDurifyVerify) {
1888+
if (regeneratePlatformSpecificToolingDuringVerify) {
18891889
await regeneratePlatformSpecificToolingIfApplicable(project);
18901890
}
18911891

@@ -1904,7 +1904,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
19041904
/// builds sequentially in one-go) may choose to override this and provide `false`, instead
19051905
/// calling [regeneratePlatformSpecificTooling] manually when applicable.
19061906
@visibleForOverriding
1907-
bool get regeneratePlatformSpecificToolingDurifyVerify => true;
1907+
bool get regeneratePlatformSpecificToolingDuringVerify => true;
19081908

19091909
/// Runs [FlutterProject.regeneratePlatformSpecificTooling] for [project] with appropriate configuration.
19101910
///

0 commit comments

Comments
 (0)