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

Unified Diff: sdk/lib/_internal/pub_generated/lib/src/command/build.dart

Issue 887223007: Revert "Use native async/await support in pub." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
Index: sdk/lib/_internal/pub_generated/lib/src/command/build.dart
diff --git a/sdk/lib/_internal/pub/lib/src/command/build.dart b/sdk/lib/_internal/pub_generated/lib/src/command/build.dart
similarity index 58%
copy from sdk/lib/_internal/pub/lib/src/command/build.dart
copy to sdk/lib/_internal/pub_generated/lib/src/command/build.dart
index 4b76909f9dae02de7ac68cd3b68556611a445909..80060c86f9d68ce43b5ac3cd50fa68bcc9246b00 100644
--- a/sdk/lib/_internal/pub/lib/src/command/build.dart
+++ b/sdk/lib/_internal/pub_generated/lib/src/command/build.dart
@@ -35,111 +35,111 @@ class BuildCommand extends BarbackCommand {
int builtFiles = 0;
BuildCommand() {
- argParser.addOption("format",
+ argParser.addOption(
+ "format",
help: "How output should be displayed.",
- allowed: ["text", "json"], defaultsTo: "text");
+ allowed: ["text", "json"],
+ defaultsTo: "text");
- argParser.addOption("output", abbr: "o",
+ argParser.addOption(
+ "output",
+ abbr: "o",
help: "Directory to write build outputs to.",
defaultsTo: "build");
}
- Future onRunTransformerCommand() async {
- cleanDir(outputDirectory);
-
- var errorsJson = [];
- var logJson = [];
-
- // Since this server will only be hit by the transformer loader and isn't
- // user-facing, just use an IPv4 address to avoid a weird bug on the
- // OS X buildbots.
- return AssetEnvironment.create(entrypoint, mode, useDart2JS: true)
- .then((environment) {
- // Show in-progress errors, but not results. Those get handled
- // implicitly by getAllAssets().
- environment.barback.errors.listen((error) {
- log.error(log.red("Build error:\n$error"));
-
- if (log.json.enabled) {
- // Wrap the error in a map in case we end up decorating it with
- // more properties later.
- errorsJson.add({
- "error": error.toString()
+ Future onRunTransformerCommand() {
+ final completer0 = new Completer();
+ scheduleMicrotask(() {
+ try {
+ cleanDir(outputDirectory);
+ var errorsJson = [];
+ var logJson = [];
+ completer0.complete(
+ AssetEnvironment.create(
+ entrypoint,
+ mode,
+ useDart2JS: true).then(((environment) {
+ environment.barback.errors.listen((error) {
+ log.error(log.red("Build error:\n$error"));
+ if (log.json.enabled) {
+ errorsJson.add({
+ "error": error.toString()
+ });
+ }
});
- }
- });
-
- // If we're using JSON output, the regular server logging is disabled.
- // Instead, we collect it here to include in the final JSON result.
- if (log.json.enabled) {
- environment.barback.log.listen(
- (entry) => logJson.add(_logEntryToJson(entry)));
- }
-
- return log.progress("Building ${entrypoint.root.name}", () {
- // Register all of the build directories.
- // TODO(rnystrom): We don't actually need to bind servers for these, we
- // just need to add them to barback's sources. Add support to
- // BuildEnvironment for going the latter without the former.
- return Future.wait(sourceDirectories.map(
- (dir) => environment.serveDirectory(dir))).then((_) {
-
- return environment.barback.getAllAssets();
- });
- }).then((assets) {
- // Find all of the JS entrypoints we built.
- var dart2JSEntrypoints = assets
- .where((asset) => asset.id.path.endsWith(".dart.js"))
- .map((asset) => asset.id);
-
- return Future.wait(assets.map(_writeAsset)).then((_) {
- builtFiles += _copyBrowserJsFiles(dart2JSEntrypoints);
- log.message('Built $builtFiles ${pluralize('file', builtFiles)} '
- 'to "$outputDirectory".');
-
+ if (log.json.enabled) {
+ environment.barback.log.listen(
+ (entry) => logJson.add(_logEntryToJson(entry)));
+ }
+ return log.progress("Building ${entrypoint.root.name}", () {
+ return Future.wait(
+ sourceDirectories.map((dir) => environment.serveDirectory(dir))).then((_) {
+ return environment.barback.getAllAssets();
+ });
+ }).then((assets) {
+ var dart2JSEntrypoints = assets.where(
+ (asset) => asset.id.path.endsWith(".dart.js")).map((asset) => asset.id);
+ return Future.wait(assets.map(_writeAsset)).then((_) {
+ builtFiles += _copyBrowserJsFiles(dart2JSEntrypoints);
+ log.message(
+ 'Built $builtFiles ${pluralize('file', builtFiles)} ' 'to "$outputDirectory".');
+ log.json.message({
+ "buildResult": "success",
+ "outputDirectory": outputDirectory,
+ "numFiles": builtFiles,
+ "log": logJson
+ });
+ });
+ });
+ })).catchError(((error) {
+ if (error is! BarbackException) throw error;
+ log.error(log.red("Build failed."));
log.json.message({
- "buildResult": "success",
- "outputDirectory": outputDirectory,
- "numFiles": builtFiles,
+ "buildResult": "failure",
+ "errors": errorsJson,
"log": logJson
});
- });
- });
- }).catchError((error) {
- // If [getAllAssets()] throws a BarbackException, the error has already
- // been reported.
- if (error is! BarbackException) throw error;
-
- log.error(log.red("Build failed."));
- log.json.message({
- "buildResult": "failure",
- "errors": errorsJson,
- "log": logJson
- });
-
- return flushThenExit(exit_codes.DATA);
+ return flushThenExit(exit_codes.DATA);
+ })));
+ } catch (e, s) {
+ completer0.completeError(e, s);
+ }
});
+ return completer0.future;
}
/// Writes [asset] to the appropriate build directory.
///
/// If [asset] is in the special "packages" directory, writes it to every
/// build directory.
- Future _writeAsset(Asset asset) async {
- // In release mode, strip out .dart files since all relevant ones have been
- // compiled to JavaScript already.
- if (mode == BarbackMode.RELEASE && asset.id.extension == ".dart") return;
-
- var destPath = _idToPath(asset.id);
-
- // If the asset is from a public directory, copy it into all of the
- // top-level build directories.
- if (path.isWithin("packages", destPath)) {
- return Future.wait(sourceDirectories.map((buildDir) =>
- _writeOutputFile(asset, path.join(buildDir, destPath))));
- }
-
- return _writeOutputFile(asset, destPath);
+ Future _writeAsset(Asset asset) {
+ final completer0 = new Completer();
+ scheduleMicrotask(() {
+ try {
+ join0() {
+ var destPath = _idToPath(asset.id);
+ join1() {
+ completer0.complete(_writeOutputFile(asset, destPath));
+ }
+ if (path.isWithin("packages", destPath)) {
+ completer0.complete(Future.wait(sourceDirectories.map(((buildDir) {
+ return _writeOutputFile(asset, path.join(buildDir, destPath));
+ }))));
+ } else {
+ join1();
+ }
+ }
+ if (mode == BarbackMode.RELEASE && asset.id.extension == ".dart") {
+ completer0.complete(null);
+ } else {
+ join0();
+ }
+ } catch (e, s) {
+ completer0.completeError(e, s);
+ }
+ });
+ return completer0.future;
}
/// Converts [id] to a relative path in the output directory for that asset.
@@ -198,14 +198,16 @@ class BuildCommand extends BarbackCommand {
}
// Get all of the subdirectories that contain Dart entrypoints.
- var entrypointDirs = entrypoints
- // Convert the asset path to a native-separated one and get the
- // directory containing the entrypoint.
- .map((id) => path.dirname(path.fromUri(id.path)))
- // Don't copy files to the top levels of the build directories since
- // the normal lib asset copying will take care of that.
- .where((dir) => path.split(dir).length > 1)
- .toSet();
+ var entrypointDirs =
+ entrypoints// Convert the asset path to a native-separated one and get the
+ // directory containing the entrypoint.
+ .map(
+ (id) =>
+ path.dirname(
+ path.fromUri(
+ id.path)))// Don't copy files to the top levels of the build directories since
+ // the normal lib asset copying will take care of that.
+ .where((dir) => path.split(dir).length > 1).toSet();
for (var dir in entrypointDirs) {
// TODO(nweiz): we should put browser JS files next to any HTML file
@@ -223,7 +225,11 @@ class BuildCommand extends BarbackCommand {
/// under `packages/browser/`.
void _addBrowserJs(String directory, String name) {
var jsPath = entrypoint.root.path(
- outputDirectory, directory, 'packages', 'browser', '$name.js');
+ outputDirectory,
+ directory,
+ 'packages',
+ 'browser',
+ '$name.js');
ensureDir(path.dirname(jsPath));
// TODO(rnystrom): This won't work if we get rid of symlinks and the top

Powered by Google App Engine
This is Rietveld 408576698