build_ios_framework_module_test.dart 23.2 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 281
    if (!await _linksOnFlutter(pluginFrameworkPath)) {
      throw TaskResult.failure('$pluginFrameworkPath does not link on Flutter');
    }

    final String transitiveDependencyFrameworkPath = path.join(
282 283 284 285 286 287 288 289
      outputPath,
      mode,
      'Reachability.xcframework',
      'ios-arm64',
      'Reachability.framework',
      'Reachability',
    );

290
    if (!exists(File(transitiveDependencyFrameworkPath))) {
291 292 293
      throw TaskResult.failure('Expected debug Flutter engine artifact binary to exist');
    }

294
    if (await _linksOnFlutter(transitiveDependencyFrameworkPath)) {
295 296
      throw TaskResult.failure(
          'Transitive dependency $transitiveDependencyFrameworkPath unexpectedly links on Flutter');
297
    }
298 299 300 301

    checkFileExists(path.join(
      outputPath,
      mode,
302
      'connectivity.xcframework',
303
      'ios-arm64',
304
      'connectivity.framework',
305
      'Headers',
306
      'FLTConnectivityPlugin.h',
307 308
    ));

309 310 311 312
    if (mode != 'Debug') {
      checkDirectoryExists(path.join(
        outputPath,
        mode,
313
        'connectivity.xcframework',
314
        'ios-arm64',
315
        'dSYMs',
316
        'connectivity.framework.dSYM',
317 318 319
      ));
    }

320 321 322
    final String simulatorFrameworkPath = path.join(
      outputPath,
      mode,
323
      'connectivity.xcframework',
324
      'ios-arm64_x86_64-simulator',
325 326
      'connectivity.framework',
      'connectivity',
327 328 329 330 331
    );

    final String simulatorFrameworkHeaderPath = path.join(
      outputPath,
      mode,
332
      'connectivity.xcframework',
333
      'ios-arm64_x86_64-simulator',
334
      'connectivity.framework',
335
      'Headers',
336
      'FLTConnectivityPlugin.h',
337 338
    );

339 340
    checkFileExists(simulatorFrameworkPath);
    checkFileExists(simulatorFrameworkHeaderPath);
341
  }
342

343
  section('Check all modes have generated plugin registrant');
344

345 346 347 348 349 350 351
  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    if (!isModule) {
      continue;
    }
    final String registrantFrameworkPath = path.join(
      outputPath,
      mode,
352
      'FlutterPluginRegistrant.xcframework',
353
      'ios-arm64',
354
      'FlutterPluginRegistrant.framework',
355
      'FlutterPluginRegistrant',
356
    );
357
    await _checkStatic(registrantFrameworkPath);
358 359 360 361 362

    checkFileExists(path.join(
      outputPath,
      mode,
      'FlutterPluginRegistrant.xcframework',
363
      'ios-arm64',
364 365 366 367 368 369 370 371
      'FlutterPluginRegistrant.framework',
      'Headers',
      'GeneratedPluginRegistrant.h',
    ));
    final String simulatorHeaderPath = path.join(
      outputPath,
      mode,
      'FlutterPluginRegistrant.xcframework',
372
      'ios-arm64_x86_64-simulator',
373 374 375 376
      'FlutterPluginRegistrant.framework',
      'Headers',
      'GeneratedPluginRegistrant.h',
    );
377
    checkFileExists(simulatorHeaderPath);
378 379 380
  }

  // This builds all build modes' frameworks by default
381
  section('Build podspec and static plugins');
382 383 384 385 386 387 388 389 390 391

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

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

398 399 400 401 402 403 404
  final String cocoapodsOutputPath = path.join(projectDir.path, cocoapodsOutputDirectoryName);
  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    checkFileExists(path.join(
      cocoapodsOutputPath,
      mode,
      'Flutter.podspec',
    ));
405
    await _checkDylib(path.join(
406 407
      cocoapodsOutputPath,
      mode,
408
      'App.xcframework',
409 410 411
      'ios-arm64',
      'App.framework',
      'App',
412 413
    ));

414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    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',
      ));
    }

