Skip to content

Commit 6a4dd4c

Browse files
authored
Skip linking on Flutter for CocoaPods transitive dependencies (#78592)
1 parent 197b440 commit 6a4dd4c

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

dev/devicelab/bin/tasks/build_ios_framework_module_test.dart

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Future<void> _testBuildIosFramework(Directory projectDir, { bool isModule = fals
6666
String content = pubspec.readAsStringSync();
6767
content = content.replaceFirst(
6868
'\ndependencies:\n',
69-
'\ndependencies:\n device_info: 0.4.1\n package_info: 0.4.0+9\n',
69+
'\ndependencies:\n device_info: 0.4.1\n package_info: 0.4.0+9\n connectivity: 3.0.3\n',
7070
);
7171
pubspec.writeAsStringSync(content, flush: true);
7272
await inDirectory(projectDir, () async {
@@ -284,6 +284,21 @@ Future<void> _testBuildIosFramework(Directory projectDir, { bool isModule = fals
284284
'device_info',
285285
);
286286
await _checkBitcode(pluginFrameworkPath, mode);
287+
if (!await _linksOnFlutter(pluginFrameworkPath)) {
288+
throw TaskResult.failure('$pluginFrameworkPath does not link on Flutter');
289+
}
290+
291+
final String transitiveDependencyFrameworkPath = path.join(
292+
outputPath,
293+
mode,
294+
'Reachability.xcframework',
295+
localXcodeArmDirectoryName,
296+
'Reachability.framework',
297+
'Reachability',
298+
);
299+
if (await _linksOnFlutter(transitiveDependencyFrameworkPath)) {
300+
throw TaskResult.failure('Transitive dependency $transitiveDependencyFrameworkPath unexpectedly links on Flutter');
301+
}
287302

288303
checkFileExists(path.join(
289304
outputPath,
@@ -407,6 +422,18 @@ Future<void> _testBuildIosFramework(Directory projectDir, { bool isModule = fals
407422
mode,
408423
'package_info.xcframework',
409424
));
425+
426+
checkDirectoryExists(path.join(
427+
cocoapodsOutputPath,
428+
mode,
429+
'connectivity.xcframework',
430+
));
431+
432+
checkDirectoryExists(path.join(
433+
cocoapodsOutputPath,
434+
mode,
435+
'Reachability.xcframework',
436+
));
410437
}
411438

412439
if (File(path.join(
@@ -443,3 +470,13 @@ Future<String> _dylibSymbols(String pathToDylib) {
443470
'arm64',
444471
]);
445472
}
473+
474+
Future<bool> _linksOnFlutter(String pathToBinary) async {
475+
final String loadCommands = await eval('otool', <String>[
476+
'-l',
477+
'-arch',
478+
'arm64',
479+
pathToBinary,
480+
]);
481+
return loadCommands.contains('Flutter.framework');
482+
}

packages/flutter_tools/bin/podhelper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def flutter_macos_podfile_setup
3333
def flutter_additional_ios_build_settings(target)
3434
return unless target.platform_name == :ios
3535

36+
# Return if it's not a Flutter plugin (transitive dependency).
37+
return unless target.dependencies.any? { |dependency| dependency.name == 'Flutter' }
38+
3639
# [target.deployment_target] is a [String] formatted as "8.0".
3740
inherit_deployment_target = target.deployment_target[/\d+/].to_i < 9
3841

@@ -78,6 +81,9 @@ def flutter_additional_ios_build_settings(target)
7881
def flutter_additional_macos_build_settings(target)
7982
return unless target.platform_name == :osx
8083

84+
# Return if it's not a Flutter plugin (transitive dependency).
85+
return unless target.dependencies.any? { |dependency| dependency.name == 'FlutterMacOS' }
86+
8187
# [target.deployment_target] is a [String] formatted as "10.8".
8288
deployment_target_major, deployment_target_minor = target.deployment_target.match(/(\d+).?(\d*)/).captures
8389

0 commit comments

Comments
 (0)