ios_test.dart 23.8 KB
Newer Older
1 2 3 4
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
// @dart = 2.8

7
import 'package:file/memory.dart';
8 9 10
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
11
import 'package:flutter_tools/src/base/logger.dart';
12
import 'package:flutter_tools/src/base/platform.dart';
13 14 15
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/ios.dart';
16
import 'package:flutter_tools/src/convert.dart';
17 18

import '../../../src/common.dart';
19 20 21
import '../../../src/context.dart';

final Platform macPlatform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{});
22 23 24 25

const List<String> _kSharedConfig = <String>[
  '-dynamiclib',
  '-fembed-bitcode-marker',
26
  '-miphoneos-version-min=9.0',
27 28 29 30 31 32 33 34 35 36 37
  '-Xlinker',
  '-rpath',
  '-Xlinker',
  '@executable_path/Frameworks',
  '-Xlinker',
  '-rpath',
  '-Xlinker',
  '@loader_path/Frameworks',
  '-install_name',
  '@rpath/App.framework/App',
  '-isysroot',
38
  'path/to/iPhoneOS.sdk',
39 40 41 42
];

void main() {
  Environment environment;
43 44 45
  FileSystem fileSystem;
  FakeProcessManager processManager;
  Artifacts artifacts;
46
  BufferLogger logger;
47 48

  setUp(() {
49
    fileSystem = MemoryFileSystem.test();
50
    processManager = FakeProcessManager.empty();
51 52 53 54 55 56 57 58 59 60 61 62 63 64
    logger = BufferLogger.test();
    artifacts = Artifacts.test();
    environment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kTargetPlatform: 'ios',
      },
      inputs: <String, String>{},
      processManager: processManager,
      artifacts: artifacts,
      logger: logger,
      fileSystem: fileSystem,
      engineVersion: '2',
    );
65 66
  });

67
  testWithoutContext('iOS AOT targets has analyticsName', () {
68 69 70 71
    expect(const AotAssemblyRelease().analyticsName, 'ios_aot');
    expect(const AotAssemblyProfile().analyticsName, 'ios_aot');
  });

72
  testUsingContext('DebugUniversalFramework creates simulator binary', () async {
73 74
    environment.defines[kIosArchs] = 'x86_64';
    environment.defines[kSdkRoot] = 'path/to/iPhoneSimulator.sdk';
75 76
    final String appFrameworkPath = environment.buildDir.childDirectory('App.framework').childFile('App').path;
    processManager.addCommands(<FakeCommand>[
77 78 79 80 81 82 83 84 85 86 87
      FakeCommand(command: <String>[
        'xcrun',
        'clang',
        '-x',
        'c',
        '-arch',
        'x86_64',
        fileSystem.path.absolute(fileSystem.path.join(
            '.tmp_rand0', 'flutter_tools_stub_source.rand0', 'debug_app.cc')),
        '-dynamiclib',
        '-fembed-bitcode-marker',
88
        '-miphonesimulator-version-min=9.0',
89 90 91 92 93 94 95 96 97 98 99 100 101
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@executable_path/Frameworks',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@loader_path/Frameworks',
        '-install_name',
        '@rpath/App.framework/App',
        '-isysroot',
        'path/to/iPhoneSimulator.sdk',
        '-o',
102
        appFrameworkPath,
103
      ]),
104 105 106 107 108 109 110 111 112
      FakeCommand(command: <String>[
        'codesign',
        '--force',
        '--sign',
        '-',
        '--timestamp=none',
        appFrameworkPath,
      ]),
    ]);
113 114 115 116 117 118 119 120 121

    await const DebugUniversalFramework().build(environment);
    expect(processManager.hasRemainingExpectations, isFalse);
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
    Platform: () => macPlatform,
  });

