build_ios_framework_module_test.dart 21.4 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
xster's avatar
xster committed
2 3 4 5 6 7
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:flutter_devicelab/framework/framework.dart';
8
import 'package:flutter_devicelab/framework/ios.dart';
9
import 'package:flutter_devicelab/framework/task_result.dart';
xster's avatar
xster committed
10 11 12
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:path/path.dart' as path;

13
/// Tests that iOS and macOS .xcframeworks can be built.
xster's avatar
xster committed
14 15 16 17 18 19 20 21
Future<void> main() async {
  await task(() async {

    section('Create module project');

    final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.');
    try {
      await inDirectory(tempDir, () async {
22
        section('Test iOS module template');
23

24 25
        final Directory moduleProjectDir =
            Directory(path.join(tempDir.path, 'hello_module'));
26
        await flutter(
27
          'create',
28
          options: <String>[
29 30 31 32
            '--org',
            'io.flutter.devicelab',
            '--template',
            'module',
33
            'hello_module',
34 35 36
          ],
        );

37
        await _addPlugin(moduleProjectDir);
38
        await _testBuildIosFramework(moduleProjectDir, isModule: true);
xster's avatar
xster committed
39

40
        section('Test app template');
41

42 43
        final Directory projectDir =
            Directory(path.join(tempDir.path, 'hello_project'));
xster's avatar
xster committed
44
        await flutter(
45 46
          'create',
          options: <String>['--org', 'io.flutter.devicelab', 'hello_project'],
47 48
        );

49
        await _addPlugin(projectDir);
50
        await _testBuildIosFramework(projectDir);
51
        await _testBuildMacOSFramework(projectDir);
52
      });
53

54 55 56 57 58 59
      return TaskResult.success(null);
    } on TaskResult catch (taskResult) {
      return taskResult;
    } catch (e) {
      return TaskResult.failure(e.toString());
    } finally {
60
      rmTree(tempDir);
61 62 63
    }
  });
}
64

65
Future<void> _addPlugin(Directory projectDir) async {
66 67 68 69 70 71
  section('Add plugins');

  final File pubspec = File(path.join(projectDir.path, 'pubspec.yaml'));
  String content = pubspec.readAsStringSync();
  content = content.replaceFirst(
    '\ndependencies:\n',
72
    '\ndependencies:\n  package_info: 2.0.2\n  connectivity: 3.0.6\n',
73 74 75 76 77 78 79 80
  );
  pubspec.writeAsStringSync(content, flush: true);
  await inDirectory(projectDir, () async {
    await flutter(
      'packages',
      options: <String>['get'],
    );
  });
81
}
82

