common_test.dart 26.4 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
  testWithoutContext('KernelSnapshot handles null result from kernel compilation', () async {
75 76 77
    fileSystem.file('.dart_tool/package_config.json')
      ..createSync(recursive: true)
      ..writeAsStringSync('{"configVersion": 2, "packages":[]}');
78
    final String build = androidEnvironment.buildDir.path;
79
    processManager.addCommands(<FakeCommand>[
80 81
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
82
        '--disable-dart-dev',
83 84
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
85 86 87 88 89
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ) + '/',
90
        '--target=flutter',
91
        '--no-print-incremental-dependencies',
92 93 94 95 96
        '-Ddart.developer.causal_async_stacks=false',
        ...buildModeOptions(BuildMode.profile),
        '--aot',
        '--tfa',
        '--packages',
97
        '/.dart_tool/package_config.json',
98 99 100 101
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
102
        'file:///lib/main.dart',
103 104 105 106 107 108
      ], exitCode: 1),
    ]);

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

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

143
    await const KernelSnapshot().build(androidEnvironment);
144 145

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

148
  testWithoutContext('KernelSnapshot correctly handles an empty string in ExtraFrontEndOptions', () async {
149 150 151
    fileSystem.file('.dart_tool/package_config.json')
      ..createSync(recursive: true)
      ..writeAsStringSync('{"configVersion": 2, "packages":[]}');
152
    final String build = androidEnvironment.buildDir.path;
153
    processManager.addCommands(<FakeCommand>[
154 155
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
156
        '--disable-dart-dev',
157 158
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
159 160 161 162 163
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ) + '/',
164
        '--target=flutter',
165
        '--no-print-incremental-dependencies',
166 167 168 169 170
        '-Ddart.developer.causal_async_stacks=false',
        ...buildModeOptions(BuildMode.profile),
        '--aot',
        '--tfa',
        '--packages',
171
        '/.dart_tool/package_config.json',
172 173 174 175
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
176
        'file:///lib/main.dart',
177 178 179 180 181 182 183
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
    ]);

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

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

186
  testWithoutContext('KernelSnapshot correctly forwards ExtraFrontEndOptions', () async {
187 188 189
    fileSystem.file('.dart_tool/package_config.json')
      ..createSync(recursive: true)
      ..writeAsStringSync('{"configVersion": 2, "packages":[]}');
190
    final String build = androidEnvironment.buildDir.path;
191
    processManager.addCommands(<FakeCommand>[
192 193
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
194
        '--disable-dart-dev',
195 196
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
197 198 199 200 201
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ) + '/',
202
        '--target=flutter',
203
        '--no-print-incremental-dependencies',
204 205 206 207 208
        '-Ddart.developer.causal_async_stacks=false',
        ...buildModeOptions(BuildMode.profile),
        '--aot',
        '--tfa',
        '--packages',
209
        '/.dart_tool/package_config.json',
210 211 212 213 214 215
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
        'foo',
        'bar',
216
        'file:///lib/main.dart',
217 218 219 220 221 222 223
      ], 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);
224
  });
225

226
  testWithoutContext('KernelSnapshot can disable track-widget-creation on debug builds', () async {
227 228 229
    fileSystem.file('.dart_tool/package_config.json')
      ..createSync(recursive: true)
      ..writeAsStringSync('{"configVersion": 2, "packages":[]}');
230
    final String build = androidEnvironment.buildDir.path;
231
    processManager.addCommands(<FakeCommand>[
232 233
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
234
        '--disable-dart-dev',
235 236
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
237 238 239 240 241
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.debug,
        ) + '/',
242
        '--target=flutter',
243
        '--no-print-incremental-dependencies',
244 245 246 247
        '-Ddart.developer.causal_async_stacks=true',
        ...buildModeOptions(BuildMode.debug),
        '--no-link-platform',
        '--packages',
248
        '/.dart_tool/package_config.json',
249 250 251 252
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
253
        'file:///lib/main.dart',
254 255
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
    ]);
256

257
    await const KernelSnapshot().build(androidEnvironment
258
      ..defines[kBuildMode] = getNameForBuildMode(BuildMode.debug)
259
      ..defines[kTrackWidgetCreation] = 'false');
260 261

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

264
  testWithoutContext('KernelSnapshot forces platform linking on debug for darwin target platforms', () async {
265 266 267
    fileSystem.file('.dart_tool/package_config.json')
      ..createSync(recursive: true)
      ..writeAsStringSync('{"configVersion": 2, "packages":[]}');
268
    final String build = androidEnvironment.buildDir.path;
269
    processManager.addCommands(<FakeCommand>[
270 271
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
272
        '--disable-dart-dev',
273 274
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
275 276 277 278 279
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.darwin_x64,
          mode: BuildMode.debug,
        ) + '/',
280
        '--target=flutter',
281
        '--no-print-incremental-dependencies',
282 283 284
        '-Ddart.developer.causal_async_stacks=true',
        ...buildModeOptions(BuildMode.debug),
        '--packages',
285
        '/.dart_tool/package_config.json',
286 287 288 289
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
290
        'file:///lib/main.dart',
291 292
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey $build/app.dill 0\n'),
    ]);
293 294

    await const KernelSnapshot().build(androidEnvironment
295
      ..defines[kTargetPlatform]  = getNameForTargetPlatform(TargetPlatform.darwin_x64)
296
      ..defines[kBuildMode] = getNameForBuildMode(BuildMode.debug)
297
      ..defines[kTrackWidgetCreation] = 'false'
298 299
    );

300
    expect(processManager.hasRemainingExpectations, false);
301
  });
