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

5 6
import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart';
7
import 'package:flutter_tools/src/base/file_system.dart';
8
import 'package:flutter_tools/src/base/logger.dart';
9
import 'package:flutter_tools/src/base/platform.dart';
10 11 12
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/exceptions.dart';
13
import 'package:flutter_tools/src/build_system/targets/common.dart';
14
import 'package:flutter_tools/src/build_system/targets/ios.dart';
15 16
import 'package:flutter_tools/src/compile.dart';

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

21 22 23 24
const String kBoundaryKey = '4d2d9609-c662-4571-afde-31410f96caa6';
const String kElfAot = '--snapshot_kind=app-aot-elf';
const String kAssemblyAot = '--snapshot_kind=app-aot-assembly';

25
final Platform macPlatform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{});
26
void main() {
27
  FakeProcessManager processManager;
28 29
  Environment androidEnvironment;
  Environment iosEnvironment;
30
  Artifacts artifacts;
31 32
  FileSystem fileSystem;
  Logger logger;
33 34

  setUp(() {
35 36 37 38 39 40 41 42 43 44
    processManager = FakeProcessManager.list(<FakeCommand>[]);
    logger = BufferLogger.test();
    artifacts = Artifacts.test();
    fileSystem = MemoryFileSystem.test(style: FileSystemStyle.posix);
    androidEnvironment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kBuildMode: getNameForBuildMode(BuildMode.profile),
        kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
      },
45
      inputs: <String, String>{},
46 47 48 49 50 51 52 53 54 55 56 57
      artifacts: artifacts,
      processManager: processManager,
      fileSystem: fileSystem,
      logger: logger,
    );
    androidEnvironment.buildDir.createSync(recursive: true);
    iosEnvironment = Environment.test(
      fileSystem.currentDirectory,
      defines: <String, String>{
        kBuildMode: getNameForBuildMode(BuildMode.profile),
        kTargetPlatform: getNameForTargetPlatform(TargetPlatform.ios),
      },
58
      inputs: <String, String>{},
59 60 61 62 63 64
      artifacts: artifacts,
      processManager: processManager,
      fileSystem: fileSystem,
      logger: logger,
    );
    iosEnvironment.buildDir.createSync(recursive: true);
65
  });
66

67
  testWithoutContext('KernelSnapshot throws error if missing build mode', () async {
68 69 70
    androidEnvironment.defines.remove(kBuildMode);
    expect(
      const KernelSnapshot().build(androidEnvironment),
71
      throwsA(isA<MissingDefineException>()));
72
  });
73

74 75
  testWithoutContext('KernelSnapshot handles null result from kernel compilation', () async {
    fileSystem.file('.packages').writeAsStringSync('\n');
76
    final String build = androidEnvironment.buildDir.path;
77
    processManager.addCommands(<FakeCommand>[
78 79
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
80
        '--disable-dart-dev',
81 82
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
83 84 85 86 87
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ) + '/',
88 89 90 91 92 93 94 95 96 97 98
        '--target=flutter',
        '-Ddart.developer.causal_async_stacks=false',
        ...buildModeOptions(BuildMode.profile),
        '--aot',
        '--tfa',
        '--packages',
        '/.packages',
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
99
        'file:///lib/main.dart',
100 101 102 103 104 105
      ], exitCode: 1),
    ]);

    await expectLater(() => const KernelSnapshot().build(androidEnvironment),
      throwsA(isA<Exception>()));
    expect(processManager.hasRemainingExpectations, false);
106
  });
107

108 109
  testWithoutContext('KernelSnapshot does not use track widget creation on profile builds', () async {
    fileSystem.file('.packages').writeAsStringSync('\n');
110
    final String build = androidEnvironment.buildDir.path;
111
    processManager.addCommands(<FakeCommand>[
112 113
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
114
        '--disable-dart-dev',
115 116
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
117 118 119 120 121
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ) + '/',
122 123 124 125 126 127 128 129 130 131 132
        '--target=flutter',
        '-Ddart.developer.causal_async_stacks=false',
        ...buildModeOptions(BuildMode.profile),
        '--aot',
        '--tfa',
        '--packages',
        '/.packages',
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
133
        'file:///lib/main.dart',
134 135
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
    ]);
136

137
    await const KernelSnapshot().build(androidEnvironment);
138 139

    expect(processManager.hasRemainingExpectations, false);
140
  });
