Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: sdk/lib/_internal/pub/lib/src/barback/asset_environment.dart

Issue 475093003: Precompile immutable globally-installed pub executables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/command/global_run.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/barback/asset_environment.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/asset_environment.dart b/sdk/lib/_internal/pub/lib/src/barback/asset_environment.dart
index 54d30f15a91d56931124242b0967710faff660b9..1eab02d6ad9e3fa0a60794586d796b17ff3e1880 100644
--- a/sdk/lib/_internal/pub/lib/src/barback/asset_environment.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback/asset_environment.dart
@@ -12,6 +12,7 @@ import 'package:path/path.dart' as path;
import 'package:watcher/watcher.dart';
import '../entrypoint.dart';
+import '../exceptions.dart';
import '../io.dart';
import '../log.dart' as log;
import '../package.dart';
@@ -232,6 +233,54 @@ class AssetEnvironment {
rootDirectory: "bin"));
}
+ /// Precompiles all of [packageName]'s executables to snapshots in
+ /// [directory].
+ ///
+ /// If [executableIds] is passed, only those executables are precompiled.
+ Future precompileExecutables(String packageName, String directory,
+ {Iterable<AssetId> executableIds}) {
+ if (executableIds == null) {
+ executableIds = graph.packages[packageName].executableIds;
+ }
+ log.fine("executables for $packageName: $executableIds");
+ if (executableIds.isEmpty) return null;
+
+ var package = graph.packages[packageName];
+ return servePackageBinDirectory(packageName).then((server) {
+ return waitAndPrintErrors(executableIds.map((id) {
+ var basename = path.url.basename(id.path);
+ var snapshotPath = path.join(directory, "$basename.snapshot");
+ return runProcess(Platform.executable, [
+ '--snapshot=$snapshotPath',
+ server.url.resolve(basename).toString()
+ ]).then((result) {
+ if (result.success) {
+ log.message("Precompiled ${_formatExecutable(id)}.");
+ } else {
+ // TODO(nweiz): Stop manually deleting this when issue 20504 is
+ // fixed.
+ deleteEntry(snapshotPath);
+ throw new ApplicationException(
+ log.yellow("Failed to precompile "
+ "${_formatExecutable(id)}:\n") +
+ result.stderr.join('\n'));
+ }
+ });
+ })).whenComplete(() {
+ // Don't return this future, since we have no need to wait for the
+ // server to fully shut down.
+ server.close();
+ });
+ });
+ }
+
+ /// Returns the executable name for [id].
+ ///
+ /// [id] is assumed to be an executable in a bin directory. The return value
+ /// is intended for log output and may contain formatting.
+ String _formatExecutable(AssetId id) =>
+ log.bold("${id.package}:${path.basenameWithoutExtension(id.path)}");
+
/// Stops the server bound to [rootDirectory].
///
/// Also removes any source files within that directory from barback. Returns
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/lib/src/command/global_run.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698