forked from firka/flutter
Instantiate ArtifactStore explicit with packageRoot
This teaches commands that need binary artifacts to explicitly instantiate an instance of the ArtifactStore with the appropriate packageRoot string. The ArtifactStore can then remember the package root and compute the engine revision when created and remember those for subsequence calls.
This commit is contained in:
@@ -8,16 +8,24 @@ import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
final Logger _logging = new Logger('sky_tools.device');
|
||||
final Logger _logging = new Logger('sky_tools.artifacts');
|
||||
|
||||
enum Artifact { FlutterCompiler, SkyViewerMojo, }
|
||||
|
||||
class _ArtifactStore {
|
||||
_ArtifactStore._();
|
||||
class ArtifactStore {
|
||||
String _engineRevision;
|
||||
final String packageRoot;
|
||||
|
||||
ArtifactStore(this.packageRoot) {
|
||||
_engineRevision = new File(path.join(packageRoot, 'sky_engine', 'REVISION')).readAsStringSync();
|
||||
}
|
||||
|
||||
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, String engineRevision) {
|
||||
String googleStorageUrl(String category, String platform) {
|
||||
return 'https://storage.googleapis.com/mojo/sky/${category}/${platform}/${engineRevision}/';
|
||||
}
|
||||
|
||||
@@ -34,8 +42,8 @@ class _ArtifactStore {
|
||||
_logging.fine('Wrote file');
|
||||
}
|
||||
|
||||
Future<Directory> _cacheDir(String engineRevision, String packageRoot) async {
|
||||
String cacheDirPath = '${packageRoot}/sky_tools/cache/sky_engine/${engineRevision}/';
|
||||
Future<Directory> _cacheDir() async {
|
||||
String cacheDirPath = path.join(packageRoot, 'sky_tools', 'cache', 'sky_engine', engineRevision);
|
||||
Directory cacheDir = new Directory(cacheDirPath);
|
||||
if (!await cacheDir.exists()) {
|
||||
await cacheDir.create(recursive: true);
|
||||
@@ -48,14 +56,8 @@ class _ArtifactStore {
|
||||
return artifact == Artifact.FlutterCompiler;
|
||||
}
|
||||
|
||||
|
||||
Future<String> getEngineRevision(String packageRoot) {
|
||||
return new File(packageRoot + '/sky_engine/REVISION').readAsString();
|
||||
}
|
||||
|
||||
Future<String> getPath(Artifact artifact, String packageRoot) async {
|
||||
String engineRevision = await getEngineRevision(packageRoot);
|
||||
Directory cacheDir = await _cacheDir(engineRevision, packageRoot);
|
||||
Future<String> getPath(Artifact artifact) async {
|
||||
Directory cacheDir = await _cacheDir();
|
||||
|
||||
String category, name;
|
||||
|
||||
@@ -70,10 +72,10 @@ class _ArtifactStore {
|
||||
return '';
|
||||
}
|
||||
|
||||
File cachedFile = new File(cacheDir.path + name);
|
||||
File cachedFile = new File(path.join(cacheDir.path, name));
|
||||
if (!await cachedFile.exists()) {
|
||||
_logging.info('Downloading ${name} from the cloud, one moment please...');
|
||||
String url = googleStorageUrl(category, 'linux-x64', engineRevision) + name;
|
||||
String url = googleStorageUrl(category, 'linux-x64') + name;
|
||||
await _downloadFile(url, cachedFile);
|
||||
if (_needsToBeExecutable(artifact)) {
|
||||
ProcessResult result = await Process.run('chmod', ['u+x', cachedFile.path]);
|
||||
@@ -83,5 +85,3 @@ class _ArtifactStore {
|
||||
return cachedFile.path;
|
||||
}
|
||||
}
|
||||
|
||||
final _ArtifactStore artifactStore = new _ArtifactStore._();
|
||||
|
||||
@@ -105,8 +105,10 @@ Future _compileSnapshot({
|
||||
String packageRoot,
|
||||
String snapshotPath
|
||||
}) async {
|
||||
if (compilerPath == null)
|
||||
compilerPath = await artifactStore.getPath(Artifact.FlutterCompiler, packageRoot);
|
||||
if (compilerPath == null) {
|
||||
ArtifactStore artifacts = new ArtifactStore(packageRoot);
|
||||
compilerPath = await artifacts.getPath(Artifact.FlutterCompiler);
|
||||
}
|
||||
ProcessResult result = await Process.run(compilerPath, [
|
||||
mainPath,
|
||||
'--package-root=$packageRoot',
|
||||
|
||||
@@ -38,8 +38,8 @@ class RunMojoCommandHandler extends CommandHandler {
|
||||
return file.absolute.path;
|
||||
}
|
||||
|
||||
Future<int> _runAndroid(ArgResults results, String appPath, String engineRevision) async {
|
||||
String skyViewerUrl = artifactStore.googleStorageUrl('viewer', 'android-arm', engineRevision);
|
||||
Future<int> _runAndroid(ArgResults results, String appPath, ArtifactStore artifacts) async {
|
||||
String skyViewerUrl = artifacts.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);
|
||||
@@ -58,8 +58,8 @@ class RunMojoCommandHandler extends CommandHandler {
|
||||
return runCommandAndStreamOutput(command, args);
|
||||
}
|
||||
|
||||
Future<int> _runLinux(ArgResults results, String appPath, String packageRoot, String engineRevision) async {
|
||||
String viewerPath = await _makePathAbsolute(await artifactStore.getPath(Artifact.SkyViewerMojo, packageRoot));
|
||||
Future<int> _runLinux(ArgResults results, String appPath, ArtifactStore artifacts) async {
|
||||
String viewerPath = await _makePathAbsolute(await artifacts.getPath(Artifact.SkyViewerMojo));
|
||||
String mojoShellPath = await _makePathAbsolute(path.join(results['mojo-path'], 'out', 'Release', 'mojo_shell'));
|
||||
List<String> mojoRunArgs = [
|
||||
'mojo:window_manager file://${appPath}',
|
||||
@@ -79,12 +79,12 @@ class RunMojoCommandHandler extends CommandHandler {
|
||||
return 1;
|
||||
}
|
||||
String packageRoot = results['package-root'];
|
||||
String engineRevision = await artifactStore.getEngineRevision(packageRoot);
|
||||
ArtifactStore artifacts = new ArtifactStore(packageRoot);
|
||||
String appPath = await _makePathAbsolute(results['app']);
|
||||
if (results['android']) {
|
||||
return _runAndroid(results, appPath, engineRevision);
|
||||
return _runAndroid(results, appPath, artifacts);
|
||||
} else {
|
||||
return _runLinux(results, appPath, packageRoot, engineRevision);
|
||||
return _runLinux(results, appPath, artifacts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user