433
    if (Directory(path.join(
434 435
          cocoapodsOutputPath,
          mode,
436
          'FlutterPluginRegistrant.xcframework',
437 438 439
        )).existsSync() !=
        isModule) {
      throw TaskResult.failure(
440
          'Unexpected FlutterPluginRegistrant.xcframework.');
441
    }
442

443
    await _checkStatic(path.join(
444 445
      cocoapodsOutputPath,
      mode,
446
      'package_info.xcframework',
447 448 449
      'ios-arm64',
      'package_info.framework',
      'package_info',
450
    ));
451

452
    await _checkStatic(path.join(
453 454 455
      cocoapodsOutputPath,
      mode,
      'connectivity.xcframework',
456 457 458
      'ios-arm64',
      'connectivity.framework',
      'connectivity',
459 460 461 462 463 464 465
    ));

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

468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
  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.');
  }
483 484 485 486 487 488

  section('Build frameworks without plugins');
  await _testBuildFrameworksWithoutPlugins(projectDir, platform: 'ios');

  section('check --static cannot be used with the --no-plugins flag');
  await _testStaticAndNoPlugins(projectDir);
xster's avatar
xster committed
489
}
490

491 492 493 494 495 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

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',
    ));
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633

    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',
    ));
634 635 636 637 638 639 640 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
  }

  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',
    ));

764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
    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',
      ));
    }

783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
    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',
  ));
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888

  section('Build frameworks without plugins');
  await _testBuildFrameworksWithoutPlugins(projectDir, platform: 'macos');
}

Future<void> _testBuildFrameworksWithoutPlugins(Directory projectDir, { required String platform}) async {
  const String noPluginsOutputDir = 'flutter-frameworks-no-plugins';

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

  final String noPluginsOutputPath = path.join(projectDir.path, noPluginsOutputDir);
  for (final String mode in <String>['Debug', 'Profile', 'Release']) {
    checkFileExists(path.join(
      noPluginsOutputPath,
      mode,
      'Flutter${platform == 'macos' ? 'MacOS' : ''}.podspec',
    ));
    checkDirectoryExists(path.join(
      noPluginsOutputPath,
      mode,
      'App.xcframework',
    ));

    checkDirectoryNotExists(path.join(
      noPluginsOutputPath,
      mode,
      'package_info.xcframework',
    ));

    checkDirectoryNotExists(path.join(
      noPluginsOutputPath,
      mode,
      'connectivity.xcframework',
    ));

    checkDirectoryNotExists(path.join(
      noPluginsOutputPath,
      mode,
      'Reachability.xcframework',
    ));
  }
}

Future<void> _testStaticAndNoPlugins(Directory projectDir) async {
  const String noPluginsOutputDir = 'flutter-frameworks-no-plugins-static';
  final ProcessResult result = await inDirectory(projectDir, () async {
    return executeFlutter(
        'build',
        options: <String>[
          'ios-framework',
          '--cocoapods',
          '--force', // Allow podspec creation on master.
          '--output=$noPluginsOutputDir',
          '--no-plugins',
          '--static'
        ],
        canFail: true
    );
  });
  if (result.exitCode == 0) {
    throw TaskResult.failure('Build framework command did not exit with error as expected');
  }
  final String output = '${result.stdout}\n${result.stderr}';
  if (!output.contains('--static cannot be used with the --no-plugins flag')) {
    throw TaskResult.failure(output);
  }
889 890
}

891 892 893 894 895 896 897
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');
  }
}

898 899 900 901 902 903 904
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');
  }
}

905 906 907 908 909 910 911
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');
  }
}

912 913 914 915 916 917 918 919
Future<String> _dylibSymbols(String pathToDylib) {
  return eval('nm', <String>[
    '-g',
    pathToDylib,
    '-arch',
    'arm64',
  ]);
}
920 921 922 923 924 925 926 927 928 929

Future<bool> _linksOnFlutter(String pathToBinary) async {
  final String loadCommands = await eval('otool', <String>[
    '-l',
    '-arch',
    'arm64',
    pathToBinary,
  ]);
  return loadCommands.contains('Flutter.framework');
}
930 931 932 933 934 935 936 937 938 939

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