141

142 143
  testWithoutContext('KernelSnapshot correctly handles an empty string in ExtraFrontEndOptions', () async {
    fileSystem.file('.packages').writeAsStringSync('\n');
144
    final String build = androidEnvironment.buildDir.path;
145
    processManager.addCommands(<FakeCommand>[
146 147
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
148
        '--disable-dart-dev',
149 150
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
151 152 153 154 155
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ) + '/',
156 157 158 159 160 161 162 163 164 165 166
        '--target=flutter',
        '-Ddart.developer.causal_async_stacks=false',
        ...buildModeOptions(BuildMode.profile),
        '--aot',
        '--tfa',
        '--packages',
        '/.packages',
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
167
        'file:///lib/main.dart',
168 169 170 171 172 173 174
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
    ]);

    await const KernelSnapshot()
      .build(androidEnvironment..defines[kExtraFrontEndOptions] = '');

    expect(processManager.hasRemainingExpectations, false);
175
  });
176

177 178
  testWithoutContext('KernelSnapshot correctly forwards ExtraFrontEndOptions', () async {
    fileSystem.file('.packages').writeAsStringSync('\n');
179
    final String build = androidEnvironment.buildDir.path;
180
    processManager.addCommands(<FakeCommand>[
181 182
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
183
        '--disable-dart-dev',
184 185
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
186 187 188 189 190
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ) + '/',
191 192 193 194 195 196 197 198 199 200 201 202 203
        '--target=flutter',
        '-Ddart.developer.causal_async_stacks=false',
        ...buildModeOptions(BuildMode.profile),
        '--aot',
        '--tfa',
        '--packages',
        '/.packages',
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
        'foo',
        'bar',
204
        'file:///lib/main.dart',
205 206 207 208 209 210 211
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
    ]);

    await const KernelSnapshot()
      .build(androidEnvironment..defines[kExtraFrontEndOptions] = 'foo,bar');

    expect(processManager.hasRemainingExpectations, false);
212
  });
213

214 215
  testWithoutContext('KernelSnapshot can disable track-widget-creation on debug builds', () async {
    fileSystem.file('.packages').writeAsStringSync('\n');
216
    final String build = androidEnvironment.buildDir.path;
217
    processManager.addCommands(<FakeCommand>[
218 219
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
220
        '--disable-dart-dev',
221 222
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
223 224 225 226 227
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.debug,
        ) + '/',
228 229 230 231 232 233 234 235 236 237
        '--target=flutter',
        '-Ddart.developer.causal_async_stacks=true',
        ...buildModeOptions(BuildMode.debug),
        '--no-link-platform',
        '--packages',
        '/.packages',
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
238
        'file:///lib/main.dart',
239 240
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
    ]);
241

242
    await const KernelSnapshot().build(androidEnvironment
243
      ..defines[kBuildMode] = getNameForBuildMode(BuildMode.debug)
244
      ..defines[kTrackWidgetCreation] = 'false');
245 246

    expect(processManager.hasRemainingExpectations, false);
247
  });
248

249 250
  testWithoutContext('KernelSnapshot forces platform linking on debug for darwin target platforms', () async {
    fileSystem.file('.packages').writeAsStringSync('\n');
251
    final String build = androidEnvironment.buildDir.path;
252
    processManager.addCommands(<FakeCommand>[
253 254
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
255
        '--disable-dart-dev',
256 257
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
258 259 260 261 262
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.darwin_x64,
          mode: BuildMode.debug,
        ) + '/',
263 264 265 266 267 268 269 270 271
        '--target=flutter',
        '-Ddart.developer.causal_async_stacks=true',
        ...buildModeOptions(BuildMode.debug),
        '--packages',
        '/.packages',
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
272
        'file:///lib/main.dart',
273 274
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
    ]);
275 276

    await const KernelSnapshot().build(androidEnvironment
277
      ..defines[kTargetPlatform]  = getNameForTargetPlatform(TargetPlatform.darwin_x64)
278
      ..defines[kBuildMode] = getNameForBuildMode(BuildMode.debug)
279
      ..defines[kTrackWidgetCreation] = 'false'
280 281
    );

282
    expect(processManager.hasRemainingExpectations, false);
283
  });
284