122
  testUsingContext('DebugUniversalFramework creates expected binary with arm64 only arch', () async {
123
    environment.defines[kIosArchs] = 'arm64';
124
    environment.defines[kSdkRoot] = 'path/to/iPhoneOS.sdk';
125 126
    final String appFrameworkPath = environment.buildDir.childDirectory('App.framework').childFile('App').path;
    processManager.addCommands(<FakeCommand>[
127 128 129 130 131
      FakeCommand(command: <String>[
        'xcrun',
        'clang',
        '-x',
        'c',
132
        // iphone only gets 64 bit arch based on kIosArchs
133 134
        '-arch',
        'arm64',
135 136
        fileSystem.path.absolute(fileSystem.path.join(
            '.tmp_rand0', 'flutter_tools_stub_source.rand0', 'debug_app.cc')),
137 138
        ..._kSharedConfig,
        '-o',
139
        appFrameworkPath,
140
      ]),
141 142 143 144 145 146 147 148 149
      FakeCommand(command: <String>[
        'codesign',
        '--force',
        '--sign',
        '-',
        '--timestamp=none',
        appFrameworkPath,
      ]),
    ]);
150

151
    await const DebugUniversalFramework().build(environment);
152
    expect(processManager.hasRemainingExpectations, isFalse);
153
  }, overrides: <Type, Generator>{
154
    FileSystem: () => fileSystem,
155
    ProcessManager: () => processManager,
156 157
    Platform: () => macPlatform,
  });
158

159
  testUsingContext('DebugIosApplicationBundle', () async {
160
    environment.defines[kBundleSkSLPath] = 'bundle.sksl';
161
    environment.defines[kBuildMode] = 'debug';
162
    environment.defines[kCodesignIdentity] = 'ABC123';
163
    // Precompiled dart data
164 165 166 167 168

    fileSystem.file(artifacts.getArtifactPath(Artifact.vmSnapshotData, mode: BuildMode.debug))
      .createSync();
    fileSystem.file(artifacts.getArtifactPath(Artifact.isolateSnapshotData, mode: BuildMode.debug))
      .createSync();
169
    // Project info
170 171
    fileSystem.file('pubspec.yaml').writeAsStringSync('name: hello');
    fileSystem.file('.packages').writeAsStringSync('\n');
172
    // Plist file
173
    fileSystem.file(fileSystem.path.join('ios', 'Flutter', 'AppFrameworkInfo.plist'))
174
      .createSync(recursive: true);
175 176 177
    // App kernel
    environment.buildDir.childFile('app.dill').createSync(recursive: true);
    // Stub framework
178
    environment.buildDir
179
        .childDirectory('App.framework')
180 181
      .childFile('App')
      .createSync(recursive: true);
182
    // sksl bundle
183
    fileSystem.file('bundle.sksl').writeAsStringSync(json.encode(
184 185 186 187 188 189 190 191
      <String, Object>{
        'engineRevision': '2',
        'platform': 'ios',
        'data': <String, Object>{
          'A': 'B',
        }
      }
    ));
192

193 194
    final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
    final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
195
    processManager.addCommand(
196 197 198 199 200 201 202 203
      FakeCommand(command: <String>[
        'codesign',
        '--force',
        '--sign',
        'ABC123',
        '--timestamp=none',
        frameworkDirectoryBinary.path,
      ]),
204
    );
205

206
    await const DebugIosApplicationBundle().build(environment);
207
    expect(processManager.hasRemainingExpectations, isFalse);
208

209
    expect(frameworkDirectoryBinary, exists);
210 211 212 213 214 215 216
    expect(frameworkDirectory.childFile('Info.plist'), exists);

    final Directory assetDirectory = frameworkDirectory.childDirectory('flutter_assets');
    expect(assetDirectory.childFile('kernel_blob.bin'), exists);
    expect(assetDirectory.childFile('AssetManifest.json'), exists);
    expect(assetDirectory.childFile('vm_snapshot_data'), exists);
    expect(assetDirectory.childFile('isolate_snapshot_data'), exists);
217 218
    expect(assetDirectory.childFile('io.flutter.shaders.json'), exists);
    expect(assetDirectory.childFile('io.flutter.shaders.json').readAsStringSync(), '{"data":{"A":"B"}}');
219
  });
220

