build_test.dart 25.5 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
import 'dart:async';
6
import 'dart:convert';
7

8
import 'package:file/memory.dart';
9
import 'package:flutter_tools/src/android/android_sdk.dart';
10
import 'package:flutter_tools/src/artifacts.dart';
11
import 'package:flutter_tools/src/build_info.dart';
12
import 'package:flutter_tools/src/base/build.dart';
13
import 'package:flutter_tools/src/base/context.dart';
14
import 'package:flutter_tools/src/base/file_system.dart';
15
import 'package:flutter_tools/src/base/io.dart';
16
import 'package:flutter_tools/src/base/logger.dart';
17
import 'package:flutter_tools/src/base/process.dart';
18
import 'package:flutter_tools/src/macos/xcode.dart';
19 20
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
21
import 'package:process/process.dart';
22

23 24
import '../../src/common.dart';
import '../../src/context.dart';
25

26
class MockFlutterVersion extends Mock implements FlutterVersion {}
27
class MockAndroidSdk extends Mock implements AndroidSdk {}
28
class MockArtifacts extends Mock implements Artifacts {}
29
class MockXcode extends Mock implements Xcode {}
30 31
class MockProcessManager extends Mock implements ProcessManager {}
class MockProcess extends Mock implements Process {}
32

33 34
class _FakeGenSnapshot implements GenSnapshot {
  _FakeGenSnapshot({
35
    this.succeed = true,
36 37 38
  });

  final bool succeed;
39
  Map<String, String> outputs = <String, String>{};
40
  int _callCount = 0;
41 42 43
  SnapshotType _snapshotType;
  String _depfilePath;
  List<String> _additionalArgs;
44 45 46

  int get callCount => _callCount;

47 48 49 50 51 52
  SnapshotType get snapshotType => _snapshotType;

  String get depfilePath => _depfilePath;

  List<String> get additionalArgs => _additionalArgs;

53 54 55 56
  @override
  Future<int> run({
    SnapshotType snapshotType,
    String depfilePath,
57
    DarwinArch darwinArch,
58
    Iterable<String> additionalArgs = const <String>[],
59 60
  }) async {
    _callCount += 1;
61 62 63
    _snapshotType = snapshotType;
    _depfilePath = depfilePath;
    _additionalArgs = additionalArgs.toList();
64

65
    if (!succeed) {
66
      return 1;
67
    }
68 69 70
    outputs.forEach((String filePath, String fileContent) {
      fs.file(filePath).writeAsString(fileContent);
    });
71 72 73 74
    return 0;
  }
}