302

303
  testWithoutContext('KernelSnapshot does use track widget creation on debug builds', () async {
304 305 306
    fileSystem.file('.dart_tool/package_config.json')
      ..createSync(recursive: true)
      ..writeAsStringSync('{"configVersion": 2, "packages":[]}');
307
    final Environment testEnvironment = Environment.test(
308
      fileSystem.currentDirectory,
309
      defines: <String, String>{
310
        kBuildMode: getNameForBuildMode(BuildMode.debug),
311
        kTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm),
312
      },
313 314
      processManager: processManager,
      artifacts: artifacts,
315 316
      fileSystem: fileSystem,
      logger: logger,
317 318
    );
    final String build = testEnvironment.buildDir.path;
319
    processManager.addCommands(<FakeCommand>[
320 321
      FakeCommand(command: <String>[
        artifacts.getArtifactPath(Artifact.engineDartBinary),
322
        '--disable-dart-dev',
323 324
        artifacts.getArtifactPath(Artifact.frontendServerSnapshotForEngineDartSdk),
        '--sdk-root',
325 326 327 328 329
        artifacts.getArtifactPath(
          Artifact.flutterPatchedSdkPath,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.debug,
        ) + '/',
330
        '--target=flutter',
331
        '--no-print-incremental-dependencies',
332 333 334 335 336
        '-Ddart.developer.causal_async_stacks=true',
        ...buildModeOptions(BuildMode.debug),
        '--track-widget-creation',
        '--no-link-platform',
        '--packages',
337
        '/.dart_tool/package_config.json',
338 339 340 341
        '--output-dill',
        '$build/app.dill',
        '--depfile',
        '$build/kernel_snapshot.d',
342
        'file:///lib/main.dart',
343 344 345 346 347 348
      ], stdout: 'result $kBoundaryKey\n$kBoundaryKey\n$kBoundaryKey /build/653e11a8e6908714056a57cd6b4f602a/app.dill 0\n'),
    ]);

    await const KernelSnapshot().build(testEnvironment);

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

351
  testUsingContext('AotElfProfile Produces correct output directory', () async {
352
    final String build = androidEnvironment.buildDir.path;
353
    processManager.addCommands(<FakeCommand>[
354
      FakeCommand(command: <String>[
355 356 357 358 359
        artifacts.getArtifactPath(
          Artifact.genSnapshot,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ),
360 361 362 363 364 365 366 367 368 369 370 371 372
        '--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);

373
    await const AotElfProfile(TargetPlatform.android_arm).build(androidEnvironment);
374 375

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

378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
  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);
  });

408
  testUsingContext('AotElfProfile throws error if missing build mode', () async {
409
    androidEnvironment.defines.remove(kBuildMode);
410

411
    expect(const AotElfProfile(TargetPlatform.android_arm).build(androidEnvironment),
412
      throwsA(isA<MissingDefineException>()));
413
  });
414

415
  testUsingContext('AotElfProfile throws error if missing target platform', () async {
416
    androidEnvironment.defines.remove(kTargetPlatform);
417

418
    expect(const AotElfProfile(TargetPlatform.android_arm).build(androidEnvironment),
419
      throwsA(isA<MissingDefineException>()));
420
  });
421

422
  testUsingContext('AotAssemblyProfile throws error if missing build mode', () async {
423
    iosEnvironment.defines.remove(kBuildMode);
424

425
    expect(const AotAssemblyProfile().build(iosEnvironment),
426
      throwsA(isA<MissingDefineException>()));
427 428 429 430 431 432
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });

433

434
  testUsingContext('AotAssemblyProfile throws error if missing target platform', () async {
435
    iosEnvironment.defines.remove(kTargetPlatform);
436

437
    expect(const AotAssemblyProfile().build(iosEnvironment),
438
      throwsA(isA<MissingDefineException>()));
439 440 441 442 443
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });
444

445
  testUsingContext('AotAssemblyProfile throws error if built for non-iOS platform', () async {
446
    expect(const AotAssemblyProfile().build(androidEnvironment),
447
      throwsA(isA<Exception>()));
448 449 450 451 452
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });
453

454
  testUsingContext('AotAssemblyProfile generates multiple arches and lipos together', () async {
455
    final String build = iosEnvironment.buildDir.path;
456
    processManager.addCommands(<FakeCommand>[
457 458
      FakeCommand(command: <String>[
        // This path is not known by the cache due to the iOS gen_snapshot split.
459
        'Artifact.genSnapshot.TargetPlatform.ios.profile_armv7',
460 461 462 463 464 465 466 467 468 469 470 471
        '--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.
472
        'Artifact.genSnapshot.TargetPlatform.ios.profile_arm64',
473 474 475 476 477 478 479 480
        '--deterministic',
        kAssemblyAot,
        '--assembly=$build/arm64/snapshot_assembly.S',
        '--strip',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ]),
481 482 483 484 485 486 487
      const FakeCommand(
        command: <String>[
          'sysctl',
          'hw.optional.arm64',
        ],
        exitCode: 1,
      ),
488 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
      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',
529
        '-miphoneos-version-min=8.0',
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
        '-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',
552
        '-miphoneos-version-min=8.0',
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
        '-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',
      ]),
    ]);
579
    iosEnvironment.defines[kIosArchs] ='armv7 arm64';
580

581
    await const AotAssemblyProfile().build(iosEnvironment);
582

583
    expect(processManager.hasRemainingExpectations, false);
584 585 586 587 588
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });
589

590
  testUsingContext('AotAssemblyProfile with bitcode sends correct argument to snapshotter (one arch)', () async {
591
    iosEnvironment.defines[kIosArchs] = 'arm64';
592
    iosEnvironment.defines[kBitcodeFlag] = 'true';
593
    final String build = iosEnvironment.buildDir.path;
594
    processManager.addCommands(<FakeCommand>[
595 596
      FakeCommand(command: <String>[
        // This path is not known by the cache due to the iOS gen_snapshot split.
597
        'Artifact.genSnapshot.TargetPlatform.ios.profile_arm64',
598 599 600 601 602 603 604 605
        '--deterministic',
        kAssemblyAot,
        '--assembly=$build/arm64/snapshot_assembly.S',
        '--strip',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ]),
606 607 608 609 610 611 612
      const FakeCommand(
        command: <String>[
          'sysctl',
          'hw.optional.arm64',
        ],
        exitCode: 1,
      ),
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
      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',
636 637
        '-arch',
        'arm64',
638
        '-miphoneos-version-min=8.0',
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
        '-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',
      ]),
695 696 697 698 699 700 701
      const FakeCommand(
        command: <String>[
          'sysctl',
          'hw.optional.arm64',
        ],
        exitCode: 1,
      ),
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
      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',
725 726
        '-arch',
        'arm64',
727
        '-miphoneos-version-min=8.0',
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
        '-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',
      ]),
    ]);