285 286
  testWithoutContext('KernelSnapshot does use track widget creation on debug builds', () async {
    fileSystem.file('.packages').writeAsStringSync('\n');
287
    final Environment testEnvironment = Environment.test(
288
      fileSystem.currentDirectory,
289
      defines: <String, String>{
290
        kBuildMode: getNameForBuildMode(BuildMode.debug),
291
        kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
292
      },
293 294
      processManager: processManager,
      artifacts: artifacts,
295 296
      fileSystem: fileSystem,
      logger: logger,
297 298
    );
    final String build = testEnvironment.buildDir.path;
299
    processManager.addCommands(<FakeCommand>[
300 301
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
302
        '--disable-dart-dev',
303 304
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
305 306 307 308 309
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.debug,
        ) + '/',
310 311 312 313 314 315 316 317 318 319 320
        '--target=flutter',
        '-Ddart.developer.causal_async_stacks=true',
        ...buildModeOptions(BuildMode.debug),
        '--track-widget-creation',
        '--no-link-platform',
        '--packages',
        '/.packages',
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
321
        'file:///lib/main.dart',
322 323 324 325 326 327
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey /build/653e11a8e6908714056a57cd6b4f602a/app.dill 0\n'),
    ]);

    await const KernelSnapshot().build(testEnvironment);

    expect(processManager.hasRemainingExpectations, false);
328
  });
329

330
  testUsingContext('AotElfProfile Produces correct output directory', () async {
331
    final String build = androidEnvironment.buildDir.path;
332
    processManager.addCommands(<FakeCommand>[
333
      FakeCommand(command: <String>[
334 335 336 337 338
        artifacts.getArtifactPath(
          Artifact.genSnapshot,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ),
339 340 341 342 343 344 345 346 347 348 349 350 351
        '--deterministic',
        kElfAot,
        '--elf=$build/app.so',
        '--strip',
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ])
    ]);
    androidEnvironment.buildDir.childFile('app.dill').createSync(recursive: true);

352
    await const AotElfProfile(TargetPlatform.android_arm).build(androidEnvironment);
353 354

    expect(processManager.hasRemainingExpectations, false);
355
  });
356

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
  testUsingContext('AotElfRelease configures gen_snapshot with code size directory', () async {
    androidEnvironment.defines[kCodeSizeDirectory] = 'code_size_1';
    final String build = androidEnvironment.buildDir.path;
    processManager.addCommands(<FakeCommand>[
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(
          Artifact.genSnapshot,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ),
        '--deterministic',
        '--write-v8-snapshot-profile-to=code_size_1/snapshot.android-arm.json',
        '--trace-precompiler-to=code_size_1/trace.android-arm.json',
        kElfAot,
        '--elf=$build/app.so',
        '--strip',
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ])
    ]);
    androidEnvironment.buildDir.childFile('app.dill').createSync(recursive: true);

    await const AotElfRelease(TargetPlatform.android_arm).build(androidEnvironment);

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

387
  testUsingContext('AotElfProfile throws error if missing build mode', () async {
388
    androidEnvironment.defines.remove(kBuildMode);
389

390
    expect(const AotElfProfile(TargetPlatform.android_arm).build(androidEnvironment),
391
      throwsA(isA<MissingDefineException>()));
392
  });
393

394
  testUsingContext('AotElfProfile throws error if missing target platform', () async {
395
    androidEnvironment.defines.remove(kTargetPlatform);
396

397
    expect(const AotElfProfile(TargetPlatform.android_arm).build(androidEnvironment),
398
      throwsA(isA<MissingDefineException>()));
399
  });
400

401
  testUsingContext('AotAssemblyProfile throws error if missing build mode', () async {
402
    iosEnvironment.defines.remove(kBuildMode);
403

404
    expect(const AotAssemblyProfile().build(iosEnvironment),
405
      throwsA(isA<MissingDefineException>()));
406 407 408 409 410 411
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });

412

413
  testUsingContext('AotAssemblyProfile throws error if missing target platform', () async {
414
    iosEnvironment.defines.remove(kTargetPlatform);
415

416
    expect(const AotAssemblyProfile().build(iosEnvironment),
417
      throwsA(isA<MissingDefineException>()));
418 419 420 421 422
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });
423

424
  testUsingContext('AotAssemblyProfile throws error if built for non-iOS platform', () async {
425
    expect(const AotAssemblyProfile().build(androidEnvironment),
426
      throwsA(isA<Exception>()));
427 428 429 430 431
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });
432

