ios_test.dart 23.9 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
import 'package:file/memory.dart';
6 7 8
import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart';
9
import 'package:flutter_tools/src/base/logger.dart';
10
import 'package:flutter_tools/src/base/platform.dart';
11 12 13
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';
14
import 'package:flutter_tools/src/convert.dart';
15 16

import '../../../src/common.dart';
17 18 19
import '../../../src/context.dart';

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

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

void main() {
40 41 42 43 44
  late Environment environment;
  late FileSystem fileSystem;
  late FakeProcessManager processManager;
  late Artifacts artifacts;
  late BufferLogger logger;
45 46

  setUp(() {
47
    fileSystem = MemoryFileSystem.test();
48
    processManager = FakeProcessManager.empty();
49 50 51 52 53 54 55 56 57 58 59 60 61 62
    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',
    );
63 64
  });

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

70
  testUsingContext('DebugUniversalFramework creates simulator binary', () async {
71 72
    environment.defines[kIosArchs] = 'x86_64';
    environment.defines[kSdkRoot] = 'path/to/iPhoneSimulator.sdk';
73 74
    final String appFrameworkPath = environment.buildDir.childDirectory('App.framework').childFile('App').path;
    processManager.addCommands(<FakeCommand>[
75 76 77 78 79 80 81 82 83 84 85
      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',
86
        '-miphonesimulator-version-min=11.0',
87 88 89 90 91 92 93 94 95 96 97 98 99
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@executable_path/Frameworks',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@loader_path/Frameworks',
        '-install_name',
        '@rpath/App.framework/App',
        '-isysroot',
        'path/to/iPhoneSimulator.sdk',
        '-o',
100
        appFrameworkPath,
101
      ]),
102 103 104 105 106 107 108 109 110
      FakeCommand(command: <String>[
        'codesign',
        '--force',
        '--sign',
        '-',
        '--timestamp=none',
        appFrameworkPath,
      ]),
    ]);
111 112 113 114 115 116 117 118 119

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

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

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

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

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

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

204
    await const DebugIosApplicationBundle().build(environment);
205
    expect(processManager.hasRemainingExpectations, isFalse);
206

207
    expect(frameworkDirectoryBinary, exists);
208 209 210 211 212 213 214
    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);
215 216
    expect(assetDirectory.childFile('io.flutter.shaders.json'), exists);
    expect(assetDirectory.childFile('io.flutter.shaders.json').readAsStringSync(), '{"data":{"A":"B"}}');
217
  });
218

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

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

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


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

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

    expect(frameworkDirectoryBinary, exists);
253 254 255 256 257 258 259
    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));
260 261 262 263 264
  }, overrides: <Type, Generator>{
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
    Platform: () => macPlatform,
  });
265

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

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

296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
  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';

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

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

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

      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,
      ]);
367 368 369 370 371 372 373 374 375

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

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

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

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

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

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

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

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

477
      await expectLater(
478 479 480 481 482 483 484
        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:'),
        )),
      );
485 486
    });

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      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,
638 639
        lipoCommandNonFatResult,
        lipoVerifyArm64Command,
640 641 642 643 644 645 646 647 648 649 650
        FakeCommand(command: <String>[
          'xcrun',
          'bitcode_strip',
          binary.path,
          '-m',
          '-o',
          binary.path,
        ], exitCode: 1, stderr: 'bitcode_strip error'),
      ]);

      await expectLater(
651 652 653 654 655 656 657
        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'),
        )),
      );
658 659 660 661 662

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

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

      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,
681 682 683
        lipoCommandNonFatResult,
        lipoVerifyArm64Command,
        bitcodeStripCommand,
684
        adHocCodesignCommand,
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
      ]);
      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,
714
        FakeCommand(command: <String>[
715 716 717 718 719
          'codesign',
          '--force',
          '--sign',
          'ABC123',
          '--timestamp=none',
720
          binary.path,
721 722 723 724
        ], exitCode: 1, stderr: 'codesign error'),
      ]);

      await expectLater(
725 726 727 728 729 730 731
        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'),
        )),
      );
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

      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,
759
        FakeCommand(command: <String>[
760 761 762 763 764
          'codesign',
          '--force',
          '--sign',
          'ABC123',
          '--timestamp=none',
765 766 767 768 769 770 771
          binary.path,
        ]),
      ]);
      await const DebugUnpackIOS().build(environment);

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