Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library pub.barback.asset_environment; | 5 library pub.barback.asset_environment; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 Future<BarbackServer> servePackageBinDirectory(String package) { | 230 Future<BarbackServer> servePackageBinDirectory(String package) { |
| 231 return _provideDirectorySources(graph.packages[package], "bin").then( | 231 return _provideDirectorySources(graph.packages[package], "bin").then( |
| 232 (_) => BarbackServer.bind(this, _hostname, 0, package: package, | 232 (_) => BarbackServer.bind(this, _hostname, 0, package: package, |
| 233 rootDirectory: "bin")); | 233 rootDirectory: "bin")); |
| 234 } | 234 } |
| 235 | 235 |
| 236 /// Precompiles all of [packageName]'s executables to snapshots in | 236 /// Precompiles all of [packageName]'s executables to snapshots in |
| 237 /// [directory]. | 237 /// [directory]. |
| 238 /// | 238 /// |
| 239 /// If [executableIds] is passed, only those executables are precompiled. | 239 /// If [executableIds] is passed, only those executables are precompiled. |
| 240 Future precompileExecutables(String packageName, String directory, | 240 /// |
| 241 {Iterable<AssetId> executableIds}) { | 241 /// Returns a map from executable ID to path for the snapshots that were |
|
nweiz
2014/09/23 00:15:44
This says "executable ID" but actually returns the
Bob Nystrom
2014/09/23 18:23:27
Done.
| |
| 242 /// successfully precompiled. | |
| 243 Future<Map<String, String>> precompileExecutables(String packageName, | |
| 244 String directory, {Iterable<AssetId> executableIds}) async { | |
| 242 if (executableIds == null) { | 245 if (executableIds == null) { |
| 243 executableIds = graph.packages[packageName].executableIds; | 246 executableIds = graph.packages[packageName].executableIds; |
| 244 } | 247 } |
| 245 log.fine("executables for $packageName: $executableIds"); | 248 |
| 246 if (executableIds.isEmpty) return null; | 249 log.fine("Executables for $packageName: $executableIds"); |
| 250 if (executableIds.isEmpty) return []; | |
| 247 | 251 |
| 248 var package = graph.packages[packageName]; | 252 var package = graph.packages[packageName]; |
| 249 return servePackageBinDirectory(packageName).then((server) { | 253 var server = await servePackageBinDirectory(packageName); |
| 250 return waitAndPrintErrors(executableIds.map((id) { | 254 try { |
| 255 var precompiled = {}; | |
| 256 await waitAndPrintErrors(executableIds.map((id) async { | |
| 251 var basename = path.url.basename(id.path); | 257 var basename = path.url.basename(id.path); |
| 252 var snapshotPath = path.join(directory, "$basename.snapshot"); | 258 var snapshotPath = path.join(directory, "$basename.snapshot"); |
| 253 return runProcess(Platform.executable, [ | 259 var result = await runProcess(Platform.executable, [ |
| 254 '--snapshot=$snapshotPath', | 260 '--snapshot=$snapshotPath', |
| 255 server.url.resolve(basename).toString() | 261 server.url.resolve(basename).toString() |
| 256 ]).then((result) { | 262 ]); |
| 257 if (result.success) { | 263 if (result.success) { |
| 258 log.message("Precompiled ${_formatExecutable(id)}."); | 264 log.message("Precompiled ${_formatExecutable(id)}."); |
| 259 } else { | 265 precompiled[path.withoutExtension(basename)] = snapshotPath; |
| 260 throw new ApplicationException( | 266 } else { |
| 261 log.yellow("Failed to precompile " | 267 throw new ApplicationException( |
| 262 "${_formatExecutable(id)}:\n") + | 268 log.yellow("Failed to precompile ${_formatExecutable(id)}:\n") + |
| 263 result.stderr.join('\n')); | 269 result.stderr.join('\n')); |
| 264 } | 270 } |
| 265 }); | 271 })); |
| 266 })).whenComplete(() { | 272 |
| 267 // Don't return this future, since we have no need to wait for the | 273 return precompiled; |
| 268 // server to fully shut down. | 274 } finally { |
| 269 server.close(); | 275 // Don't await this future, since we have no need to wait for the server |
| 270 }); | 276 // to fully shut down. |
| 271 }); | 277 server.close(); |
| 278 } | |
| 272 } | 279 } |
| 273 | 280 |
| 274 /// Returns the executable name for [id]. | 281 /// Returns the executable name for [id]. |
| 275 /// | 282 /// |
| 276 /// [id] is assumed to be an executable in a bin directory. The return value | 283 /// [id] is assumed to be an executable in a bin directory. The return value |
| 277 /// is intended for log output and may contain formatting. | 284 /// is intended for log output and may contain formatting. |
| 278 String _formatExecutable(AssetId id) => | 285 String _formatExecutable(AssetId id) => |
| 279 log.bold("${id.package}:${path.basenameWithoutExtension(id.path)}"); | 286 log.bold("${id.package}:${path.basenameWithoutExtension(id.path)}"); |
| 280 | 287 |
| 281 /// Stops the server bound to [rootDirectory]. | 288 /// Stops the server bound to [rootDirectory]. |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 String toString() => "polling"; | 796 String toString() => "polling"; |
| 790 } | 797 } |
| 791 | 798 |
| 792 class _NoneWatcherType implements WatcherType { | 799 class _NoneWatcherType implements WatcherType { |
| 793 const _NoneWatcherType(); | 800 const _NoneWatcherType(); |
| 794 | 801 |
| 795 DirectoryWatcher create(String directory) => null; | 802 DirectoryWatcher create(String directory) => null; |
| 796 | 803 |
| 797 String toString() => "none"; | 804 String toString() => "none"; |
| 798 } | 805 } |
| OLD | NEW |