221
  testUsingContext('ReleaseIosApplicationBundle', () async {
222
    environment.defines[kBuildMode] = 'release';
223
    environment.defines[kCodesignIdentity] = 'ABC123';
224 225

    // Project info
226 227
    fileSystem.file('pubspec.yaml').writeAsStringSync('name: hello');
    fileSystem.file('.packages').writeAsStringSync('\n');
228
    // Plist file
229
    fileSystem.file(fileSystem.path.join('ios', 'Flutter', 'AppFrameworkInfo.plist'))
230
      .createSync(recursive: true);
231 232 233 234 235 236 237 238 239

    // Real framework
    environment.buildDir
      .childDirectory('App.framework')
      .childFile('App')
      .createSync(recursive: true);


    final Directory frameworkDirectory = environment.outputDir.childDirectory('App.framework');
240
    final File frameworkDirectoryBinary = frameworkDirectory.childFile('App');
241
    processManager.addCommand(
242 243 244 245 246 247 248
      FakeCommand(command: <String>[
        'codesign',
        '--force',
        '--sign',
        'ABC123',
        frameworkDirectoryBinary.path,
      ]),
249
    );
250 251 252 253 254

    await const ReleaseIosApplicationBundle().build(environment);
    expect(processManager.hasRemainingExpectations, isFalse);

    expect(frameworkDirectoryBinary, exists);
255 256 257 258 259 260 261
    expect(frameworkDirectory.childFile('Info.plist'), exists);

    final Directory assetDirectory = frameworkDirectory.childDirectory('flutter_assets');
    expect(assetDirectory.childFile('kernel_blob.bin'), isNot(exists));
    expect(assetDirectory.childFile('AssetManifest.json'), exists);
    expect(assetDirectory.childFile('vm_snapshot_data'), isNot(exists));
    expect(assetDirectory.childFile('isolate_snapshot_data'), isNot(exists));
262 263 264 265 266
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
    Platform: () => macPlatform,
  });
267

268
  testUsingContext('AotAssemblyRelease throws exception if asked to build for simulator', () async {
269 270 271 272 273
    final FileSystem fileSystem = MemoryFileSystem.test();
    final Environment environment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kTargetPlatform: 'ios',
274 275 276
        kSdkRoot: 'path/to/iPhoneSimulator.sdk',
        kBuildMode: 'release',
        kIosArchs: 'x86_64',
277 278
      },
      processManager: processManager,
279 280
      artifacts: artifacts,
      logger: logger,
281 282 283
      fileSystem: fileSystem,
    );

284
    expect(const AotAssemblyRelease().build(environment), throwsA(isException
285 286 287 288 289 290
      .having(
        (Exception exception) => exception.toString(),
        'description',
        contains('release/profile builds are only supported for physical devices.'),
      )
    ));
291
    expect(processManager.hasRemainingExpectations, isFalse);
292 293 294 295 296
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
    Platform: () => macPlatform,
  });
297

298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
  testUsingContext('AotAssemblyRelease throws exception if sdk root is missing', () async {
    final FileSystem fileSystem = MemoryFileSystem.test();
    final Environment environment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kTargetPlatform: 'ios',
      },
      processManager: processManager,
      artifacts: artifacts,
      logger: logger,
      fileSystem: fileSystem,
    );
    environment.defines[kBuildMode] = 'release';
    environment.defines[kIosArchs] = 'x86_64';

313 314
    expect(const AotAssemblyRelease().build(environment), throwsA(isException.having(
      (Exception exception) => exception.toString(),
315 316
      'description',
      contains('required define SdkRoot but it was not provided'),
317
    )));
318
    expect(processManager.hasRemainingExpectations, isFalse);
319 320 321 322 323 324
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
    Platform: () => macPlatform,
  });