75
void main() {
76 77 78
  group('SnapshotType', () {
    test('throws, if build mode is null', () {
      expect(
79
        () => SnapshotType(TargetPlatform.android_x64, null),
80 81 82 83
        throwsA(anything),
      );
    });
    test('does not throw, if target platform is null', () {
84
      expect(SnapshotType(null, BuildMode.release), isNotNull);
85 86
    });
  });
87

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
  group('GenSnapshot', () {
    GenSnapshot genSnapshot;
    MockArtifacts mockArtifacts;
    MockProcessManager mockProcessManager;
    MockProcess mockProc;

    setUp(() async {
      genSnapshot = const GenSnapshot();
      mockArtifacts = MockArtifacts();
      mockProcessManager = MockProcessManager();
      mockProc = MockProcess();
    });

    final Map<Type, Generator> contextOverrides = <Type, Generator>{
      Artifacts: () => mockArtifacts,
      ProcessManager: () => mockProcessManager,
    };

    testUsingContext('android_x64', () async {
      when(mockArtifacts.getArtifactPath(Artifact.genSnapshot,
              platform: TargetPlatform.android_x64, mode: BuildMode.release))
          .thenReturn('gen_snapshot');
      when(mockProcessManager.start(any,
              workingDirectory: anyNamed('workingDirectory'),
              environment: anyNamed('environment')))
          .thenAnswer((_) => Future<Process>.value(mockProc));
      when(mockProc.stdout).thenAnswer((_) => const Stream<List<int>>.empty());
      when(mockProc.stderr).thenAnswer((_) => const Stream<List<int>>.empty());
      await genSnapshot.run(
          snapshotType:
              SnapshotType(TargetPlatform.android_x64, BuildMode.release),
          darwinArch: null,
          additionalArgs: <String>['--additional_arg']);
121 122 123 124 125 126 127 128 129
      verify(mockProcessManager.start(
        <String>[
          'gen_snapshot',
          '--causal_async_stacks',
          '--additional_arg',
        ],
        workingDirectory: anyNamed('workingDirectory'),
        environment: anyNamed('environment'),
      )).called(1);
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    }, overrides: contextOverrides);

    testUsingContext('iOS armv7', () async {
      when(mockArtifacts.getArtifactPath(Artifact.genSnapshot,
              platform: TargetPlatform.ios, mode: BuildMode.release))
          .thenReturn('gen_snapshot');
      when(mockProcessManager.start(any,
              workingDirectory: anyNamed('workingDirectory'),
              environment: anyNamed('environment')))
          .thenAnswer((_) => Future<Process>.value(mockProc));
      when(mockProc.stdout).thenAnswer((_) => const Stream<List<int>>.empty());
      when(mockProc.stderr).thenAnswer((_) => const Stream<List<int>>.empty());
      await genSnapshot.run(
          snapshotType: SnapshotType(TargetPlatform.ios, BuildMode.release),
          darwinArch: DarwinArch.armv7,
          additionalArgs: <String>['--additional_arg']);
146 147 148 149 150 151 152 153 154
      verify(mockProcessManager.start(
        <String>[
          'gen_snapshot_armv7',
          '--causal_async_stacks',
          '--additional_arg',
        ],
        workingDirectory: anyNamed('workingDirectory'),
        environment: anyNamed('environment')),
      ).called(1);
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    }, overrides: contextOverrides);

    testUsingContext('iOS arm64', () async {
      when(mockArtifacts.getArtifactPath(Artifact.genSnapshot,
              platform: TargetPlatform.ios, mode: BuildMode.release))
          .thenReturn('gen_snapshot');
      when(mockProcessManager.start(any,
              workingDirectory: anyNamed('workingDirectory'),
              environment: anyNamed('environment')))
          .thenAnswer((_) => Future<Process>.value(mockProc));
      when(mockProc.stdout).thenAnswer((_) => const Stream<List<int>>.empty());
      when(mockProc.stderr).thenAnswer((_) => const Stream<List<int>>.empty());
      await genSnapshot.run(
          snapshotType: SnapshotType(TargetPlatform.ios, BuildMode.release),
          darwinArch: DarwinArch.arm64,
          additionalArgs: <String>['--additional_arg']);
171 172 173 174 175 176 177 178 179
      verify(mockProcessManager.start(
        <String>[
          'gen_snapshot_arm64',
          '--causal_async_stacks',
          '--additional_arg',
        ],
        workingDirectory: anyNamed('workingDirectory'),
        environment: anyNamed('environment'),
      )).called(1);
180 181 182 183 184 185 186 187 188 189 190 191 192
    }, overrides: contextOverrides);

    testUsingContext('--strip filters outputs', () async {
      when(mockArtifacts.getArtifactPath(Artifact.genSnapshot,
              platform: TargetPlatform.android_x64, mode: BuildMode.release))
          .thenReturn('gen_snapshot');
      when(mockProcessManager.start(
              <String>['gen_snapshot', '--causal_async_stacks', '--strip'],
              workingDirectory: anyNamed('workingDirectory'),
              environment: anyNamed('environment')))
          .thenAnswer((_) => Future<Process>.value(mockProc));
      when(mockProc.stdout).thenAnswer((_) => const Stream<List<int>>.empty());
      when(mockProc.stderr)
193 194 195 196 197 198
        .thenAnswer((_) => Stream<String>.fromIterable(<String>[
          '--ABC\n',
          'Warning: Generating ELF library without DWARF debugging information.\n',
          '--XYZ\n',
        ])
        .transform<List<int>>(utf8.encoder));
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
      await genSnapshot.run(
          snapshotType:
              SnapshotType(TargetPlatform.android_x64, BuildMode.release),
          darwinArch: null,
          additionalArgs: <String>['--strip']);
      verify(mockProcessManager.start(
              <String>['gen_snapshot', '--causal_async_stacks', '--strip'],
              workingDirectory: anyNamed('workingDirectory'),
              environment: anyNamed('environment')))
          .called(1);
      expect(testLogger.errorText, contains('ABC'));
      expect(testLogger.errorText, isNot(contains('ELF library')));
      expect(testLogger.errorText, contains('XYZ'));
    }, overrides: contextOverrides);
  });

215
  group('Snapshotter - AOT', () {
216
    const String kSnapshotDart = 'snapshot.dart';
217
    const String kSDKPath = '/path/to/sdk';
218 219 220 221
    String skyEnginePath;

    _FakeGenSnapshot genSnapshot;
    MemoryFileSystem fs;
222
    AOTSnapshotter snapshotter;
223
    AOTSnapshotter snapshotterWithTimings;
224
    MockAndroidSdk mockAndroidSdk;
225 226
    MockArtifacts mockArtifacts;
    MockXcode mockXcode;
227
    BufferLogger bufferLogger;
228 229

    setUp(() async {
230
      fs = MemoryFileSystem();
231 232 233
      fs.file(kSnapshotDart).createSync();
      fs.file('.packages').writeAsStringSync('sky_engine:file:///flutter/bin/cache/pkg/sky_engine/lib/');

234
      skyEnginePath = fs.path.fromUri(Uri.file('/flutter/bin/cache/pkg/sky_engine'));
235 236 237 238 239 240
      fs.directory(fs.path.join(skyEnginePath, 'lib', 'ui')).createSync(recursive: true);
      fs.directory(fs.path.join(skyEnginePath, 'sdk_ext')).createSync(recursive: true);
      fs.file(fs.path.join(skyEnginePath, '.packages')).createSync();
      fs.file(fs.path.join(skyEnginePath, 'lib', 'ui', 'ui.dart')).createSync();
      fs.file(fs.path.join(skyEnginePath, 'sdk_ext', 'vmservice_io.dart')).createSync();

241 242
      genSnapshot = _FakeGenSnapshot();
      snapshotter = AOTSnapshotter();
243
      snapshotterWithTimings = AOTSnapshotter(reportTimings: true);
244 245 246
      mockAndroidSdk = MockAndroidSdk();
      mockArtifacts = MockArtifacts();
      mockXcode = MockXcode();
247 248
      when(mockXcode.iPhoneSdkLocation()).thenAnswer((_) => Future<String>.value(kSDKPath));

249
      bufferLogger = BufferLogger();
250
      for (BuildMode mode in BuildMode.values) {
251 252
        when(mockArtifacts.getArtifactPath(Artifact.snapshotDart,
            platform: anyNamed('platform'), mode: mode)).thenReturn(kSnapshotDart);
253 254 255 256
      }
    });

    final Map<Type, Generator> contextOverrides = <Type, Generator>{
257
      AndroidSdk: () => mockAndroidSdk,
258 259
      Artifacts: () => mockArtifacts,
      FileSystem: () => fs,
260
      ProcessManager: () => FakeProcessManager.any(),
261 262
      GenSnapshot: () => genSnapshot,
      Xcode: () => mockXcode,
263
      Logger: () => bufferLogger,
264 265
    };

266
    testUsingContext('iOS debug AOT snapshot is invalid', () async {
267
      final String outputPath = fs.path.join('build', 'foo');
268
      expect(await snapshotter.build(
269 270
        platform: TargetPlatform.ios,
        buildMode: BuildMode.debug,
271
        mainPath: 'main.dill',
272 273
        packagesPath: '.packages',
        outputPath: outputPath,
274
        bitcode: false,
275
      ), isNot(equals(0)));
276 277
    }, overrides: contextOverrides);

278
    testUsingContext('Android arm debug AOT snapshot is invalid', () async {
279 280 281 282 283 284 285
      final String outputPath = fs.path.join('build', 'foo');
      expect(await snapshotter.build(
        platform: TargetPlatform.android_arm,
        buildMode: BuildMode.debug,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
286
        bitcode: false,
287 288 289
      ), isNot(0));
    }, overrides: contextOverrides);

290 291 292 293 294 295 296 297
    testUsingContext('Android arm64 debug AOT snapshot is invalid', () async {
      final String outputPath = fs.path.join('build', 'foo');
      expect(await snapshotter.build(
        platform: TargetPlatform.android_arm64,
        buildMode: BuildMode.debug,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
298
        bitcode: false,
299 300 301
      ), isNot(0));
    }, overrides: contextOverrides);

302
    testUsingContext('iOS profile AOT with bitcode uses right flags', () async {
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
      fs.file('main.dill').writeAsStringSync('binary magic');

      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);

      final String assembly = fs.path.join(outputPath, 'snapshot_assembly.S');
      genSnapshot.outputs = <String, String>{
        assembly: 'blah blah\n.section __DWARF\nblah blah\n',
      };

      final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
      when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
      when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));

      final int genSnapshotExitCode = await snapshotter.build(
        platform: TargetPlatform.ios,
        buildMode: BuildMode.profile,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
323
        darwinArch: DarwinArch.armv7,
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
        bitcode: true,
      );

      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
      expect(genSnapshot.snapshotType.platform, TargetPlatform.ios);
      expect(genSnapshot.snapshotType.mode, BuildMode.profile);
      expect(genSnapshot.additionalArgs, <String>[
        '--deterministic',
        '--snapshot_kind=app-aot-assembly',
        '--assembly=$assembly',
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        'main.dill',
      ]);

340 341 342 343 344 345 346 347 348 349 350 351 352
      final VerificationResult toVerifyCC = verify(xcode.cc(captureAny));
      expect(toVerifyCC.callCount, 1);
      final dynamic ccArgs = toVerifyCC.captured.first;
      expect(ccArgs, contains('-fembed-bitcode'));
      expect(ccArgs, contains('-isysroot'));
      expect(ccArgs, contains(kSDKPath));

      final VerificationResult toVerifyClang = verify(xcode.clang(captureAny));
      expect(toVerifyClang.callCount, 1);
      final dynamic clangArgs = toVerifyClang.captured.first;
      expect(clangArgs, contains('-fembed-bitcode'));
      expect(clangArgs, contains('-isysroot'));
      expect(clangArgs, contains(kSDKPath));
353

354 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 387 388 389 390 391 392 393 394 395 396
      final File assemblyFile = fs.file(assembly);
      expect(assemblyFile.existsSync(), true);
      expect(assemblyFile.readAsStringSync().contains('.section __DWARF'), true);
    }, overrides: contextOverrides);

    testUsingContext('iOS release AOT with bitcode uses right flags', () async {
      fs.file('main.dill').writeAsStringSync('binary magic');

      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);

      final String assembly = fs.path.join(outputPath, 'snapshot_assembly.S');
      genSnapshot.outputs = <String, String>{
        assembly: 'blah blah\n.section __DWARF\nblah blah\n',
      };

      final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
      when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
      when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));

      final int genSnapshotExitCode = await snapshotter.build(
        platform: TargetPlatform.ios,
        buildMode: BuildMode.release,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
        darwinArch: DarwinArch.armv7,
        bitcode: true,
      );

      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
      expect(genSnapshot.snapshotType.platform, TargetPlatform.ios);
      expect(genSnapshot.snapshotType.mode, BuildMode.release);
      expect(genSnapshot.additionalArgs, <String>[
        '--deterministic',
        '--snapshot_kind=app-aot-assembly',
        '--assembly=$assembly',
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        'main.dill',
      ]);

