Configure ArtifactStore for all commands and make 'package-root' universal

This makes the 'package-root' option universal for sky_tools and configures the
ArtifactStore with it statically at startup. The actual sky_engine revision
is computed on demand.
This commit is contained in:
James Robinson 2015-09-25 15:43:03 -07:00
parent be0b3e61be
commit 9996d4255e
5 changed files with 28 additions and 35 deletions

View file

@ -8,6 +8,7 @@ import 'package:args/args.dart';
import 'package:args/command_runner.dart';
import 'package:logging/logging.dart';
import 'package:sky_tools/src/application_package.dart';
import 'package:sky_tools/src/artifacts.dart';
import 'package:sky_tools/src/build.dart';
import 'package:sky_tools/src/cache.dart';
import 'package:sky_tools/src/init.dart';
@ -72,6 +73,9 @@ class FlutterCommandRunner extends CommandRunner {
'Path to your iOS Simulator Release out directory, if you are building Sky locally. '
'This path is relative to sky-src-path. Not normally required.',
defaultsTo: 'out/ios_sim_Release/');
argParser.addOption('package-root',
help: 'Path to your packages directory.',
defaultsTo: 'packages');
}
Future<int> runCommand(ArgResults topLevelResults) async {
@ -89,6 +93,7 @@ class FlutterCommandRunner extends CommandRunner {
}
void _setupPaths(ArgResults results) {
ArtifactStore.packageRoot = results['package-root'];
if (results['debug'] || results['release']) {
if (results['sky-src-path'] == null) {
// TODO(iansf): Figure out how to get the default src path

View file

@ -15,21 +15,21 @@ final Logger _logging = new Logger('sky_tools.artifacts');
enum Artifact { FlutterCompiler, SkyViewerMojo, }
class ArtifactStore {
String _engineRevision;
final String packageRoot;
static String packageRoot;
static String _engineRevision;
ArtifactStore(this.packageRoot) {
_engineRevision = new File(path.join(packageRoot, 'sky_engine', 'REVISION')).readAsStringSync();
static String get engineRevision {
if (_engineRevision == null)
_engineRevision = new File(path.join(packageRoot, 'sky_engine', 'REVISION')).readAsStringSync();
return _engineRevision;
}
String get engineRevision => _engineRevision;
// Keep in sync with https://github.com/flutter/engine/blob/master/sky/tools/big_red_button.py#L50
String googleStorageUrl(String category, String platform) {
static String googleStorageUrl(String category, String platform) {
return 'https://storage.googleapis.com/mojo/sky/${category}/${platform}/${engineRevision}/';
}
Future _downloadFile(String url, File file) async {
static Future _downloadFile(String url, File file) async {
_logging.fine('Downloading $url to ${file.path}');
HttpClient httpClient = new HttpClient();
HttpClientRequest request = await httpClient.getUrl(Uri.parse(url));
@ -42,7 +42,7 @@ class ArtifactStore {
_logging.fine('Wrote file');
}
Future<Directory> _cacheDir() async {
static Future<Directory> _cacheDir() async {
Directory cacheDir = new Directory(path.join(packageRoot, 'sky_tools', 'cache'));
if (!await cacheDir.exists()) {
await cacheDir.create(recursive: true);
@ -50,7 +50,7 @@ class ArtifactStore {
return cacheDir;
}
Future<Directory> _engineSpecificCacheDir() async {
static Future<Directory> _engineSpecificCacheDir() async {
Directory cacheDir = await _cacheDir();
// For now, all downloaded artifacts are release mode host binaries so use
// a path that mirrors a local release build.
@ -65,11 +65,11 @@ class ArtifactStore {
}
// Whether the artifact needs to be marked as executable on disk.
bool _needsToBeExecutable(Artifact artifact) {
static bool _needsToBeExecutable(Artifact artifact) {
return artifact == Artifact.FlutterCompiler;
}
Future<String> getPath(Artifact artifact) async {
static Future<String> getPath(Artifact artifact) async {
Directory cacheDir = await _engineSpecificCacheDir();
String category, name;
@ -98,13 +98,13 @@ class ArtifactStore {
return cachedFile.path;
}
Future clear() async {
static Future clear() async {
Directory cacheDir = await _cacheDir();
_logging.fine('Clearing cache directory ${cacheDir.path}');
await cacheDir.delete(recursive: true);
}
Future populate() async {
static Future populate() async {
for (Artifact artifact in Artifact.values) {
_logging.fine('Populating cache with $artifact');
await getPath(artifact);

View file

@ -105,8 +105,7 @@ Future _compileSnapshot({
String snapshotPath
}) async {
if (compilerPath == null) {
ArtifactStore artifacts = new ArtifactStore(packageRoot);
compilerPath = await artifacts.getPath(Artifact.FlutterCompiler);
compilerPath = await ArtifactStore.getPath(Artifact.FlutterCompiler);
}
ProcessResult result = await Process.run(compilerPath, [
mainPath,
@ -135,7 +134,6 @@ class BuildCommand extends Command {
argParser.addOption('main', defaultsTo: 'lib/main.dart');
argParser.addOption('manifest');
argParser.addOption('output-file', abbr: 'o', defaultsTo: 'app.flx');
argParser.addOption('package-root', defaultsTo: 'packages');
argParser.addOption('snapshot', defaultsTo: 'snapshot_blob.bin');
}

View file

@ -25,14 +25,10 @@ class CacheCommand extends Command {
class _ClearCommand extends Command {
final name = 'clear';
final description = 'Clears all artifacts from the cache.';
_ClearCommand() {
argParser.addOption('package-root', defaultsTo: 'packages');
}
@override
Future<int> run() async {
ArtifactStore artifacts = new ArtifactStore(argResults['package-root']);
await artifacts.clear();
await ArtifactStore.clear();
return 0;
}
}
@ -40,14 +36,10 @@ class _ClearCommand extends Command {
class _PopulateCommand extends Command {
final name = 'populate';
final description = 'Populates the cache with all known artifacts.';
_PopulateCommand() {
argParser.addOption('package-root', defaultsTo: 'packages');
}
@override
Future<int> run() async {
ArtifactStore artifacts = new ArtifactStore(argResults['package-root']);
await artifacts.populate();
await ArtifactStore.populate();
return 0;
}
}

View file

@ -38,8 +38,8 @@ class RunMojoCommand extends Command {
return file.absolute.path;
}
Future<int> _runAndroid(ArgResults results, String appPath, ArtifactStore artifacts) async {
String skyViewerUrl = artifacts.googleStorageUrl('viewer', 'android-arm');
Future<int> _runAndroid(ArgResults results, String appPath) async {
String skyViewerUrl = ArtifactStore.googleStorageUrl('viewer', 'android-arm');
String command = await _makePathAbsolute(path.join(results['mojo-path'], 'mojo', 'devtools', 'common', 'mojo_run'));
String appName = path.basename(appPath);
String appDir = path.dirname(appPath);
@ -62,8 +62,8 @@ class RunMojoCommand extends Command {
return runCommandAndStreamOutput(command, args);
}
Future<int> _runLinux(ArgResults results, String appPath, ArtifactStore artifacts) async {
String viewerPath = await _makePathAbsolute(await artifacts.getPath(Artifact.SkyViewerMojo));
Future<int> _runLinux(ArgResults results, String appPath) async {
String viewerPath = await _makePathAbsolute(await ArtifactStore.getPath(Artifact.SkyViewerMojo));
String mojoBuildType = argResults['mojo-debug'] ? 'Debug' : 'Release';
String mojoShellPath = await _makePathAbsolute(path.join(results['mojo-path'], 'out', mojoBuildType, 'mojo_shell'));
List<String> args = [
@ -84,13 +84,11 @@ class RunMojoCommand extends Command {
_logging.severe('Cannot specify both --mojo-debug and --mojo-release');
return 1;
}
String packageRoot = argResults['package-root'];
ArtifactStore artifacts = new ArtifactStore(packageRoot);
String appPath = await _makePathAbsolute(argResults['app']);
if (argResults['android']) {
return _runAndroid(argResults, appPath, artifacts);
return _runAndroid(argResults, appPath);
} else {
return _runLinux(argResults, appPath, artifacts);
return _runLinux(argResults, appPath);
}
}
}