bundle.dart 2.03 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:convert/convert.dart';
import 'package:crypto/crypto.dart';
7

8
import 'base/config.dart';
9
import 'base/file_system.dart';
10
import 'build_info.dart';
11
import 'convert.dart';
12
import 'globals.dart' as globals;
13

14
String get defaultMainPath => globals.fs.path.join('lib', 'main.dart');
15
const String defaultManifestPath = 'pubspec.yaml';
16
String get defaultDepfilePath => globals.fs.path.join(getBuildDirectory(), 'snapshot_blob.bin.d');
17

18
String getDefaultApplicationKernelPath({
19
  required bool trackWidgetCreation,
20
}) {
21
  return getKernelPathForTransformerOptions(
22
    globals.fs.path.join(getBuildDirectory(), 'app.dill'),
23 24 25 26
    trackWidgetCreation: trackWidgetCreation,
  );
}

27
String getDefaultCachedKernelPath({
28 29 30 31 32
  required bool trackWidgetCreation,
  required List<String> dartDefines,
  List<String> extraFrontEndOptions = const <String>[],
  FileSystem? fileSystem,
  Config? config,
33 34
}) {
  final StringBuffer buffer = StringBuffer();
35 36
   final List<String> cacheFrontEndOptions = extraFrontEndOptions.toList()
     ..removeWhere((String arg) => arg.startsWith('--enable-experiment=') || arg == '--flutter-widget-cache');
37
  buffer.writeAll(dartDefines);
38
  buffer.writeAll(cacheFrontEndOptions);
39 40 41 42 43 44
  String buildPrefix = '';
  if (buffer.isNotEmpty) {
    final String output = buffer.toString();
    final Digest digest = md5.convert(utf8.encode(output));
    buildPrefix = '${hex.encode(digest.bytes)}.';
  }
45
  return getKernelPathForTransformerOptions(
46 47 48 49
    (fileSystem ?? globals.fs).path.join(getBuildDirectory(
      config ?? globals.config,
     fileSystem ?? globals.fs
    ), '${buildPrefix}cache.dill'),
50 51 52 53
    trackWidgetCreation: trackWidgetCreation,
  );
}

54 55
String getKernelPathForTransformerOptions(
  String path, {
56
  required bool trackWidgetCreation,
57 58 59 60 61 62 63
}) {
  if (trackWidgetCreation) {
    path += '.track.dill';
  }
  return path;
}

64
const String defaultPrivateKeyPath = 'privatekey.der';