size_tests.dart 2.09 KB
Newer Older
1 2 3 4 5 6
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

7 8
import 'package:flutter_devicelab/framework/adb.dart';

9
import '../framework/framework.dart';
10
import '../framework/ios.dart';
11 12 13 14 15
import '../framework/utils.dart';

TaskFunction createBasicMaterialAppSizeTest() {
  return () async {
    const String sampleAppName = 'sample_flutter_app';
16
    final Directory sampleDir = dir('${Directory.systemTemp.path}/$sampleAppName');
17 18 19 20

    if (await sampleDir.exists())
      rmTree(sampleDir);

21
    final Stopwatch watch = new Stopwatch();
Yegor's avatar
Yegor committed
22
    int releaseSizeInBytes;
23 24 25 26 27 28 29 30

    await inDirectory(Directory.systemTemp, () async {
      await flutter('create', options: <String>[sampleAppName]);

      if (!(await sampleDir.exists()))
        throw 'Failed to create sample Flutter app in ${sampleDir.path}';

      await inDirectory(sampleDir, () async {
31
        await flutter('packages', options: <String>['get']);
32
        await flutter('build', options: <String>['clean']);
Yegor's avatar
Yegor committed
33 34

        if (deviceOperatingSystem == DeviceOperatingSystem.ios) {
35
          await prepareProvisioningCertificates(sampleDir.path);
36
          watch.start();
Yegor's avatar
Yegor committed
37
          await flutter('build', options: <String>['ios', '--release']);
38
          watch.stop();
Yegor's avatar
Yegor committed
39 40 41 42
          // IPAs are created manually AFAICT
          await exec('tar', <String>['-zcf', 'build/app.ipa', 'build/ios/Release-iphoneos/Runner.app/']);
          releaseSizeInBytes = await file('${sampleDir.path}/build/app.ipa').length();
        } else {
43
          watch.start();
Yegor's avatar
Yegor committed
44
          await flutter('build', options: <String>['apk', '--release']);
45
          watch.stop();
46
          releaseSizeInBytes = await file('${sampleDir.path}/build/app/outputs/apk/app-release.apk').length();
Yegor's avatar
Yegor committed
47
        }
48 49 50 51
      });
    });

    return new TaskResult.success(
52 53 54 55 56
        <String, dynamic>{
          'release_size_in_bytes': releaseSizeInBytes,
          'build_time_millis': watch.elapsedMilliseconds,
        },
        benchmarkScoreKeys: <String>['release_size_in_bytes', 'build_time_millis']);
57 58
  };
}