325
  group('copies Flutter.framework', () {
326
    Directory outputDir;
327
    File binary;
328
    FakeCommand copyPhysicalFrameworkCommand;
329 330 331
    FakeCommand lipoCommandNonFatResult;
    FakeCommand lipoVerifyArm64Command;
    FakeCommand bitcodeStripCommand;
332
    FakeCommand adHocCodesignCommand;
333 334

    setUp(() {
335
      final FileSystem fileSystem = MemoryFileSystem.test();
336
      outputDir = fileSystem.directory('output');
337
      binary = outputDir.childDirectory('Flutter.framework').childFile('Flutter');
338 339 340 341 342 343 344 345 346
      copyPhysicalFrameworkCommand = FakeCommand(command: <String>[
        'rsync',
        '-av',
        '--delete',
        '--filter',
        '- .DS_Store/',
        'Artifact.flutterFramework.TargetPlatform.ios.debug.EnvironmentType.physical',
        outputDir.path,
      ]);
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368

      lipoCommandNonFatResult = FakeCommand(command: <String>[
        'lipo',
        '-info',
        binary.path,
      ], stdout: 'Non-fat file:');

      lipoVerifyArm64Command = FakeCommand(command: <String>[
        'lipo',
        binary.path,
        '-verify_arch',
        'arm64',
      ]);

      bitcodeStripCommand = FakeCommand(command: <String>[
        'xcrun',
        'bitcode_strip',
        binary.path,
        '-m',
        '-o',
        binary.path,
      ]);
369 370 371 372 373 374 375 376 377

      adHocCodesignCommand = FakeCommand(command: <String>[
        'codesign',
        '--force',
        '--sign',
        '-',
        '--timestamp=none',
        binary.path,
      ]);
378 379 380
    });

    testWithoutContext('iphonesimulator', () async {
381 382 383 384 385 386 387 388
      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
389
          kIosArchs: 'x86_64',
390
          kSdkRoot: 'path/to/iPhoneSimulator.sdk',
391
          kBitcodeFlag: 'true',
392 393
        },
      );
394

395
      processManager.addCommands(<FakeCommand>[
396 397 398 399 400 401 402 403
        FakeCommand(command: <String>[
          'rsync',
          '-av',
          '--delete',
          '--filter',
          '- .DS_Store/',
          'Artifact.flutterFramework.TargetPlatform.ios.debug.EnvironmentType.simulator',
          outputDir.path,
404 405 406
          ],
          onRun: () => binary.createSync(recursive: true),
        ),
407
        lipoCommandNonFatResult,
408
        FakeCommand(command: <String>[
409 410 411 412
          'lipo',
          binary.path,
          '-verify_arch',
          'x86_64',
413
        ]),
414
        adHocCodesignCommand,
415
      ]);
416
      await const DebugUnpackIOS().build(environment);
417 418 419

      expect(logger.traceText, contains('Skipping lipo for non-fat file output/Flutter.framework/Flutter'));
      expect(processManager.hasRemainingExpectations, isFalse);
420
    });
421

422
    testWithoutContext('fails when frameworks missing', () async {
423 424 425 426 427 428 429 430 431
      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64',
432
          kSdkRoot: 'path/to/iPhoneOS.sdk',
433
          kBitcodeFlag: '',
434 435
        },
      );
436
      processManager.addCommand(copyPhysicalFrameworkCommand);
437
      await expectLater(
438
        const DebugUnpackIOS().build(environment),
439
        throwsA(isException.having(
440 441
          (Exception exception) => exception.toString(),
          'description',
442
          contains('Flutter.framework/Flutter does not exist, cannot thin'),
443 444 445
        )));
    });

446
    testWithoutContext('fails when requested archs missing from framework', () async {
447
      binary.createSync(recursive: true);
448 449 450 451 452 453 454 455 456 457

      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64 armv7',
458
          kSdkRoot: 'path/to/iPhoneOS.sdk',
459
          kBitcodeFlag: '',
460 461 462
        },
      );

463 464
      processManager.addCommands(<FakeCommand>[
        copyPhysicalFrameworkCommand,
465 466 467
        FakeCommand(command: <String>[
          'lipo',
          '-info',
468
          binary.path,
469 470 471
        ], stdout: 'Architectures in the fat file:'),
        FakeCommand(command: <String>[
          'lipo',
472
          binary.path,
473 474 475 476
          '-verify_arch',
          'arm64',
          'armv7',
        ], exitCode: 1),
477
      ]);
