Commit 9996d425 authored by James Robinson's avatar James Robinson

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.
parent be0b3e61
...@@ -8,6 +8,7 @@ import 'package:args/args.dart'; ...@@ -8,6 +8,7 @@ import 'package:args/args.dart';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:sky_tools/src/application_package.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/build.dart';
import 'package:sky_tools/src/cache.dart'; import 'package:sky_tools/src/cache.dart';
import 'package:sky_tools/src/init.dart'; import 'package:sky_tools/src/init.dart';
...@@ -72,6 +73,9 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -72,6 +73,9 @@ class FlutterCommandRunner extends CommandRunner {
'Path to your iOS Simulator Release out directory, if you are building Sky locally. ' '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.', 'This path is relative to sky-src-path. Not normally required.',
defaultsTo: 'out/ios_sim_Release/'); defaultsTo: 'out/ios_sim_Release/');
argParser.addOption('package-root',
help: 'Path to your packages directory.',
defaultsTo: 'packages');
} }
Future<int> runCommand(ArgResults topLevelResults) async { Future<int> runCommand(ArgResults topLevelResults) async {
...@@ -89,6 +93,7 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -89,6 +93,7 @@ class FlutterCommandRunner extends CommandRunner {
} }
void _setupPaths(ArgResults results) { void _setupPaths(ArgResults results) {
ArtifactStore.packageRoot = results['package-root'];
if (results['debug'] || results['release']) { if (results['debug'] || results['release']) {
if (results['sky-src-path'] == null) { if (results['sky-src-path'] == null) {
// TODO(iansf): Figure out how to get the default src path // TODO(iansf): Figure out how to get the default src path
......
...@@ -15,21 +15,21 @@ final Logger _logging = new Logger('sky_tools.artifacts'); ...@@ -15,21 +15,21 @@ final Logger _logging = new Logger('sky_tools.artifacts');
enum Artifact { FlutterCompiler, SkyViewerMojo, } enum Artifact { FlutterCompiler, SkyViewerMojo, }
class ArtifactStore { class ArtifactStore {
String _engineRevision; static String packageRoot;
final String packageRoot; static String _engineRevision;
ArtifactStore(this.packageRoot) { static String get engineRevision {
if (_engineRevision == null)
_engineRevision = new File(path.join(packageRoot, 'sky_engine', 'REVISION')).readAsStringSync(); _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 // 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}/'; 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}'); _logging.fine('Downloading $url to ${file.path}');
HttpClient httpClient = new HttpClient(); HttpClient httpClient = new HttpClient();
HttpClientRequest request = await httpClient.getUrl(Uri.parse(url)); HttpClientRequest request = await httpClient.getUrl(Uri.parse(url));
...@@ -42,7 +42,7 @@ class ArtifactStore { ...@@ -42,7 +42,7 @@ class ArtifactStore {
_logging.fine('Wrote file'); _logging.fine('Wrote file');
} }
Future<Directory> _cacheDir() async { static Future<Directory> _cacheDir() async {
Directory cacheDir = new Directory(path.join(packageRoot, 'sky_tools', 'cache')); Directory cacheDir = new Directory(path.join(packageRoot, 'sky_tools', 'cache'));
if (!await cacheDir.exists()) { if (!await cacheDir.exists()) {
await cacheDir.create(recursive: true); await cacheDir.create(recursive: true);
...@@ -50,7 +50,7 @@ class ArtifactStore { ...@@ -50,7 +50,7 @@ class ArtifactStore {
return cacheDir; return cacheDir;
} }
Future<Directory> _engineSpecificCacheDir() async { static Future<Directory> _engineSpecificCacheDir() async {
Directory cacheDir = await _cacheDir(); Directory cacheDir = await _cacheDir();
// For now, all downloaded artifacts are release mode host binaries so use // For now, all downloaded artifacts are release mode host binaries so use
// a path that mirrors a local release build. // a path that mirrors a local release build.
...@@ -65,11 +65,11 @@ class ArtifactStore { ...@@ -65,11 +65,11 @@ class ArtifactStore {
} }
// Whether the artifact needs to be marked as executable on disk. // Whether the artifact needs to be marked as executable on disk.
bool _needsToBeExecutable(Artifact artifact) { static bool _needsToBeExecutable(Artifact artifact) {
return artifact == Artifact.FlutterCompiler; return artifact == Artifact.FlutterCompiler;
} }
Future<String> getPath(Artifact artifact) async { static Future<String> getPath(Artifact artifact) async {
Directory cacheDir = await _engineSpecificCacheDir(); Directory cacheDir = await _engineSpecificCacheDir();
String category, name; String category, name;
...@@ -98,13 +98,13 @@ class ArtifactStore { ...@@ -98,13 +98,13 @@ class ArtifactStore {
return cachedFile.path; return cachedFile.path;
} }
Future clear() async { static Future clear() async {
Directory cacheDir = await _cacheDir(); Directory cacheDir = await _cacheDir();
_logging.fine('Clearing cache directory ${cacheDir.path}'); _logging.fine('Clearing cache directory ${cacheDir.path}');
await cacheDir.delete(recursive: true); await cacheDir.delete(recursive: true);
} }
Future populate() async { static Future populate() async {
for (Artifact artifact in Artifact.values) { for (Artifact artifact in Artifact.values) {
_logging.fine('Populating cache with $artifact'); _logging.fine('Populating cache with $artifact');
await getPath(artifact); await getPath(artifact);
......
...@@ -105,8 +105,7 @@ Future _compileSnapshot({ ...@@ -105,8 +105,7 @@ Future _compileSnapshot({
String snapshotPath String snapshotPath
}) async { }) async {
if (compilerPath == null) { if (compilerPath == null) {
ArtifactStore artifacts = new ArtifactStore(packageRoot); compilerPath = await ArtifactStore.getPath(Artifact.FlutterCompiler);
compilerPath = await artifacts.getPath(Artifact.FlutterCompiler);
} }
ProcessResult result = await Process.run(compilerPath, [ ProcessResult result = await Process.run(compilerPath, [
mainPath, mainPath,
...@@ -135,7 +134,6 @@ class BuildCommand extends Command { ...@@ -135,7 +134,6 @@ class BuildCommand extends Command {
argParser.addOption('main', defaultsTo: 'lib/main.dart'); argParser.addOption('main', defaultsTo: 'lib/main.dart');
argParser.addOption('manifest'); argParser.addOption('manifest');
argParser.addOption('output-file', abbr: 'o', defaultsTo: 'app.flx'); argParser.addOption('output-file', abbr: 'o', defaultsTo: 'app.flx');
argParser.addOption('package-root', defaultsTo: 'packages');
argParser.addOption('snapshot', defaultsTo: 'snapshot_blob.bin'); argParser.addOption('snapshot', defaultsTo: 'snapshot_blob.bin');
} }
......
...@@ -25,14 +25,10 @@ class CacheCommand extends Command { ...@@ -25,14 +25,10 @@ class CacheCommand extends Command {
class _ClearCommand extends Command { class _ClearCommand extends Command {
final name = 'clear'; final name = 'clear';
final description = 'Clears all artifacts from the cache.'; final description = 'Clears all artifacts from the cache.';
_ClearCommand() {
argParser.addOption('package-root', defaultsTo: 'packages');
}
@override @override
Future<int> run() async { Future<int> run() async {
ArtifactStore artifacts = new ArtifactStore(argResults['package-root']); await ArtifactStore.clear();
await artifacts.clear();
return 0; return 0;
} }
} }
...@@ -40,14 +36,10 @@ class _ClearCommand extends Command { ...@@ -40,14 +36,10 @@ class _ClearCommand extends Command {
class _PopulateCommand extends Command { class _PopulateCommand extends Command {
final name = 'populate'; final name = 'populate';
final description = 'Populates the cache with all known artifacts.'; final description = 'Populates the cache with all known artifacts.';
_PopulateCommand() {
argParser.addOption('package-root', defaultsTo: 'packages');
}
@override @override
Future<int> run() async { Future<int> run() async {
ArtifactStore artifacts = new ArtifactStore(argResults['package-root']); await ArtifactStore.populate();
await artifacts.populate();
return 0; return 0;
} }
} }
...@@ -38,8 +38,8 @@ class RunMojoCommand extends Command { ...@@ -38,8 +38,8 @@ class RunMojoCommand extends Command {
return file.absolute.path; return file.absolute.path;
} }
Future<int> _runAndroid(ArgResults results, String appPath, ArtifactStore artifacts) async { Future<int> _runAndroid(ArgResults results, String appPath) async {
String skyViewerUrl = artifacts.googleStorageUrl('viewer', 'android-arm'); String skyViewerUrl = ArtifactStore.googleStorageUrl('viewer', 'android-arm');
String command = await _makePathAbsolute(path.join(results['mojo-path'], 'mojo', 'devtools', 'common', 'mojo_run')); String command = await _makePathAbsolute(path.join(results['mojo-path'], 'mojo', 'devtools', 'common', 'mojo_run'));
String appName = path.basename(appPath); String appName = path.basename(appPath);
String appDir = path.dirname(appPath); String appDir = path.dirname(appPath);
...@@ -62,8 +62,8 @@ class RunMojoCommand extends Command { ...@@ -62,8 +62,8 @@ class RunMojoCommand extends Command {
return runCommandAndStreamOutput(command, args); return runCommandAndStreamOutput(command, args);
} }
Future<int> _runLinux(ArgResults results, String appPath, ArtifactStore artifacts) async { Future<int> _runLinux(ArgResults results, String appPath) async {
String viewerPath = await _makePathAbsolute(await artifacts.getPath(Artifact.SkyViewerMojo)); String viewerPath = await _makePathAbsolute(await ArtifactStore.getPath(Artifact.SkyViewerMojo));
String mojoBuildType = argResults['mojo-debug'] ? 'Debug' : 'Release'; String mojoBuildType = argResults['mojo-debug'] ? 'Debug' : 'Release';
String mojoShellPath = await _makePathAbsolute(path.join(results['mojo-path'], 'out', mojoBuildType, 'mojo_shell')); String mojoShellPath = await _makePathAbsolute(path.join(results['mojo-path'], 'out', mojoBuildType, 'mojo_shell'));
List<String> args = [ List<String> args = [
...@@ -84,13 +84,11 @@ class RunMojoCommand extends Command { ...@@ -84,13 +84,11 @@ class RunMojoCommand extends Command {
_logging.severe('Cannot specify both --mojo-debug and --mojo-release'); _logging.severe('Cannot specify both --mojo-debug and --mojo-release');
return 1; return 1;
} }
String packageRoot = argResults['package-root'];
ArtifactStore artifacts = new ArtifactStore(packageRoot);
String appPath = await _makePathAbsolute(argResults['app']); String appPath = await _makePathAbsolute(argResults['app']);
if (argResults['android']) { if (argResults['android']) {
return _runAndroid(argResults, appPath, artifacts); return _runAndroid(argResults, appPath);
} else { } else {
return _runLinux(argResults, appPath, artifacts); return _runLinux(argResults, appPath);
} }
} }
} }
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