diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart index 9d0b1895d8..1ac743f825 100644 --- a/packages/flutter_tools/lib/src/artifacts.dart +++ b/packages/flutter_tools/lib/src/artifacts.dart @@ -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 _cacheDir(String engineRevision, String packageRoot) async { - String cacheDirPath = '${packageRoot}/sky_tools/cache/sky_engine/${engineRevision}/'; + Future _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 getEngineRevision(String packageRoot) { - return new File(packageRoot + '/sky_engine/REVISION').readAsString(); - } - - Future getPath(Artifact artifact, String packageRoot) async { - String engineRevision = await getEngineRevision(packageRoot); - Directory cacheDir = await _cacheDir(engineRevision, packageRoot); + Future 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._(); diff --git a/packages/flutter_tools/lib/src/build.dart b/packages/flutter_tools/lib/src/build.dart index 5b03493f82..0ee38cee89 100644 --- a/packages/flutter_tools/lib/src/build.dart +++ b/packages/flutter_tools/lib/src/build.dart @@ -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', diff --git a/packages/flutter_tools/lib/src/run_mojo.dart b/packages/flutter_tools/lib/src/run_mojo.dart index 5330ea701d..71b6d2539c 100644 --- a/packages/flutter_tools/lib/src/run_mojo.dart +++ b/packages/flutter_tools/lib/src/run_mojo.dart @@ -38,8 +38,8 @@ class RunMojoCommandHandler extends CommandHandler { return file.absolute.path; } - Future _runAndroid(ArgResults results, String appPath, String engineRevision) async { - String skyViewerUrl = artifactStore.googleStorageUrl('viewer', 'android-arm', engineRevision); + Future _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 _runLinux(ArgResults results, String appPath, String packageRoot, String engineRevision) async { - String viewerPath = await _makePathAbsolute(await artifactStore.getPath(Artifact.SkyViewerMojo, packageRoot)); + Future _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 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); } } }