478

479
      await expectLater(
480 481 482 483 484 485 486
        const DebugUnpackIOS().build(environment),
        throwsA(isException.having(
          (Exception exception) => exception.toString(),
          'description',
          contains('does not contain arm64 armv7. Running lipo -info:\nArchitectures in the fat file:'),
        )),
      );
487 488
    });

489
    testWithoutContext('fails when lipo extract fails', () async {
490
      binary.createSync(recursive: true);
491 492 493 494 495 496 497 498 499 500

      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64 armv7',
501
          kSdkRoot: 'path/to/iPhoneOS.sdk',
502
          kBitcodeFlag: '',
503 504 505
        },
      );

506 507
      processManager.addCommands(<FakeCommand>[
        copyPhysicalFrameworkCommand,
508 509 510
        FakeCommand(command: <String>[
          'lipo',
          '-info',
511
          binary.path,
512 513 514
        ], stdout: 'Architectures in the fat file:'),
        FakeCommand(command: <String>[
          'lipo',
515
          binary.path,
516 517 518 519 520 521 522
          '-verify_arch',
          'arm64',
          'armv7',
        ]),
        FakeCommand(command: <String>[
          'lipo',
          '-output',
523
          binary.path,
524 525 526 527
          '-extract',
          'arm64',
          '-extract',
          'armv7',
528
          binary.path,
529 530
        ], exitCode: 1,
        stderr: 'lipo error'),
531
      ]);
532

533
      await expectLater(
534
        const DebugUnpackIOS().build(environment),
535 536
        throwsA(isException.having(
          (Exception exception) => exception.toString(),
537
          'description',
538
          contains('Failed to extract arm64 armv7 for output/Flutter.framework/Flutter.\nlipo error\nRunning lipo -info:\nArchitectures in the fat file:'),
539 540
        )),
      );
541 542
    });

543
    testWithoutContext('skips thin framework', () async {
544
      binary.createSync(recursive: true);
545 546 547 548 549 550 551 552 553 554

      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64',
555
          kSdkRoot: 'path/to/iPhoneOS.sdk',
556
          kBitcodeFlag: 'true',
557 558 559
        },
      );

560 561 562 563
      processManager.addCommands(<FakeCommand>[
        copyPhysicalFrameworkCommand,
        lipoCommandNonFatResult,
        lipoVerifyArm64Command,
564
        adHocCodesignCommand,
565
      ]);
566
      await const DebugUnpackIOS().build(environment);
567

568
      expect(logger.traceText, contains('Skipping lipo for non-fat file output/Flutter.framework/Flutter'));
569 570 571 572

      expect(processManager.hasRemainingExpectations, isFalse);
    });

573
    testWithoutContext('thins fat framework', () async {
574
      binary.createSync(recursive: true);
575 576 577 578 579 580 581 582 583 584

      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64 armv7',
585
          kSdkRoot: 'path/to/iPhoneOS.sdk',
586
          kBitcodeFlag: 'true',
587 588 589
        },
      );

590 591
      processManager.addCommands(<FakeCommand>[
        copyPhysicalFrameworkCommand,
592 593 594
        FakeCommand(command: <String>[
          'lipo',
          '-info',
595
          binary.path,
596 597 598
        ], stdout: 'Architectures in the fat file:'),
        FakeCommand(command: <String>[
          'lipo',
599
          binary.path,
600 601 602 603 604 605 606
          '-verify_arch',
          'arm64',
          'armv7',
        ]),
        FakeCommand(command: <String>[
          'lipo',
          '-output',
607
          binary.path,
608 609 610 611
          '-extract',
          'arm64',
          '-extract',
          'armv7',
612
          binary.path,
613
        ]),
614
        adHocCodesignCommand,
615
      ]);
616

617
      await const DebugUnpackIOS().build(environment);
618 619
      expect(processManager.hasRemainingExpectations, isFalse);
    });