397 398 399 400 401 402 403 404 405 406 407 408 409
      final VerificationResult toVerifyCC = verify(xcode.cc(captureAny));
      expect(toVerifyCC.callCount, 1);
      final dynamic ccArgs = toVerifyCC.captured.first;
      expect(ccArgs, contains('-fembed-bitcode'));
      expect(ccArgs, contains('-isysroot'));
      expect(ccArgs, contains(kSDKPath));

      final VerificationResult toVerifyClang = verify(xcode.clang(captureAny));
      expect(toVerifyClang.callCount, 1);
      final dynamic clangArgs = toVerifyClang.captured.first;
      expect(clangArgs, contains('-fembed-bitcode'));
      expect(clangArgs, contains('-isysroot'));
      expect(clangArgs, contains(kSDKPath));
410

411
      final File assemblyFile = fs.file(assembly);
412
      final File assemblyBitcodeFile = fs.file('$assembly.stripped.S');
413 414 415 416 417 418
      expect(assemblyFile.existsSync(), true);
      expect(assemblyBitcodeFile.existsSync(), true);
      expect(assemblyFile.readAsStringSync().contains('.section __DWARF'), true);
      expect(assemblyBitcodeFile.readAsStringSync().contains('.section __DWARF'), false);
    }, overrides: contextOverrides);