433
  testUsingContext('AotAssemblyProfile generates multiple arches and lipos together', () async {
434
    final String build = iosEnvironment.buildDir.path;
435
    processManager.addCommands(<FakeCommand>[
436 437
      FakeCommand(command: <String>[
        // This path is not known by the cache due to the iOS gen_snapshot split.
438
        'Artifact.genSnapshot.TargetPlatform.ios.profile_armv7',
439 440 441 442 443 444 445 446 447 448 449 450
        '--deterministic',
        kAssemblyAot,
        '--assembly=$build/armv7/snapshot_assembly.S',
        '--strip',
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ]),
      FakeCommand(command: <String>[
        // This path is not known by the cache due to the iOS gen_snapshot split.
451
        'Artifact.genSnapshot.TargetPlatform.ios.profile_arm64',
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
        '--deterministic',
        kAssemblyAot,
        '--assembly=$build/arm64/snapshot_assembly.S',
        '--strip',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ]),
      const FakeCommand(command: <String>[
        'xcrun',
        '--sdk',
        'iphoneos',
        '--show-sdk-path',
      ]),
      const FakeCommand(command: <String>[
        'xcrun',
        '--sdk',
        'iphoneos',
        '--show-sdk-path',
      ]),
      FakeCommand(command: <String>[
        'xcrun',
        'cc',
        '-arch',
        'armv7',
        '-isysroot',
        '',
        '-c',
        '$build/armv7/snapshot_assembly.S',
        '-o',
        '$build/armv7/snapshot_assembly.o',
      ]),
      FakeCommand(command: <String>[
        'xcrun',
        'cc',
        '-arch',
        'arm64',
        '-isysroot',
        '',
        '-c',
        '$build/arm64/snapshot_assembly.S',
        '-o',
        '$build/arm64/snapshot_assembly.o',
      ]),
      FakeCommand(command: <String>[
        'xcrun',
        'clang',
        '-arch',
        'armv7',
501
        '-miphoneos-version-min=9.0',
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
        '-dynamiclib',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@executable_path/Frameworks',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@loader_path/Frameworks',
        '-install_name',
        '@rpath/App.framework/App',
        '-isysroot',
        '',
        '-o',
        '$build/armv7/App.framework/App',
        '$build/armv7/snapshot_assembly.o',
      ]),
      FakeCommand(command: <String>[
        'xcrun',
        'clang',
        '-arch',
        'arm64',
524
        '-miphoneos-version-min=9.0',
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
        '-dynamiclib',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@executable_path/Frameworks',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@loader_path/Frameworks',
        '-install_name',
        '@rpath/App.framework/App',
        '-isysroot',
        '',
        '-o',
        '$build/arm64/App.framework/App',
        '$build/arm64/snapshot_assembly.o',
      ]),
      FakeCommand(command: <String>[
        'lipo',
        '$build/armv7/App.framework/App',
        '$build/arm64/App.framework/App',
        '-create',
        '-output',
        '$build/App.framework/App',
      ]),
    ]);
551
    iosEnvironment.defines[kIosArchs] ='armv7 arm64';
552

553
    await const AotAssemblyProfile().build(iosEnvironment);
554

555
    expect(processManager.hasRemainingExpectations, false);
556 557 558 559 560
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });
561

