Commit 32846de9 authored by Jason Simmons's avatar Jason Simmons

Remove ArtifactStore and move flutterRoot into Cache (#3883)

parent 42209575
// 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';
import 'package:path/path.dart' as path;
import 'build_info.dart';
import 'globals.dart';
enum ArtifactType {
snapshot,
shell,
mojo,
androidClassesJar,
androidIcuData,
androidKeystore,
androidLibSkyShell,
}
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)
return getNameForTargetPlatform(targetPlatform);
if (hostPlatform != null)
return getNameForHostPlatform(hostPlatform);
assert(false);
return null;
}
}
class ArtifactStore {
static const List<Artifact> knownArtifacts = const <Artifact>[
// tester
const Artifact._(
name: 'Flutter Tester',
fileName: 'sky_shell',
type: ArtifactType.shell,
targetPlatform: TargetPlatform.linux_x64
),
// snapshotters
const Artifact._(
name: 'Sky Snapshot',
fileName: 'sky_snapshot',
type: ArtifactType.snapshot,
hostPlatform: HostPlatform.linux_x64
),
const Artifact._(
name: 'Sky Snapshot',
fileName: 'sky_snapshot',
type: ArtifactType.snapshot,
hostPlatform: HostPlatform.darwin_x64
),
// mojo
const Artifact._(
name: 'Flutter for Mojo',
fileName: 'flutter.mojo',
type: ArtifactType.mojo,
targetPlatform: TargetPlatform.android_arm
),
const Artifact._(
name: 'Flutter for Mojo',
fileName: 'flutter.mojo',
type: ArtifactType.mojo,
targetPlatform: TargetPlatform.linux_x64
),
// android-arm
const Artifact._(
name: 'Compiled Java code',
fileName: 'classes.dex.jar',
type: ArtifactType.androidClassesJar,
targetPlatform: TargetPlatform.android_arm
),
const Artifact._(
name: 'ICU data table',
fileName: 'icudtl.dat',
type: ArtifactType.androidIcuData,
targetPlatform: TargetPlatform.android_arm
),
const Artifact._(
name: 'Key Store',
fileName: 'chromium-debug.keystore',
type: ArtifactType.androidKeystore,
targetPlatform: TargetPlatform.android_arm
),
const Artifact._(
name: 'Compiled C++ code',
fileName: 'libsky_shell.so',
type: ArtifactType.androidLibSkyShell,
targetPlatform: TargetPlatform.android_arm
),
// 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
),
];
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;
}
// Initialized by FlutterCommandRunner on startup.
static String flutterRoot;
static String _engineRevision;
static String get engineRevision {
if (_engineRevision == null) {
File revisionFile = new File(path.join(flutterRoot, 'bin', 'cache', 'engine.version'));
if (revisionFile.existsSync())
_engineRevision = revisionFile.readAsStringSync().trim();
}
return _engineRevision;
}
static Directory _getBaseCacheDir() {
return new Directory(path.join(flutterRoot, 'bin', 'cache', 'artifacts'));
}
// 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`.
static String getPath(Artifact artifact) {
File cachedFile = new File(
path.join(_getBaseCacheDir().path, 'engine', artifact.platform, artifact.fileName)
);
if (!cachedFile.existsSync()) {
printError('File not found in the platform artifacts: ${cachedFile.path}');
return null;
} else {
return cachedFile.path;
}
}
}
......@@ -7,7 +7,6 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import 'artifacts.dart';
import 'base/context.dart';
import 'base/logger.dart';
import 'base/os.dart';
......@@ -22,6 +21,20 @@ class Cache {
Directory _rootOverride;
// Initialized by FlutterCommandRunner on startup.
static String flutterRoot;
static String _engineRevision;
static String get engineRevision {
if (_engineRevision == null) {
File revisionFile = new File(path.join(flutterRoot, 'bin', 'cache', 'engine.version'));
if (revisionFile.existsSync())
_engineRevision = revisionFile.readAsStringSync().trim();
}
return _engineRevision;
}
static Cache get instance => context[Cache] ?? (context[Cache] = new Cache());
/// Return the top-level directory in the cache; this is `bin/cache`.
......@@ -29,7 +42,7 @@ class Cache {
if (_rootOverride != null)
return new Directory(path.join(_rootOverride.path, 'bin', 'cache'));
else
return new Directory(path.join(ArtifactStore.flutterRoot, 'bin', 'cache'));
return new Directory(path.join(flutterRoot, 'bin', 'cache'));
}
/// Return a directory in the cache dir. For `pkg`, this will return `bin/cache/pkg`.
......
......@@ -10,8 +10,8 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart' as yaml;
import '../artifacts.dart';
import '../base/utils.dart';
import '../cache.dart';
import '../dart/analysis.dart';
import '../dart/sdk.dart';
import '../globals.dart';
......@@ -66,7 +66,7 @@ class AnalyzeCommand extends FlutterCommand {
List<String> flutterRootComponents;
bool isFlutterLibrary(String filename) {
flutterRootComponents ??= path.normalize(path.absolute(ArtifactStore.flutterRoot)).split(path.separator);
flutterRootComponents ??= path.normalize(path.absolute(Cache.flutterRoot)).split(path.separator);
List<String> filenameComponents = path.normalize(path.absolute(filename)).split(path.separator);
if (filenameComponents.length < flutterRootComponents.length + 4) // the 4: 'packages', package_name, 'lib', file_name
return false;
......@@ -195,7 +195,7 @@ class AnalyzeCommand extends FlutterCommand {
DriverOptions options = new DriverOptions();
options.dartSdkPath = argResults['dart-sdk'];
options.packageMap = packages;
options.analysisOptionsFile = path.join(ArtifactStore.flutterRoot, 'packages', 'flutter_tools', 'flutter_analysis_options');
options.analysisOptionsFile = path.join(Cache.flutterRoot, 'packages', 'flutter_tools', 'flutter_analysis_options');
AnalysisDriver analyzer = new AnalysisDriver(options);
//TODO (pq): consider error handling
......@@ -397,11 +397,11 @@ class PackageDependency {
}
bool get hasConflict => values.length > 1;
bool get hasConflictAffectingFlutterRepo {
assert(path.isAbsolute(ArtifactStore.flutterRoot));
assert(path.isAbsolute(Cache.flutterRoot));
for (List<String> targetSources in values.values) {
for (String source in targetSources) {
assert(path.isAbsolute(source));
if (path.isWithin(ArtifactStore.flutterRoot, source))
if (path.isWithin(Cache.flutterRoot, source))
return true;
}
}
......
......@@ -8,7 +8,6 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import '../android/android.dart' as android;
import '../artifacts.dart';
import '../base/utils.dart';
import '../cache.dart';
import '../dart/pub.dart';
......@@ -64,7 +63,7 @@ class CreateCommand extends FlutterCommand {
return 2;
}
if (ArtifactStore.flutterRoot == null) {
if (Cache.flutterRoot == null) {
printError('Neither the --flutter-root command line flag nor the FLUTTER_ROOT environment\n'
'variable was specified. Unable to find package:flutter.');
return 2;
......@@ -72,7 +71,7 @@ class CreateCommand extends FlutterCommand {
await Cache.instance.updateAll();
String flutterRoot = path.absolute(ArtifactStore.flutterRoot);
String flutterRoot = path.absolute(Cache.flutterRoot);
String flutterPackagesDirectory = path.join(flutterRoot, 'packages');
String flutterPackagePath = path.join(flutterPackagesDirectory, 'flutter');
......
......@@ -9,8 +9,8 @@ import 'package:path/path.dart' as path;
import '../base/os.dart';
import '../base/process.dart';
import '../cache.dart';
import '../doctor.dart';
import '../artifacts.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
......@@ -113,7 +113,7 @@ class SetupCommand extends FlutterCommand {
// dartlang:
// sdkLocation: "..."
String flutterRoot = path.normalize(path.absolute(ArtifactStore.flutterRoot));
String flutterRoot = path.normalize(path.absolute(Cache.flutterRoot));
String sdkLocation = path.join(flutterRoot, 'bin/cache/dart-sdk');
File file = AtomValidator.getConfigFile();
......
......@@ -5,9 +5,9 @@
import 'dart:async';
import 'dart:io';
import '../artifacts.dart';
import '../base/process.dart';
import '../dart/pub.dart';
import '../cache.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
import '../version.dart';
......@@ -27,17 +27,17 @@ class UpgradeCommand extends FlutterCommand {
try {
runCheckedSync(<String>[
'git', 'rev-parse', '@{u}'
], workingDirectory: ArtifactStore.flutterRoot);
], workingDirectory: Cache.flutterRoot);
} catch (e) {
printError('Unable to upgrade Flutter: no upstream repository configured.');
return 1;
}
printStatus('Upgrading Flutter from ${ArtifactStore.flutterRoot}...');
printStatus('Upgrading Flutter from ${Cache.flutterRoot}...');
int code = await runCommandAndStreamOutput(
<String>['git', 'pull', '--ff-only'],
workingDirectory: ArtifactStore.flutterRoot,
workingDirectory: Cache.flutterRoot,
mapFunction: (String line) => matchesGitLine(line) ? null : line
);
......@@ -49,10 +49,10 @@ class UpgradeCommand extends FlutterCommand {
printStatus('Upgrading engine...');
code = await runCommandAndStreamOutput(<String>[
'bin/flutter', '--no-color', 'precache'
], workingDirectory: ArtifactStore.flutterRoot);
], workingDirectory: Cache.flutterRoot);
printStatus('');
printStatus(FlutterVersion.getVersion(ArtifactStore.flutterRoot).toString());
printStatus(FlutterVersion.getVersion(Cache.flutterRoot).toString());
if (FileSystemEntity.isFileSync('pubspec.yaml')) {
printStatus('');
......
......@@ -6,11 +6,11 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import '../artifacts.dart';
import '../cache.dart';
/// Locate the Dart SDK.
String get dartSdkPath {
return path.join(ArtifactStore.flutterRoot, 'bin', 'cache', 'dart-sdk');
return path.join(Cache.flutterRoot, 'bin', 'cache', 'dart-sdk');
}
/// Return the platform specific name for the given Dart SDK binary. So, `pub`
......
......@@ -12,9 +12,9 @@ import 'package:json_schema/json_schema.dart';
import 'package:path/path.dart' as path;
import 'package:yaml/yaml.dart';
import 'artifacts.dart';
import 'base/file_system.dart' show ensureDirectoryExists;
import 'base/process.dart';
import 'cache.dart';
import 'globals.dart';
import 'package_map.dart';
import 'toolchain.dart';
......@@ -93,7 +93,7 @@ class _Asset {
}
Map<String, dynamic> _readMaterialFontsManifest() {
String fontsPath = path.join(path.absolute(ArtifactStore.flutterRoot),
String fontsPath = path.join(path.absolute(Cache.flutterRoot),
'packages', 'flutter_tools', 'schema', 'material_fonts.yaml');
return loadYaml(new File(fontsPath).readAsStringSync());
......@@ -112,7 +112,7 @@ List<_Asset> _getMaterialAssets(String fontSet) {
for (Map<String, dynamic> font in family['fonts']) {
String assetKey = font['asset'];
result.add(new _Asset(
base: '${ArtifactStore.flutterRoot}/bin/cache/artifacts/material_fonts',
base: '${Cache.flutterRoot}/bin/cache/artifacts/material_fonts',
source: path.basename(assetKey),
relativePath: assetKey
));
......@@ -227,7 +227,7 @@ dynamic _loadManifest(String manifestPath) {
}
Future<int> _validateManifest(Object manifest) async {
String schemaPath = path.join(path.absolute(ArtifactStore.flutterRoot),
String schemaPath = path.join(path.absolute(Cache.flutterRoot),
'packages', 'flutter_tools', 'schema', 'flutter_yaml.json');
Schema schema = await Schema.createSchemaFromUrl('file://$schemaPath');
......
......@@ -9,9 +9,9 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import '../application_package.dart';
import '../artifacts.dart';
import '../base/context.dart';
import '../base/process.dart';
import '../cache.dart';
import '../globals.dart';
import '../services.dart';
import 'setup_xcodeproj.dart';
......@@ -184,7 +184,7 @@ bool _checkXcodeVersion() {
}
bool _validateEngineRevision(ApplicationPackage app) {
String skyRevision = ArtifactStore.engineRevision;
String skyRevision = Cache.engineRevision;
String iosRevision = _getIOSEngineRevision(app);
if (iosRevision != skyRevision) {
......
......@@ -7,9 +7,9 @@ import 'dart:io';
import 'package:path/path.dart' as path;
import '../artifacts.dart';
import '../base/process.dart';
import '../build_info.dart';
import '../cache.dart';
import '../globals.dart';
import '../runner/flutter_command_runner.dart';
......@@ -85,7 +85,7 @@ bool xcodeProjectRequiresUpdate() {
return true;
}
if (revisionFile.readAsStringSync() != ArtifactStore.engineRevision) {
if (revisionFile.readAsStringSync() != Cache.engineRevision) {
printTrace("The revision stamp and the Flutter engine revision differ. Project needs to be updated.");
return true;
}
......@@ -121,7 +121,7 @@ Future<int> setupXcodeProjectHarness(String flutterProjectPath) async {
// Step 4: Write the REVISION file
File revisionFile = new File(path.join(xcodeprojPath, 'REVISION'));
revisionFile.createSync();
revisionFile.writeAsStringSync(ArtifactStore.engineRevision);
revisionFile.writeAsStringSync(Cache.engineRevision);
// Step 5: Tell the user the location of the generated project.
printStatus('Xcode project created in $iosFilesPath/.');
......
......@@ -10,10 +10,10 @@ import 'package:args/command_runner.dart';
import 'package:path/path.dart' as path;
import '../android/android_sdk.dart';
import '../artifacts.dart';
import '../base/context.dart';
import '../base/logger.dart';
import '../base/process.dart';
import '../cache.dart';
import '../globals.dart';
import '../package_map.dart';
import '../toolchain.dart';
......@@ -128,9 +128,9 @@ class FlutterCommandRunner extends CommandRunner {
if (globalResults.wasParsed('color'))
logger.supportsColor = globalResults['color'];
// we must set ArtifactStore.flutterRoot early because other features use it
// we must set Cache.flutterRoot early because other features use it
// (e.g. enginePath's initialiser uses it)
ArtifactStore.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root']));
Cache.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root']));
_checkFlutterCopy();
......@@ -159,7 +159,7 @@ class FlutterCommandRunner extends CommandRunner {
if (globalResults['version']) {
flutterUsage.sendCommand('version');
printStatus(FlutterVersion.getVersion(ArtifactStore.flutterRoot).toString());
printStatus(FlutterVersion.getVersion(Cache.flutterRoot).toString());
return new Future<int>.value(0);
}
......@@ -185,7 +185,7 @@ class FlutterCommandRunner extends CommandRunner {
} on FileSystemException { } on FormatException { }
if (engineSourcePath == null)
engineSourcePath = _tryEnginePath(path.join(ArtifactStore.flutterRoot, '../engine/src'));
engineSourcePath = _tryEnginePath(path.join(Cache.flutterRoot, '../engine/src'));
if (engineSourcePath == null) {
printError('Unable to detect local Flutter engine build directory.\n'
......@@ -225,13 +225,13 @@ class FlutterCommandRunner extends CommandRunner {
}
static void initFlutterRoot() {
if (ArtifactStore.flutterRoot == null)
ArtifactStore.flutterRoot = _defaultFlutterRoot;
if (Cache.flutterRoot == null)
Cache.flutterRoot = _defaultFlutterRoot;
}
/// Get all pub packages in the Flutter repo.
List<Directory> getRepoPackages() {
return _gatherProjectPaths(path.absolute(ArtifactStore.flutterRoot))
return _gatherProjectPaths(path.absolute(Cache.flutterRoot))
.map((String dir) => new Directory(dir))
.toList();
}
......@@ -258,10 +258,10 @@ class FlutterCommandRunner extends CommandRunner {
// Check if the cwd is a flutter dir.
while (directory.isNotEmpty) {
if (_isDirectoryFlutterRepo(directory)) {
if (directory != ArtifactStore.flutterRoot) {
if (directory != Cache.flutterRoot) {
printError(
'Warning: the active Flutter is not the one from the current directory.\n'
' Active Flutter : ${ArtifactStore.flutterRoot}\n'
' Active Flutter : ${Cache.flutterRoot}\n'
' Current directory: $directory\n'
);
}
......
......@@ -7,7 +7,7 @@ import 'dart:io';
import 'package:mustache4dart/mustache4dart.dart' as mustache;
import 'package:path/path.dart' as path;
import 'artifacts.dart';
import 'cache.dart';
import 'globals.dart';
const String _kTemplateExtension = '.tmpl';
......@@ -122,7 +122,7 @@ class Template {
}
Directory _templateDirectoryInPackage(String name) {
String templatesDir = path.join(ArtifactStore.flutterRoot,
String templatesDir = path.join(Cache.flutterRoot,
'packages', 'flutter_tools', 'templates');
return new Directory(path.join(templatesDir, name));
}
......@@ -4,8 +4,8 @@
import 'dart:io';
import 'artifacts.dart';
import 'base/process.dart';
import 'cache.dart';
final Set<String> kKnownBranchNames = new Set<String>.from(<String>[
'master',
......@@ -48,7 +48,7 @@ class FlutterVersion {
String _frameworkAge;
String get frameworkAge => _frameworkAge;
String get engineRevision => ArtifactStore.engineRevision;
String get engineRevision => Cache.engineRevision;
String get engineRevisionShort => _shortGitRevision(engineRevision);
String _runGit(String command) => runSync(command.split(' '), workingDirectory: flutterRoot);
......@@ -62,12 +62,12 @@ class FlutterVersion {
}
static FlutterVersion getVersion([String flutterRoot]) {
return new FlutterVersion(flutterRoot != null ? flutterRoot : ArtifactStore.flutterRoot);
return new FlutterVersion(flutterRoot != null ? flutterRoot : Cache.flutterRoot);
}
/// Return a short string for the version (`alpha/a76bc8e22b`).
static String getVersionString({ bool whitelistBranchName: false }) {
final String cwd = ArtifactStore.flutterRoot;
final String cwd = Cache.flutterRoot;
String commit = _shortGitRevision(_runSync('git', <String>['rev-parse', 'HEAD'], cwd));
commit = commit.isEmpty ? 'unknown' : commit;
......
......@@ -5,7 +5,7 @@
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/commands/config.dart';
import 'package:flutter_tools/src/commands/doctor.dart';
......@@ -22,7 +22,7 @@ void main() {
bool wasEnabled;
setUp(() {
ArtifactStore.flutterRoot = '../..';
Cache.flutterRoot = '../..';
wasEnabled = flutterUsage.enabled;
temp = Directory.systemTemp.createTempSync('flutter_tools');
});
......
......@@ -6,7 +6,7 @@ import 'dart:async';
import 'dart:io';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:path/path.dart' as path;
......@@ -38,7 +38,7 @@ void main() {
// Verify that we can regenerate over an existing project.
testUsingContext('can re-gen over existing project', () async {
ArtifactStore.flutterRoot = '../..';
Cache.flutterRoot = '../..';
CreateCommand command = new CreateCommand();
CommandRunner runner = createTestCommandRunner(command);
......@@ -52,7 +52,7 @@ void main() {
// Verify that we fail with an error code when the file exists.
testUsingContext('fails when file exists', () async {
ArtifactStore.flutterRoot = '../..';
Cache.flutterRoot = '../..';
CreateCommand command = new CreateCommand();
CommandRunner runner = createTestCommandRunner(command);
File existingFile = new File("${temp.path.toString()}/bad");
......@@ -64,7 +64,7 @@ void main() {
}
Future<Null> _createAndAnalyzeProject(Directory dir, List<String> createArgs) async {
ArtifactStore.flutterRoot = '../..';
Cache.flutterRoot = '../..';
CreateCommand command = new CreateCommand();
CommandRunner runner = createTestCommandRunner(command);
List<String> args = <String>['create'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment