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

Side by Side Diff: lib/src/command/build.dart

Issue 2184303002: Make pub strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 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 unified diff | Download patch
« no previous file with comments | « lib/src/command/barback.dart ('k') | lib/src/command/cache_repair.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:barback/barback.dart'; 7 import 'package:barback/barback.dart';
8 import 'package:path/path.dart' as path; 8 import 'package:path/path.dart' as path;
9 9
10 import '../barback/asset_environment.dart'; 10 import '../barback/asset_environment.dart';
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 help: "Directory to write build outputs to.", 46 help: "Directory to write build outputs to.",
47 defaultsTo: "build"); 47 defaultsTo: "build");
48 } 48 }
49 49
50 Future onRunTransformerCommand() async { 50 Future onRunTransformerCommand() async {
51 cleanDir(outputDirectory); 51 cleanDir(outputDirectory);
52 52
53 var errorsJson = []; 53 var errorsJson = [];
54 var logJson = []; 54 var logJson = [];
55 55
56 var environmentConstants = new Map.fromIterable(argResults["define"], 56 var environmentConstants = new Map<String, String>.fromIterable(
57 argResults["define"],
57 key: (pair) => pair.split("=").first, 58 key: (pair) => pair.split("=").first,
58 value: (pair) => pair.split("=").last); 59 value: (pair) => pair.split("=").last);
59 60
60 // Since this server will only be hit by the transformer loader and isn't 61 try {
61 // user-facing, just use an IPv4 address to avoid a weird bug on the 62 // Since this server will only be hit by the transformer loader and isn't
62 // OS X buildbots. 63 // user-facing, just use an IPv4 address to avoid a weird bug on the OS X
63 return AssetEnvironment.create(entrypoint, mode, 64 // buildbots.
65 var environment = await AssetEnvironment.create(entrypoint, mode,
64 environmentConstants: environmentConstants, 66 environmentConstants: environmentConstants,
65 useDart2JS: true) 67 useDart2JS: true);
66 .then((environment) { 68
67 // Show in-progress errors, but not results. Those get handled 69 // Show in-progress errors, but not results. Those get handled
68 // implicitly by getAllAssets(). 70 // implicitly by getAllAssets().
69 environment.barback.errors.listen((error) { 71 environment.barback.errors.listen((error) {
70 log.error(log.red("Build error:\n$error")); 72 log.error(log.red("Build error:\n$error"));
71 73
72 if (log.json.enabled) { 74 if (log.json.enabled) {
73 // Wrap the error in a map in case we end up decorating it with 75 // Wrap the error in a map in case we end up decorating it with
74 // more properties later. 76 // more properties later.
75 errorsJson.add({ 77 errorsJson.add({
76 "error": error.toString() 78 "error": error.toString()
77 }); 79 });
78 } 80 }
79 }); 81 });
80 82
81 // If we're using JSON output, the regular server logging is disabled. 83 // If we're using JSON output, the regular server logging is disabled.
82 // Instead, we collect it here to include in the final JSON result. 84 // Instead, we collect it here to include in the final JSON result.
83 if (log.json.enabled) { 85 if (log.json.enabled) {
84 environment.barback.log.listen( 86 environment.barback.log.listen(
85 (entry) => logJson.add(_logEntryToJson(entry))); 87 (entry) => logJson.add(_logEntryToJson(entry)));
86 } 88 }
87 89
88 return log.progress("Building ${entrypoint.root.name}", () { 90 var assets = await log.progress("Building ${entrypoint.root.name}",
91 () async {
89 // Register all of the build directories. 92 // Register all of the build directories.
90 // TODO(rnystrom): We don't actually need to bind servers for these, we 93 // TODO(rnystrom): We don't actually need to bind servers for these, we
91 // just need to add them to barback's sources. Add support to 94 // just need to add them to barback's sources. Add support to
92 // BuildEnvironment for going the latter without the former. 95 // BuildEnvironment for going the latter without the former.
93 return Future.wait(sourceDirectories.map( 96 await Future.wait(sourceDirectories.map(
94 (dir) => environment.serveDirectory(dir))).then((_) { 97 (dir) => environment.serveDirectory(dir)));
95 98
96 return environment.barback.getAllAssets(); 99 return environment.barback.getAllAssets();
97 }); 100 });
98 }).then((assets) {
99 // Find all of the JS entrypoints we built.
100 var dart2JSEntrypoints = assets
101 .where((asset) => asset.id.path.endsWith(".dart.js"))
102 .map((asset) => asset.id);
103 101
104 return Future.wait(assets.map(_writeAsset)).then((_) { 102 // Find all of the JS entrypoints we built.
105 return _copyBrowserJsFiles(dart2JSEntrypoints, assets); 103 var dart2JSEntrypoints = assets
106 }).then((_) { 104 .where((asset) => asset.id.path.endsWith(".dart.js"))
107 log.message('Built $builtFiles ${pluralize('file', builtFiles)} ' 105 .map((asset) => asset.id);
108 'to "$outputDirectory".');
109 106
110 log.json.message({ 107 await Future.wait(assets.map(_writeAsset));
111 "buildResult": "success", 108 await _copyBrowserJsFiles(dart2JSEntrypoints, assets);
112 "outputDirectory": outputDirectory, 109
113 "numFiles": builtFiles, 110 log.message('Built $builtFiles ${pluralize('file', builtFiles)} '
114 "log": logJson 111 'to "$outputDirectory".');
115 }); 112
116 }); 113 log.json.message({
114 "buildResult": "success",
115 "outputDirectory": outputDirectory,
116 "numFiles": builtFiles,
117 "log": logJson
117 }); 118 });
118 }).catchError((error) { 119 } on BarbackException catch (_) {
119 // If [getAllAssets()] throws a BarbackException, the error has already 120 // If [getAllAssets()] throws a BarbackException, the error has already
120 // been reported. 121 // been reported.
121 if (error is! BarbackException) throw error;
122
123 log.error(log.red("Build failed.")); 122 log.error(log.red("Build failed."));
124 log.json.message({ 123 log.json.message({
125 "buildResult": "failure", 124 "buildResult": "failure",
126 "errors": errorsJson, 125 "errors": errorsJson,
127 "log": logJson 126 "log": logJson
128 }); 127 });
129 128
130 return flushThenExit(exit_codes.DATA); 129 return flushThenExit(exit_codes.DATA);
131 }); 130 }
132 } 131 }
133 132
134 /// Writes [asset] to the appropriate build directory. 133 /// Writes [asset] to the appropriate build directory.
135 /// 134 ///
136 /// If [asset] is in the special "packages" directory, writes it to every 135 /// If [asset] is in the special "packages" directory, writes it to every
137 /// build directory. 136 /// build directory.
138 Future _writeAsset(Asset asset) async { 137 Future _writeAsset(Asset asset) async {
139 // In release mode, strip out .dart files since all relevant ones have been 138 // In release mode, strip out .dart files since all relevant ones have been
140 // compiled to JavaScript already. 139 // compiled to JavaScript already.
141 if (mode == BarbackMode.RELEASE && asset.id.extension == ".dart") { 140 if (mode == BarbackMode.RELEASE && asset.id.extension == ".dart") {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 "end": { 257 "end": {
259 "line": entry.span.end.line, 258 "line": entry.span.end.line,
260 "column": entry.span.end.column 259 "column": entry.span.end.column
261 }, 260 },
262 }; 261 };
263 } 262 }
264 263
265 return data; 264 return data;
266 } 265 }
267 } 266 }
OLDNEW
« no previous file with comments | « lib/src/command/barback.dart ('k') | lib/src/command/cache_repair.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698