419 420 421 422 423 424
    testUsingContext('builds iOS armv7 profile AOT snapshot', () async {
      fs.file('main.dill').writeAsStringSync('binary magic');

      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);

425
      final String assembly = fs.path.join(outputPath, 'snapshot_assembly.S');
426
      genSnapshot.outputs = <String, String>{
427
        assembly: 'blah blah\n.section __DWARF\nblah blah\n',
428 429
      };

430 431 432
      final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
      when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
      when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
433 434 435 436 437 438 439

      final int genSnapshotExitCode = await snapshotter.build(
        platform: TargetPlatform.ios,
        buildMode: BuildMode.profile,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
440
        darwinArch: DarwinArch.armv7,
441
        bitcode: false,
442 443 444 445 446 447 448
      );

      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
      expect(genSnapshot.snapshotType.platform, TargetPlatform.ios);
      expect(genSnapshot.snapshotType.mode, BuildMode.profile);
      expect(genSnapshot.additionalArgs, <String>[
449
        '--deterministic',
450
        '--snapshot_kind=app-aot-assembly',
451
        '--assembly=$assembly',
452 453 454 455
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        'main.dill',
      ]);
456 457 458
      verifyNever(xcode.cc(argThat(contains('-fembed-bitcode'))));
      verifyNever(xcode.clang(argThat(contains('-fembed-bitcode'))));

459 460 461
      verify(xcode.cc(argThat(contains('-isysroot')))).called(1);
      verify(xcode.clang(argThat(contains('-isysroot')))).called(1);

462 463 464
      final File assemblyFile = fs.file(assembly);
      expect(assemblyFile.existsSync(), true);
      expect(assemblyFile.readAsStringSync().contains('.section __DWARF'), true);
465 466 467
    }, overrides: contextOverrides);

    testUsingContext('builds iOS arm64 profile AOT snapshot', () async {
468
      fs.file('main.dill').writeAsStringSync('binary magic');
469 470 471 472 473 474 475 476

      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);

      genSnapshot.outputs = <String, String>{
        fs.path.join(outputPath, 'snapshot_assembly.S'): '',
      };

477 478 479
      final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
      when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
      when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
480

481
      final int genSnapshotExitCode = await snapshotter.build(
482 483
        platform: TargetPlatform.ios,
        buildMode: BuildMode.profile,
484
        mainPath: 'main.dill',
485 486
        packagesPath: '.packages',
        outputPath: outputPath,
487
        darwinArch: DarwinArch.arm64,
488
        bitcode: false,
489 490 491 492 493 494 495
      );

      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
      expect(genSnapshot.snapshotType.platform, TargetPlatform.ios);
      expect(genSnapshot.snapshotType.mode, BuildMode.profile);
      expect(genSnapshot.additionalArgs, <String>[
496
        '--deterministic',
497 498 499 500 501 502
        '--snapshot_kind=app-aot-assembly',
        '--assembly=${fs.path.join(outputPath, 'snapshot_assembly.S')}',
        'main.dill',
      ]);
    }, overrides: contextOverrides);