562
  testUsingContext('AotAssemblyProfile with bitcode sends correct argument to snapshotter (one arch)', () async {
563
    iosEnvironment.defines[kIosArchs] = 'arm64';
564
    iosEnvironment.defines[kBitcodeFlag] = 'true';
565
    final String build = iosEnvironment.buildDir.path;
566
    processManager.addCommands(<FakeCommand>[
567 568
      FakeCommand(command: <String>[
        // This path is not known by the cache due to the iOS gen_snapshot split.
569
        'Artifact.genSnapshot.TargetPlatform.ios.profile_arm64',
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
        '--deterministic',
        kAssemblyAot,
        '--assembly=$build/arm64/snapshot_assembly.S',
        '--strip',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ]),
      const FakeCommand(command: <String>[
        'xcrun',
        '--sdk',
        'iphoneos',
        '--show-sdk-path',
      ]),
      FakeCommand(command: <String>[
        'xcrun',
        'cc',
        '-arch',
        'arm64',
        '-isysroot',
        '',
        // Contains bitcode flag.
        '-fembed-bitcode',
        '-c',
        '$build/arm64/snapshot_assembly.S',
        '-o',
        '$build/arm64/snapshot_assembly.o',
      ]),
      FakeCommand(command: <String>[
        'xcrun',
        'clang',
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 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
        '-arch',
        'arm64',
        '-miphoneos-version-min=9.0',
        '-dynamiclib',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@executable_path/Frameworks',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@loader_path/Frameworks',
        '-install_name',
        '@rpath/App.framework/App',
        // Contains bitcode flag.
        '-fembed-bitcode',
        '-isysroot',
        '',
        '-o',
        '$build/arm64/App.framework/App',
        '$build/arm64/snapshot_assembly.o',
      ]),
      FakeCommand(command: <String>[
        'lipo',
        '$build/arm64/App.framework/App',
        '-create',
        '-output',
        '$build/App.framework/App',
      ]),
    ]);

    await const AotAssemblyProfile().build(iosEnvironment);

    expect(processManager.hasRemainingExpectations, false);
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });

  testUsingContext('AotAssemblyRelease configures gen_snapshot with code size directory', () async {
    iosEnvironment.defines[kCodeSizeDirectory] = 'code_size_1';
    iosEnvironment.defines[kIosArchs] = 'arm64';
    iosEnvironment.defines[kBitcodeFlag] = 'true';
    final String build = iosEnvironment.buildDir.path;
    processManager.addCommands(<FakeCommand>[
      FakeCommand(command: <String>[
        // This path is not known by the cache due to the iOS gen_snapshot split.
        'Artifact.genSnapshot.TargetPlatform.ios.profile_arm64',
        '--deterministic',
        '--write-v8-snapshot-profile-to=code_size_1/snapshot.arm64.json',
        '--trace-precompiler-to=code_size_1/trace.arm64.json',
        kAssemblyAot,
        '--assembly=$build/arm64/snapshot_assembly.S',
        '--strip',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ]),
      const FakeCommand(command: <String>[
        'xcrun',
        '--sdk',
        'iphoneos',
        '--show-sdk-path',
      ]),
      FakeCommand(command: <String>[
        'xcrun',
        'cc',
        '-arch',
        'arm64',
        '-isysroot',
        '',
        // Contains bitcode flag.
        '-fembed-bitcode',
        '-c',
        '$build/arm64/snapshot_assembly.S',
        '-o',
        '$build/arm64/snapshot_assembly.o',
      ]),
      FakeCommand(command: <String>[
        'xcrun',
        'clang',
683 684
        '-arch',
        'arm64',
685
        '-miphoneos-version-min=9.0',
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
        '-dynamiclib',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@executable_path/Frameworks',
        '-Xlinker',
        '-rpath',
        '-Xlinker',
        '@loader_path/Frameworks',
        '-install_name',
        '@rpath/App.framework/App',
        // Contains bitcode flag.
        '-fembed-bitcode',
        '-isysroot',
        '',
        '-o',
        '$build/arm64/App.framework/App',
        '$build/arm64/snapshot_assembly.o',
      ]),
      FakeCommand(command: <String>[
        'lipo',
        '$build/arm64/App.framework/App',
        '-create',
        '-output',
        '$build/App.framework/App',
      ]),
    ]);
713

714
    await const AotAssemblyProfile().build(iosEnvironment);
715

716
    expect(processManager.hasRemainingExpectations, false);
717 718 719 720 721
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });
722

723
  testUsingContext('kExtraGenSnapshotOptions passes values to gen_snapshot', () async {
724
    androidEnvironment.defines[kExtraGenSnapshotOptions] = 'foo,bar,baz=2';
725 726
    androidEnvironment.defines[kBuildMode] = getNameForBuildMode(BuildMode.profile);
    final String build = androidEnvironment.buildDir.path;
727

728
    processManager.addCommands(<FakeCommand>[
729
      FakeCommand(command: <String>[
730 731 732 733 734
        artifacts.getArtifactPath(
          Artifact.genSnapshot,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ),
735
        '--deterministic',
736 737 738
        'foo',
        'bar',
        'baz=2',
739 740 741 742 743 744 745 746 747 748
        kElfAot,
        '--elf=$build/app.so',
        '--strip',
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ]),
    ]);
749

750
    await const AotElfRelease(TargetPlatform.android_arm).build(androidEnvironment);
751

752
    expect(processManager.hasRemainingExpectations, false);
753
  });
754
}