artifacts.dart 5.06 KB
Newer Older
1 2 3 4 5 6
// Copyright 2015 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
import 'package:path/path.dart' as path;
8

Devon Carew's avatar
Devon Carew committed
9
import 'build_configuration.dart';
10
import 'globals.dart';
11

12 13 14
enum ArtifactType {
  snapshot,
  shell,
15
  mojo,
16
  androidClassesJar,
17 18 19
  androidIcuData,
  androidKeystore,
  androidLibSkyShell,
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
}

class Artifact {
  const Artifact._({
    this.name,
    this.fileName,
    this.type,
    this.hostPlatform,
    this.targetPlatform
  });

  final String name;
  final String fileName;
  final ArtifactType type;
  final HostPlatform hostPlatform;
  final TargetPlatform targetPlatform;

  String get platform {
    if (targetPlatform != null)
Devon Carew's avatar
Devon Carew committed
39
      return getNameForTargetPlatform(targetPlatform);
40
    if (hostPlatform != null)
41
      return getNameForHostPlatform(hostPlatform);
42 43 44
    assert(false);
    return null;
  }
45
}
46

47
class ArtifactStore {
48
  static const List<Artifact> knownArtifacts = const <Artifact>[
Devon Carew's avatar
Devon Carew committed
49
    // tester
50
    const Artifact._(
Adam Barth's avatar
Adam Barth committed
51
      name: 'Flutter Tester',
52 53
      fileName: 'sky_shell',
      type: ArtifactType.shell,
54
      targetPlatform: TargetPlatform.linux_x64
55
    ),
Devon Carew's avatar
Devon Carew committed
56 57

    // snapshotters
58 59 60 61
    const Artifact._(
      name: 'Sky Snapshot',
      fileName: 'sky_snapshot',
      type: ArtifactType.snapshot,
62
      hostPlatform: HostPlatform.linux_x64
63 64 65 66 67
    ),
    const Artifact._(
      name: 'Sky Snapshot',
      fileName: 'sky_snapshot',
      type: ArtifactType.snapshot,
68
      hostPlatform: HostPlatform.darwin_x64
69
    ),
Devon Carew's avatar
Devon Carew committed
70 71

    // mojo
72
    const Artifact._(
73 74 75
      name: 'Flutter for Mojo',
      fileName: 'flutter.mojo',
      type: ArtifactType.mojo,
76
      targetPlatform: TargetPlatform.android_arm
77 78
    ),
    const Artifact._(
79 80 81
      name: 'Flutter for Mojo',
      fileName: 'flutter.mojo',
      type: ArtifactType.mojo,
82
      targetPlatform: TargetPlatform.linux_x64
83
    ),
Devon Carew's avatar
Devon Carew committed
84 85

    // android-arm
86 87
    const Artifact._(
      name: 'Compiled Java code',
88 89
      fileName: 'classes.dex.jar',
      type: ArtifactType.androidClassesJar,
90
      targetPlatform: TargetPlatform.android_arm
91 92 93 94 95
    ),
    const Artifact._(
      name: 'ICU data table',
      fileName: 'icudtl.dat',
      type: ArtifactType.androidIcuData,
96
      targetPlatform: TargetPlatform.android_arm
97 98 99 100 101
    ),
    const Artifact._(
      name: 'Key Store',
      fileName: 'chromium-debug.keystore',
      type: ArtifactType.androidKeystore,
102
      targetPlatform: TargetPlatform.android_arm
103 104 105 106 107
    ),
    const Artifact._(
      name: 'Compiled C++ code',
      fileName: 'libsky_shell.so',
      type: ArtifactType.androidLibSkyShell,
108
      targetPlatform: TargetPlatform.android_arm
109
    ),
Devon Carew's avatar
Devon Carew committed
110

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    // android-x86
    const Artifact._(
      name: 'Compiled Java code',
      fileName: 'classes.dex.jar',
      type: ArtifactType.androidClassesJar,
      targetPlatform: TargetPlatform.android_x64
    ),
    const Artifact._(
      name: 'ICU data table',
      fileName: 'icudtl.dat',
      type: ArtifactType.androidIcuData,
      targetPlatform: TargetPlatform.android_x64
    ),
    const Artifact._(
      name: 'Key Store',
      fileName: 'chromium-debug.keystore',
      type: ArtifactType.androidKeystore,
      targetPlatform: TargetPlatform.android_x64
    ),
    const Artifact._(
      name: 'Compiled C++ code',
      fileName: 'libsky_shell.so',
      type: ArtifactType.androidLibSkyShell,
      targetPlatform: TargetPlatform.android_x64
    ),
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
  ];

  static Artifact getArtifact({
    ArtifactType type,
    HostPlatform hostPlatform,
    TargetPlatform targetPlatform
  }) {
    for (Artifact artifact in ArtifactStore.knownArtifacts) {
      if (type != null &&
          type != artifact.type)
        continue;
      if (hostPlatform != null &&
          artifact.hostPlatform != null &&
          hostPlatform != artifact.hostPlatform)
        continue;
      if (targetPlatform != null &&
          artifact.targetPlatform != null &&
          targetPlatform != artifact.targetPlatform)
        continue;
      return artifact;
    }
    return null;
  }

160
  // Initialized by FlutterCommandRunner on startup.
161 162
  static String flutterRoot;

163
  static String _engineRevision;
164

165
  static String get engineRevision {
166
    if (_engineRevision == null) {
167
      File revisionFile = new File(path.join(flutterRoot, 'bin', 'cache', 'engine.version'));
168
      if (revisionFile.existsSync())
169
        _engineRevision = revisionFile.readAsStringSync().trim();
170
    }
171
    return _engineRevision;
172 173
  }

174 175
  static Directory _getBaseCacheDir() {
    return new Directory(path.join(flutterRoot, 'bin', 'cache', 'artifacts'));
176 177
  }

178 179 180
  // TODO(devoncarew): There are 5 call-sites of this (run_mojo, build_apk, the
  // test command, toolchain, setup_xcodeproj); move them over to using
  // something from `cache.dart`.
Devon Carew's avatar
Devon Carew committed
181
  static String getPath(Artifact artifact) {
182 183 184
    File cachedFile = new File(
      path.join(_getBaseCacheDir().path, 'engine', artifact.platform, artifact.fileName)
    );
185

186 187
    if (!cachedFile.existsSync()) {
      printError('File not found in the platform artifacts: ${cachedFile.path}');
188 189 190
      return null;
    } else {
      return cachedFile.path;
191
    }
192
  }
193
}