503 504 505 506 507 508 509 510 511 512
    testUsingContext('builds iOS release armv7 AOT snapshot', () async {
      fs.file('main.dill').writeAsStringSync('binary magic');

      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);

      genSnapshot.outputs = <String, String>{
        fs.path.join(outputPath, 'snapshot_assembly.S'): '',
      };

513 514 515
      final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
      when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
      when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
516 517 518 519 520 521 522

      final int genSnapshotExitCode = await snapshotter.build(
        platform: TargetPlatform.ios,
        buildMode: BuildMode.release,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
523
        darwinArch: DarwinArch.armv7,
524
        bitcode: false,
525 526 527 528 529 530 531
      );

      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
      expect(genSnapshot.snapshotType.platform, TargetPlatform.ios);
      expect(genSnapshot.snapshotType.mode, BuildMode.release);
      expect(genSnapshot.additionalArgs, <String>[
532
        '--deterministic',
533 534 535 536 537 538 539 540 541
        '--snapshot_kind=app-aot-assembly',
        '--assembly=${fs.path.join(outputPath, 'snapshot_assembly.S')}',
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        'main.dill',
      ]);
    }, overrides: contextOverrides);

    testUsingContext('builds iOS release arm64 AOT snapshot', () async {
542
      fs.file('main.dill').writeAsStringSync('binary magic');
543 544 545 546 547 548 549 550

      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);

      genSnapshot.outputs = <String, String>{
        fs.path.join(outputPath, 'snapshot_assembly.S'): '',
      };

551 552 553
      final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
      when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
      when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
554

555
      final int genSnapshotExitCode = await snapshotter.build(
556 557
        platform: TargetPlatform.ios,
        buildMode: BuildMode.release,
558
        mainPath: 'main.dill',
559 560
        packagesPath: '.packages',
        outputPath: outputPath,
561
        darwinArch: DarwinArch.arm64,
562
        bitcode: false,
563 564 565 566 567 568 569
      );

      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
      expect(genSnapshot.snapshotType.platform, TargetPlatform.ios);
      expect(genSnapshot.snapshotType.mode, BuildMode.release);
      expect(genSnapshot.additionalArgs, <String>[
570
        '--deterministic',
571 572 573 574 575
        '--snapshot_kind=app-aot-assembly',
        '--assembly=${fs.path.join(outputPath, 'snapshot_assembly.S')}',
        'main.dill',
      ]);
    }, overrides: contextOverrides);