83
Future<void> _testBuildIosFramework(Directory projectDir, { bool isModule = false}) async {
84
  // This builds all build modes' frameworks by default
85
  section('Build iOS app');
86

87
  const String outputDirectoryName = 'flutter-frameworks';
88

89
  await inDirectory(projectDir, () async {
90 91
    final StringBuffer outputError = StringBuffer();
    await evalFlutter(
92 93 94
      'build',
      options: <String>[
        'ios-framework',
95
        '--verbose',
96 97 98
        '--output=$outputDirectoryName',
        '--obfuscate',
        '--split-debug-info=symbols',
99
      ],
100
      stderr: outputError,
101
    );
102 103 104
    if (!outputError.toString().contains('Bitcode support has been deprecated.')) {
      throw TaskResult.failure('Missing bitcode deprecation warning');
    }
105
  });
106

107 108
  final String outputPath = path.join(projectDir.path, outputDirectoryName);

109
  checkFileExists(path.join(
110 111 112 113 114
    outputPath,
    'Debug',
    'Flutter.xcframework',
    'ios-arm64',
    'Flutter.framework',
115 116
    'Flutter',
  ));
117

118 119 120 121
  final String debugAppFrameworkPath = path.join(
    outputPath,
    'Debug',
    'App.xcframework',
122
    'ios-arm64',
123 124 125 126 127
    'App.framework',
    'App',
  );
  checkFileExists(debugAppFrameworkPath);

128 129 130 131
  checkFileExists(path.join(
    outputPath,
    'Debug',
    'App.xcframework',
132
    'ios-arm64',
133 134 135 136
    'App.framework',
    'Info.plist',
  ));

137 138
  section('Check debug build has Dart snapshot as asset');

139 140 141 142
  checkFileExists(path.join(
    outputPath,
    'Debug',
    'App.xcframework',
143
    'ios-arm64_x86_64-simulator',
144
    'App.framework',
145 146
    'flutter_assets',
    'vm_snapshot_data',
147 148
  ));

149 150 151 152 153 154 155 156
  section('Check obfuscation symbols');

  checkFileExists(path.join(
    projectDir.path,
    'symbols',
    'app.ios-arm64.symbols',
  ));

157 158
  section('Check debug build has no Dart AOT');

159
  final String aotSymbols = await _dylibSymbols(debugAppFrameworkPath);
160 161 162 163 164 165

  if (aotSymbols.contains('architecture') ||
      aotSymbols.contains('_kDartVmSnapshot')) {
    throw TaskResult.failure('Debug App.framework contains AOT');
  }

166 167 168 169 170 171
  section('Check profile, release builds has Dart AOT dylib');

  for (final String mode in <String>['Profile', 'Release']) {
    final String appFrameworkPath = path.join(
      outputPath,
      mode,
172
      'App.xcframework',
173
      'ios-arm64',
174 175 176 177
      'App.framework',
      'App',
    );

178
    await _checkDylib(appFrameworkPath);
179

180
    final String aotSymbols = await _dylibSymbols(appFrameworkPath);
181 182 183 184

    if (!aotSymbols.contains('_kDartVmSnapshot')) {
      throw TaskResult.failure('$mode App.framework missing Dart AOT');
    }
185

186 187 188 189
    checkFileNotExists(path.join(
      outputPath,
      mode,
      'App.xcframework',
190
      'ios-arm64',
191
      'App.framework',
192 193
      'flutter_assets',
      'vm_snapshot_data',
194 195
    ));

196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    final String appFrameworkDsymPath = path.join(
      outputPath,
      mode,
      'App.xcframework',
      'ios-arm64',
      'dSYMs',
      'App.framework.dSYM'
    );
    checkDirectoryExists(appFrameworkDsymPath);
    await _checkDsym(path.join(
      appFrameworkDsymPath,
      'Contents',
      'Resources',
      'DWARF',
      'App',
    ));

213
    checkFileExists(path.join(
214 215 216
      outputPath,
      mode,
      'App.xcframework',
217
      'ios-arm64_x86_64-simulator',
218 219 220
      'App.framework',
      'App',
    ));
221 222 223 224 225

    checkFileExists(path.join(
      outputPath,
      mode,
      'App.xcframework',
226
      'ios-arm64_x86_64-simulator',
227 228 229
      'App.framework',
      'Info.plist',
    ));
230 231 232 233 234
  }

  section("Check all modes' engine dylib");

  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
235
    checkFileExists(path.join(
236 237 238 239 240 241
      outputPath,
      mode,
      'Flutter.xcframework',
      'ios-arm64',
      'Flutter.framework',
      'Flutter',
242
    ));
243

244
    checkFileExists(path.join(
245 246 247
      outputPath,
      mode,
      'Flutter.xcframework',
248
      'ios-arm64_x86_64-simulator',
249
      'Flutter.framework',
250 251
      'Flutter',
    ));
252

253
    checkFileExists(path.join(
254 255 256
      outputPath,
      mode,
      'Flutter.xcframework',
257
      'ios-arm64_x86_64-simulator',
258
      'Flutter.framework',
259 260 261
      'Headers',
      'Flutter.h',
    ));
262 263 264 265 266 267 268 269
  }

  section('Check all modes have plugins');

  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    final String pluginFrameworkPath = path.join(
      outputPath,
      mode,
270
      'connectivity.xcframework',
271
      'ios-arm64',
272 273
      'connectivity.framework',
      'connectivity',
274
    );
275 276

    await _checkDylib(pluginFrameworkPath);
277 278 279 280
    if (!await _linksOnFlutter(pluginFrameworkPath)) {
      throw TaskResult.failure('$pluginFrameworkPath does not link on Flutter');
    }

281
    // TODO(jmagman): Remove ios-arm64_armv7 checks when CI is updated to Xcode 14.