620 621

    testWithoutContext('fails when bitcode strip fails', () async {
622
      binary.createSync(recursive: true);
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639

      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64',
          kSdkRoot: 'path/to/iPhoneOS.sdk',
          kBitcodeFlag: '',
        },
      );

      processManager.addCommands(<FakeCommand>[
        copyPhysicalFrameworkCommand,
640 641
        lipoCommandNonFatResult,
        lipoVerifyArm64Command,
642 643 644 645 646 647 648 649 650 651 652
        FakeCommand(command: <String>[
          'xcrun',
          'bitcode_strip',
          binary.path,
          '-m',
          '-o',
          binary.path,
        ], exitCode: 1, stderr: 'bitcode_strip error'),
      ]);

      await expectLater(
653 654 655 656 657 658 659
        const DebugUnpackIOS().build(environment),
        throwsA(isException.having(
          (Exception exception) => exception.toString(),
          'description',
          contains('Failed to strip bitcode for output/Flutter.framework/Flutter.\nbitcode_strip error'),
        )),
      );
660 661 662 663 664

      expect(processManager.hasRemainingExpectations, isFalse);
    });

    testWithoutContext('strips framework', () async {
665
      binary.createSync(recursive: true);
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682

      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64',
          kSdkRoot: 'path/to/iPhoneOS.sdk',
          kBitcodeFlag: '',
        },
      );

      processManager.addCommands(<FakeCommand>[
        copyPhysicalFrameworkCommand,
683 684 685
        lipoCommandNonFatResult,
        lipoVerifyArm64Command,
        bitcodeStripCommand,
686
        adHocCodesignCommand,
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
      ]);
      await const DebugUnpackIOS().build(environment);

      expect(processManager.hasRemainingExpectations, isFalse);
    });

    testWithoutContext('fails when codesign fails', () async {
      binary.createSync(recursive: true);

      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64',
          kSdkRoot: 'path/to/iPhoneOS.sdk',
          kBitcodeFlag: '',
          kCodesignIdentity: 'ABC123',
        },
      );

      processManager.addCommands(<FakeCommand>[
        copyPhysicalFrameworkCommand,
        lipoCommandNonFatResult,
        lipoVerifyArm64Command,
        bitcodeStripCommand,
716
        FakeCommand(command: <String>[
717 718 719 720 721
          'codesign',
          '--force',
          '--sign',
          'ABC123',
          '--timestamp=none',
722
          binary.path,
723 724 725 726
        ], exitCode: 1, stderr: 'codesign error'),
      ]);

      await expectLater(
727 728 729 730 731 732 733
        const DebugUnpackIOS().build(environment),
        throwsA(isException.having(
          (Exception exception) => exception.toString(),
          'description',
          contains('Failed to codesign output/Flutter.framework/Flutter with identity ABC123.\ncodesign error'),
        )),
      );
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

      expect(processManager.hasRemainingExpectations, isFalse);
    });

    testWithoutContext('codesigns framework', () async {
      binary.createSync(recursive: true);

      final Environment environment = Environment.test(
        fileSystem.currentDirectory,
        processManager: processManager,
        artifacts: artifacts,
        logger: logger,
        fileSystem: fileSystem,
        outputDir: outputDir,
        defines: <String, String>{
          kIosArchs: 'arm64',
          kSdkRoot: 'path/to/iPhoneOS.sdk',
          kBitcodeFlag: '',
          kCodesignIdentity: 'ABC123',
        },
      );

      processManager.addCommands(<FakeCommand>[
        copyPhysicalFrameworkCommand,
        lipoCommandNonFatResult,
        lipoVerifyArm64Command,
        bitcodeStripCommand,
761
        FakeCommand(command: <String>[
762 763 764 765 766
          'codesign',
          '--force',
          '--sign',
          'ABC123',
          '--timestamp=none',
767 768 769 770 771 772 773
          binary.path,
        ]),
      ]);
      await const DebugUnpackIOS().build(environment);

      expect(processManager.hasRemainingExpectations, isFalse);
    });
774
  });
775
}