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

Side by Side Diff: pkg/polymer/lib/src/build/runner.dart

Issue 26268002: Emit assets in serial, use Stream.pipe to write to output files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: another forEach Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 /** 5 /**
6 * Definitions used to run the polymer linter and deploy tools without using 6 * Definitions used to run the polymer linter and deploy tools without using
7 * pub serve or pub deploy. 7 * pub serve or pub deploy.
8 */ 8 */
9 library polymer.src.build.runner; 9 library polymer.src.build.runner;
10 10
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 .then((_) => assets); 203 .then((_) => assets);
204 }); 204 });
205 } 205 }
206 206
207 Future _emitTransformedFiles(AssetSet assets, BarbackOptions options) { 207 Future _emitTransformedFiles(AssetSet assets, BarbackOptions options) {
208 // Copy all the assets we transformed 208 // Copy all the assets we transformed
209 var futures = []; 209 var futures = [];
210 var currentPackage = options.currentPackage; 210 var currentPackage = options.currentPackage;
211 var transformTests = options.transformTests; 211 var transformTests = options.transformTests;
212 var outPackages = path.join(options.outDir, 'packages'); 212 var outPackages = path.join(options.outDir, 'packages');
213 for (var asset in assets) { 213
214 return Future.forEach(assets, (asset) {
214 var id = asset.id; 215 var id = asset.id;
215 var dir = _firstDir(id.path); 216 var dir = _firstDir(id.path);
216 if (dir == null) continue; 217 if (dir == null) return null;
217 218
218 var filepath; 219 var filepath;
219 if (dir == 'lib') { 220 if (dir == 'lib') {
220 // Put lib files directly under the packages folder (e.g. 'lib/foo.dart' 221 // Put lib files directly under the packages folder (e.g. 'lib/foo.dart'
221 // will be emitted at out/packages/package_name/foo.dart). 222 // will be emitted at out/packages/package_name/foo.dart).
222 filepath = path.join(outPackages, id.package, 223 filepath = path.join(outPackages, id.package,
223 _toSystemPath(id.path.substring(4))); 224 _toSystemPath(id.path.substring(4)));
224 } else if (id.package == currentPackage && 225 } else if (id.package == currentPackage &&
225 (dir == 'web' || (transformTests && dir == 'test'))) { 226 (dir == 'web' || (transformTests && dir == 'test'))) {
226 filepath = path.join(options.outDir, _toSystemPath(id.path)); 227 filepath = path.join(options.outDir, _toSystemPath(id.path));
227 } else { 228 } else {
228 // TODO(sigmund): do something about other assets? 229 // TODO(sigmund): do something about other assets?
229 continue; 230 return null;
230 } 231 }
231 232
232 futures.add(_writeAsset(filepath, asset)); 233 return _writeAsset(filepath, asset);
233 } 234 });
234 return Future.wait(futures);
235 } 235 }
236 236
237 /** 237 /**
238 * Adds a package symlink from each directory under `out/web/foo/` to 238 * Adds a package symlink from each directory under `out/web/foo/` to
239 * `out/packages`. 239 * `out/packages`.
240 */ 240 */
241 Future _addPackagesSymlinks(AssetSet assets, BarbackOptions options) { 241 Future _addPackagesSymlinks(AssetSet assets, BarbackOptions options) {
242 var outPackages = path.join(options.outDir, 'packages'); 242 var outPackages = path.join(options.outDir, 'packages');
243 var currentPackage = options.currentPackage; 243 var currentPackage = options.currentPackage;
244 for (var asset in assets) { 244 for (var asset in assets) {
(...skipping 19 matching lines...) Expand all
264 /** 264 /**
265 * Emits a 'packages' directory directly under `out/packages` with the contents 265 * Emits a 'packages' directory directly under `out/packages` with the contents
266 * of every file that was not transformed by barback. 266 * of every file that was not transformed by barback.
267 */ 267 */
268 Future _emitPackagesDir(BarbackOptions options) { 268 Future _emitPackagesDir(BarbackOptions options) {
269 if (options.transformPolymerDependencies) return new Future.value(null); 269 if (options.transformPolymerDependencies) return new Future.value(null);
270 var outPackages = path.join(options.outDir, 'packages'); 270 var outPackages = path.join(options.outDir, 'packages');
271 _ensureDir(outPackages); 271 _ensureDir(outPackages);
272 272
273 // Copy all the files we didn't process 273 // Copy all the files we didn't process
274 var futures = [];
275 var dirs = options.packageDirs; 274 var dirs = options.packageDirs;
276 for (var package in _polymerPackageDependencies) { 275
277 for (var relpath in _listPackageDir(package, 'lib', options)) { 276 return Future.forEach(_polymerPackageDependencies, (package) {
277 return Future.forEach(_listPackageDir(package, 'lib', options), (relpath) {
278 var inpath = path.join(dirs[package], relpath); 278 var inpath = path.join(dirs[package], relpath);
279 var outpath = path.join(outPackages, package, relpath.substring(4)); 279 var outpath = path.join(outPackages, package, relpath.substring(4));
280 futures.add(_copyFile(inpath, outpath)); 280 return _copyFile(inpath, outpath);
281 } 281 });
282 } 282 });
283 return Future.wait(futures);
284 } 283 }
285 284
286 /** Ensure [dirpath] exists. */ 285 /** Ensure [dirpath] exists. */
287 void _ensureDir(String dirpath) { 286 void _ensureDir(String dirpath) {
288 new Directory(dirpath).createSync(recursive: true); 287 new Directory(dirpath).createSync(recursive: true);
289 } 288 }
290 289
291 /** 290 /**
292 * Returns the first directory name on a url-style path, or null if there are no 291 * Returns the first directory name on a url-style path, or null if there are no
293 * slashes. 292 * slashes.
294 */ 293 */
295 String _firstDir(String url) { 294 String _firstDir(String url) {
296 var firstSlash = url.indexOf('/'); 295 var firstSlash = url.indexOf('/');
297 if (firstSlash == -1) return null; 296 if (firstSlash == -1) return null;
298 return url.substring(0, firstSlash); 297 return url.substring(0, firstSlash);
299 } 298 }
300 299
301 /** Copy a file from [inpath] to [outpath]. */ 300 /** Copy a file from [inpath] to [outpath]. */
302 Future _copyFile(String inpath, String outpath) { 301 Future _copyFile(String inpath, String outpath) {
303 _ensureDir(path.dirname(outpath)); 302 _ensureDir(path.dirname(outpath));
304 var writer = new File(outpath).openWrite(); 303 return new File(inpath).openRead().pipe(new File(outpath).openWrite());
305 return writer.addStream(new File(inpath).openRead())
306 .then((_) => writer.close());
307 } 304 }
308 305
309 /** Write contents of an [asset] into a file at [filepath]. */ 306 /** Write contents of an [asset] into a file at [filepath]. */
310 Future _writeAsset(String filepath, Asset asset) { 307 Future _writeAsset(String filepath, Asset asset) {
311 _ensureDir(path.dirname(filepath)); 308 _ensureDir(path.dirname(filepath));
312 var writer = new File(filepath).openWrite(); 309 return asset.read().pipe(new File(filepath).openWrite());
313 return writer.addStream(asset.read()).then((_) => writer.close());
314 } 310 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698