282
    final String transitiveDependencyFrameworkPath = path.join(
283 284 285 286 287 288 289 290 291
      outputPath,
      mode,
      'Reachability.xcframework',
      'ios-arm64',
      'Reachability.framework',
      'Reachability',
    );

    final String armv7TransitiveDependencyFrameworkPath = path.join(
292 293 294
      outputPath,
      mode,
      'Reachability.xcframework',
295
      'ios-arm64_armv7',
296 297 298
      'Reachability.framework',
      'Reachability',
    );
299 300 301 302 303 304 305 306 307 308 309

    final bool transitiveDependencyExists = exists(File(transitiveDependencyFrameworkPath));
    final bool armv7TransitiveDependencyExists = exists(File(armv7TransitiveDependencyFrameworkPath));
    if (!transitiveDependencyExists && !armv7TransitiveDependencyExists) {
      throw TaskResult.failure('Expected debug Flutter engine artifact binary to exist');
    }

    if ((transitiveDependencyExists && await _linksOnFlutter(transitiveDependencyFrameworkPath)) ||
        (armv7TransitiveDependencyExists && await _linksOnFlutter(armv7TransitiveDependencyFrameworkPath))) {
      throw TaskResult.failure(
          'Transitive dependency $transitiveDependencyFrameworkPath unexpectedly links on Flutter');
310
    }
311 312 313 314

    checkFileExists(path.join(
      outputPath,
      mode,
315
      'connectivity.xcframework',
316
      'ios-arm64',
317
      'connectivity.framework',
318
      'Headers',
319
      'FLTConnectivityPlugin.h',
320 321
    ));

322 323 324 325
    if (mode != 'Debug') {
      checkDirectoryExists(path.join(
        outputPath,
        mode,
326
        'connectivity.xcframework',
327
        'ios-arm64',
328
        'dSYMs',
329
        'connectivity.framework.dSYM',
330 331 332
      ));
    }

333 334 335
    final String simulatorFrameworkPath = path.join(
      outputPath,
      mode,
336
      'connectivity.xcframework',
337
      'ios-arm64_x86_64-simulator',
338 339
      'connectivity.framework',
      'connectivity',
340 341 342 343 344
    );

    final String simulatorFrameworkHeaderPath = path.join(
      outputPath,
      mode,
345
      'connectivity.xcframework',
346
      'ios-arm64_x86_64-simulator',
347
      'connectivity.framework',
348
      'Headers',
349
      'FLTConnectivityPlugin.h',
350 351
    );

352 353
    checkFileExists(simulatorFrameworkPath);
    checkFileExists(simulatorFrameworkHeaderPath);
354
  }
355

356
  section('Check all modes have generated plugin registrant');
357

358 359 360 361 362 363 364
  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    if (!isModule) {
      continue;
    }
    final String registrantFrameworkPath = path.join(
      outputPath,
      mode,
365
      'FlutterPluginRegistrant.xcframework',
366
      'ios-arm64',
367
      'FlutterPluginRegistrant.framework',
368
      'FlutterPluginRegistrant',
369
    );
370
    await _checkStatic(registrantFrameworkPath);
371 372 373 374 375

    checkFileExists(path.join(
      outputPath,
      mode,
      'FlutterPluginRegistrant.xcframework',
376
      'ios-arm64',
377 378 379 380 381 382 383 384
      'FlutterPluginRegistrant.framework',
      'Headers',
      'GeneratedPluginRegistrant.h',
    ));
    final String simulatorHeaderPath = path.join(
      outputPath,
      mode,
      'FlutterPluginRegistrant.xcframework',
385
      'ios-arm64_x86_64-simulator',
386 387 388 389
      'FlutterPluginRegistrant.framework',
      'Headers',
      'GeneratedPluginRegistrant.h',
    );
390
    checkFileExists(simulatorHeaderPath);
391 392 393
  }

  // This builds all build modes' frameworks by default
394
  section('Build podspec and static plugins');
395 396 397 398 399 400 401 402 403 404

  const String cocoapodsOutputDirectoryName = 'flutter-frameworks-cocoapods';

  await inDirectory(projectDir, () async {
    await flutter(
      'build',
      options: <String>[
        'ios-framework',
        '--cocoapods',
        '--force', // Allow podspec creation on master.
405
        '--output=$cocoapodsOutputDirectoryName',
406
        '--static',
407 408 409
      ],
    );
  });