576

577 578
    testUsingContext('builds shared library for android-arm', () async {
      fs.file('main.dill').writeAsStringSync('binary magic');
579

580 581
      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);
582 583

      final int genSnapshotExitCode = await snapshotter.build(
584
        platform: TargetPlatform.android_arm,
585 586 587 588
        buildMode: BuildMode.release,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
589
        bitcode: false,
590 591
      );

592 593 594 595 596 597 598 599
      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
      expect(genSnapshot.snapshotType.platform, TargetPlatform.android_arm);
      expect(genSnapshot.snapshotType.mode, BuildMode.release);
      expect(genSnapshot.additionalArgs, <String>[
        '--deterministic',
        '--snapshot_kind=app-aot-elf',
        '--elf=build/foo/app.so',
600
        '--strip',
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
        '--no-sim-use-hardfp',
        '--no-use-integer-division',
        'main.dill',
      ]);
    }, overrides: contextOverrides);

    testUsingContext('builds shared library for android-arm64', () async {
      fs.file('main.dill').writeAsStringSync('binary magic');

      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);

      final int genSnapshotExitCode = await snapshotter.build(
        platform: TargetPlatform.android_arm64,
        buildMode: BuildMode.release,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
619
        bitcode: false,
620 621 622 623 624 625 626 627 628 629
      );

      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
      expect(genSnapshot.snapshotType.platform, TargetPlatform.android_arm64);
      expect(genSnapshot.snapshotType.mode, BuildMode.release);
      expect(genSnapshot.additionalArgs, <String>[
        '--deterministic',
        '--snapshot_kind=app-aot-elf',
        '--elf=build/foo/app.so',
630
        '--strip',
631 632
        'main.dill',
      ]);
633
    }, overrides: contextOverrides);
634

635 636 637 638 639 640 641
    testUsingContext('reports timing', () async {
      fs.file('main.dill').writeAsStringSync('binary magic');

      final String outputPath = fs.path.join('build', 'foo');
      fs.directory(outputPath).createSync(recursive: true);

      genSnapshot.outputs = <String, String>{
642
        fs.path.join(outputPath, 'app.so'): '',
643 644 645 646 647 648 649 650 651 652 653 654
      };

      final RunResult successResult = RunResult(ProcessResult(1, 0, '', ''), <String>['command name', 'arguments...']);
      when(xcode.cc(any)).thenAnswer((_) => Future<RunResult>.value(successResult));
      when(xcode.clang(any)).thenAnswer((_) => Future<RunResult>.value(successResult));

      final int genSnapshotExitCode = await snapshotterWithTimings.build(
        platform: TargetPlatform.android_arm,
        buildMode: BuildMode.release,
        mainPath: 'main.dill',
        packagesPath: '.packages',
        outputPath: outputPath,
655
        bitcode: false,
656 657 658 659
      );

      expect(genSnapshotExitCode, 0);
      expect(genSnapshot.callCount, 1);
660
      expect(bufferLogger.statusText, matches(RegExp(r'snapshot\(CompileTime\): \d+ ms.')));
661
    }, overrides: contextOverrides);
662
  });
663
}