755

756
    await const AotAssemblyProfile().build(iosEnvironment);
757

758
    expect(processManager.hasRemainingExpectations, false);
759 760 761 762 763
  }, overrides: <Type, Generator>{
    Platform: () => macPlatform,
    FileSystem: () => fileSystem,
    ProcessManager: () => processManager,
  });
764

765
  testUsingContext('kExtraGenSnapshotOptions passes values to gen_snapshot', () async {
766
    androidEnvironment.defines[kExtraGenSnapshotOptions] = 'foo,bar,baz=2';
767 768
    androidEnvironment.defines[kBuildMode] = getNameForBuildMode(BuildMode.profile);
    final String build = androidEnvironment.buildDir.path;
769

770
    processManager.addCommands(<FakeCommand>[
771
      FakeCommand(command: <String>[
772 773 774 775 776
        artifacts.getArtifactPath(
          Artifact.genSnapshot,
          platform: TargetPlatform.android_arm,
          mode: BuildMode.profile,
        ),
777
        '--deterministic',
778 779 780
        'foo',
        'bar',
        'baz=2',
781 782 783 784 785 786 787 788 789 790
        kElfAot,
        '--elf=$build/app.so',
        '--strip',
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        '--no-causal-async-stacks',
        '--lazy-async-stacks',
        '$build/app.dill',
      ]),
    ]);
791

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

794
    expect(processManager.hasRemainingExpectations, false);
795
  });
796
}