410

411 412 413 414 415 416 417
  final String cocoapodsOutputPath = path.join(projectDir.path, cocoapodsOutputDirectoryName);
  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    checkFileExists(path.join(
      cocoapodsOutputPath,
      mode,
      'Flutter.podspec',
    ));
418
    await _checkDylib(path.join(
419 420
      cocoapodsOutputPath,
      mode,
421
      'App.xcframework',
422 423 424
      'ios-arm64',
      'App.framework',
      'App',
425 426
    ));

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
    if (mode != 'Debug') {
      final String appFrameworkDsymPath = path.join(
        cocoapodsOutputPath,
        mode,
        'App.xcframework',
        'ios-arm64',
        'dSYMs',
        'App.framework.dSYM'
      );
      checkDirectoryExists(appFrameworkDsymPath);
      await _checkDsym(path.join(
        appFrameworkDsymPath,
        'Contents',
        'Resources',
        'DWARF',
        'App',
      ));
    }

446
    if (Directory(path.join(
447 448
          cocoapodsOutputPath,
          mode,
449
          'FlutterPluginRegistrant.xcframework',
450 451 452
        )).existsSync() !=
        isModule) {
      throw TaskResult.failure(
453
          'Unexpected FlutterPluginRegistrant.xcframework.');
454
    }
455

456
    await _checkStatic(path.join(
457 458
      cocoapodsOutputPath,
      mode,
459
      'package_info.xcframework',
460 461 462
      'ios-arm64',
      'package_info.framework',
      'package_info',
463
    ));
464

465
    await _checkStatic(path.join(
466 467 468
      cocoapodsOutputPath,
      mode,
      'connectivity.xcframework',
469 470 471
      'ios-arm64',
      'connectivity.framework',
      'connectivity',
472 473 474 475 476 477 478
    ));

    checkDirectoryExists(path.join(
      cocoapodsOutputPath,
      mode,
      'Reachability.xcframework',
    ));
479
  }
480

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
  if (File(path.join(
        outputPath,
        'GeneratedPluginRegistrant.h',
      )).existsSync() ==
      isModule) {
    throw TaskResult.failure('Unexpected GeneratedPluginRegistrant.h.');
  }

  if (File(path.join(
        outputPath,
        'GeneratedPluginRegistrant.m',
      )).existsSync() ==
      isModule) {
    throw TaskResult.failure('Unexpected GeneratedPluginRegistrant.m.');
  }
xster's avatar
xster committed
496
}
497

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623

Future<void> _testBuildMacOSFramework(Directory projectDir) async {
  // This builds all build modes' frameworks by default
  section('Build macOS frameworks');

  const String outputDirectoryName = 'flutter-frameworks';

  await inDirectory(projectDir, () async {
    await flutter(
      'build',
      options: <String>[
        'macos-framework',
        '--verbose',
        '--output=$outputDirectoryName',
        '--obfuscate',
        '--split-debug-info=symbols',
      ],
    );
  });

  final String outputPath = path.join(projectDir.path, outputDirectoryName);
  final String flutterFramework = path.join(
    outputPath,
    'Debug',
    'FlutterMacOS.xcframework',
    'macos-arm64_x86_64',
    'FlutterMacOS.framework',
  );
  checkDirectoryExists(flutterFramework);

  final String debugAppFrameworkPath = path.join(
    outputPath,
    'Debug',
    'App.xcframework',
    'macos-arm64_x86_64',
    'App.framework',
    'App',
  );
  checkSymlinkExists(debugAppFrameworkPath);

  checkFileExists(path.join(
    outputPath,
    'Debug',
    'App.xcframework',
    'macos-arm64_x86_64',
    'App.framework',
    'Resources',
    'Info.plist',
  ));

  section('Check debug build has Dart snapshot as asset');

  checkFileExists(path.join(
    outputPath,
    'Debug',
    'App.xcframework',
    'macos-arm64_x86_64',
    'App.framework',
    'Resources',
    'flutter_assets',
    'vm_snapshot_data',
  ));

  section('Check obfuscation symbols');

  checkFileExists(path.join(
    projectDir.path,
    'symbols',
    'app.darwin-arm64.symbols',
  ));

  checkFileExists(path.join(
    projectDir.path,
    'symbols',
    'app.darwin-x86_64.symbols',
  ));

  section('Check debug build has no Dart AOT');

  final String aotSymbols = await _dylibSymbols(debugAppFrameworkPath);

  if (aotSymbols.contains('architecture') ||
      aotSymbols.contains('_kDartVmSnapshot')) {
    throw TaskResult.failure('Debug App.framework contains AOT');
  }

  section('Check profile, release builds has Dart AOT dylib');

  for (final String mode in <String>['Profile', 'Release']) {
    final String appFrameworkPath = path.join(
      outputPath,
      mode,
      'App.xcframework',
      'macos-arm64_x86_64',
      'App.framework',
      'App',
    );

    await _checkDylib(appFrameworkPath);

    final String aotSymbols = await _dylibSymbols(appFrameworkPath);

    if (!aotSymbols.contains('_kDartVmSnapshot')) {
      throw TaskResult.failure('$mode App.framework missing Dart AOT');
    }

    checkFileNotExists(path.join(
      outputPath,
      mode,
      'App.xcframework',
      'macos-arm64_x86_64',
      'App.framework',
      'Resources',
      'flutter_assets',
      'vm_snapshot_data',
    ));

    checkFileExists(path.join(
      outputPath,
      mode,
      'App.xcframework',
      'macos-arm64_x86_64',
      'App.framework',
      'Resources',
      'Info.plist',
    ));
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640

    final String appFrameworkDsymPath = path.join(
      outputPath,
      mode,
      'App.xcframework',
      'macos-arm64_x86_64',
      'dSYMs',
      'App.framework.dSYM'
    );
    checkDirectoryExists(appFrameworkDsymPath);
    await _checkDsym(path.join(
      appFrameworkDsymPath,
      'Contents',
      'Resources',
      'DWARF',
      'App',
    ));
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
  }

  section("Check all modes' engine dylib");

  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    final String engineBinary = path.join(
      outputPath,
      mode,
      'FlutterMacOS.xcframework',
      'macos-arm64_x86_64',
      'FlutterMacOS.framework',
      'FlutterMacOS',
    );
    checkSymlinkExists(engineBinary);

    checkFileExists(path.join(
      outputPath,
      mode,
      'FlutterMacOS.xcframework',
      'macos-arm64_x86_64',
      'FlutterMacOS.framework',
      'Headers',
      'FlutterMacOS.h',
    ));
  }

  section('Check all modes have plugins');

  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    final String pluginFrameworkPath = path.join(
      outputPath,
      mode,
      'connectivity_macos.xcframework',
      'macos-arm64_x86_64',
      'connectivity_macos.framework',
      'connectivity_macos',
    );

    await _checkDylib(pluginFrameworkPath);
    if (!await _linksOnFlutterMacOS(pluginFrameworkPath)) {
      throw TaskResult.failure('$pluginFrameworkPath does not link on Flutter');
    }

    final String transitiveDependencyFrameworkPath = path.join(
      outputPath,
      mode,
      'Reachability.xcframework',
      'macos-arm64_x86_64',
      'Reachability.framework',
      'Reachability',
    );
    if (await _linksOnFlutterMacOS(transitiveDependencyFrameworkPath)) {
      throw TaskResult.failure('Transitive dependency $transitiveDependencyFrameworkPath unexpectedly links on Flutter');
    }

    checkFileExists(path.join(
      outputPath,
      mode,
      'connectivity_macos.xcframework',
      'macos-arm64_x86_64',
      'connectivity_macos.framework',
      'Headers',
      'connectivity_macos-Swift.h',
    ));

    checkDirectoryExists(path.join(
      outputPath,
      mode,
      'connectivity_macos.xcframework',
      'macos-arm64_x86_64',
      'connectivity_macos.framework',
      'Modules',
      'connectivity_macos.swiftmodule',
    ));

    if (mode != 'Debug') {
      checkDirectoryExists(path.join(
        outputPath,
        mode,
        'connectivity_macos.xcframework',
        'macos-arm64_x86_64',
        'dSYMs',
        'connectivity_macos.framework.dSYM',
      ));
    }

    checkSymlinkExists(path.join(
      outputPath,
      mode,
      'connectivity_macos.xcframework',
      'macos-arm64_x86_64',
      'connectivity_macos.framework',
      'connectivity_macos',
    ));
  }

  // This builds all build modes' frameworks by default
  section('Build podspec and static plugins');

  const String cocoapodsOutputDirectoryName = 'flutter-frameworks-cocoapods';

  await inDirectory(projectDir, () async {
    await flutter(
      'build',
      options: <String>[
        'macos-framework',
        '--cocoapods',
        '--force', // Allow podspec creation on master.
        '--output=$cocoapodsOutputDirectoryName',
        '--static',
      ],
    );
  });

  final String cocoapodsOutputPath = path.join(projectDir.path, cocoapodsOutputDirectoryName);
  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    checkFileExists(path.join(
      cocoapodsOutputPath,
      mode,
      'FlutterMacOS.podspec',
    ));
    await _checkDylib(path.join(
      cocoapodsOutputPath,
      mode,
      'App.xcframework',
      'macos-arm64_x86_64',
      'App.framework',
      'App',
    ));

771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
    if (mode != 'Debug') {
      final String appFrameworkDsymPath = path.join(
        cocoapodsOutputPath,
        mode,
        'App.xcframework',
        'macos-arm64_x86_64',
        'dSYMs',
        'App.framework.dSYM'
      );
      checkDirectoryExists(appFrameworkDsymPath);
      await _checkDsym(path.join(
        appFrameworkDsymPath,
        'Contents',
        'Resources',
        'DWARF',
        'App',
      ));
    }

790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
    await _checkStatic(path.join(
      cocoapodsOutputPath,
      mode,
      'package_info.xcframework',
      'macos-arm64_x86_64',
      'package_info.framework',
      'package_info',
    ));

    await _checkStatic(path.join(
      cocoapodsOutputPath,
      mode,
      'connectivity_macos.xcframework',
      'macos-arm64_x86_64',
      'connectivity_macos.framework',
      'connectivity_macos',
    ));

    checkDirectoryExists(path.join(
      cocoapodsOutputPath,
      mode,
      'Reachability.xcframework',
    ));
  }

  checkFileExists(path.join(
    outputPath,
    'GeneratedPluginRegistrant.swift',
  ));
}

821 822 823 824 825 826 827
Future<void> _checkDylib(String pathToLibrary) async {
  final String binaryFileType = await fileType(pathToLibrary);
  if (!binaryFileType.contains('dynamically linked')) {
    throw TaskResult.failure('$pathToLibrary is not a dylib, found: $binaryFileType');
  }
}

828 829 830 831 832 833 834
Future<void> _checkDsym(String pathToSymbolFile) async {
  final String binaryFileType = await fileType(pathToSymbolFile);
  if (!binaryFileType.contains('dSYM companion file')) {
    throw TaskResult.failure('$pathToSymbolFile is not a dSYM, found: $binaryFileType');
  }
}

835 836 837 838 839 840 841
Future<void> _checkStatic(String pathToLibrary) async {
  final String binaryFileType = await fileType(pathToLibrary);
  if (!binaryFileType.contains('current ar archive random library')) {
    throw TaskResult.failure('$pathToLibrary is not a static library, found: $binaryFileType');
  }
}

842 843 844 845 846 847 848 849
Future<String> _dylibSymbols(String pathToDylib) {
  return eval('nm', <String>[
    '-g',
    pathToDylib,
    '-arch',
    'arm64',
  ]);
}
850 851 852 853 854 855 856 857 858 859

Future<bool> _linksOnFlutter(String pathToBinary) async {
  final String loadCommands = await eval('otool', <String>[
    '-l',
    '-arch',
    'arm64',
    pathToBinary,
  ]);
  return loadCommands.contains('Flutter.framework');
}
860 861 862 863 864 865 866 867 868 869

Future<bool> _linksOnFlutterMacOS(String pathToBinary) async {
  final String loadCommands = await eval('otool', <String>[
    '-l',
    '-arch',
    'arm64',
    pathToBinary,
  ]);
  return loadCommands.contains('FlutterMacOS.framework');
}