Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 | 190 |
| 191 /** | 191 /** |
| 192 * Emits all outputs of [barback] and copies files that we didn't process (like | 192 * Emits all outputs of [barback] and copies files that we didn't process (like |
| 193 * polymer's libraries). | 193 * polymer's libraries). |
| 194 */ | 194 */ |
| 195 Future _emitAllFiles(Barback barback, BarbackOptions options) { | 195 Future _emitAllFiles(Barback barback, BarbackOptions options) { |
| 196 return barback.getAllAssets().then((assets) { | 196 return barback.getAllAssets().then((assets) { |
| 197 // Delete existing output folder before we generate anything | 197 // Delete existing output folder before we generate anything |
| 198 var dir = new Directory(options.outDir); | 198 var dir = new Directory(options.outDir); |
| 199 if (dir.existsSync()) dir.deleteSync(recursive: true); | 199 if (dir.existsSync()) dir.deleteSync(recursive: true); |
| 200 return _emitPackagesDir(options) | 200 _emitPackagesDir(options); |
| 201 .then((_) => _emitTransformedFiles(assets, options)) | 201 return _emitTransformedFiles(assets, options) |
| 202 .then((_) => _addPackagesSymlinks(assets, options)) | 202 .then((_) => _addPackagesSymlinks(assets, options)) |
| 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; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 link.createSync(targetPath); | 258 link.createSync(targetPath); |
| 259 } | 259 } |
| 260 } | 260 } |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 | 263 |
| 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 void _emitPackagesDir(BarbackOptions options) { |
| 269 if (options.transformPolymerDependencies) return new Future.value(null); | 269 if (options.transformPolymerDependencies) return; |
| 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 for (var package in _polymerPackageDependencies) { |
| 277 for (var relpath in _listPackageDir(package, 'lib', options)) { | 276 for (var relpath in _listPackageDir(package, 'lib', options)) { |
| 278 var inpath = path.join(dirs[package], relpath); | 277 var inpath = path.join(dirs[package], relpath); |
| 279 var outpath = path.join(outPackages, package, relpath.substring(4)); | 278 var outpath = path.join(outPackages, package, relpath.substring(4)); |
| 280 futures.add(_copyFile(inpath, outpath)); | 279 _copyFileSync(inpath, outpath); |
|
kevmoo-old
2013/10/05 04:23:12
Could this be the problem? We're adding a bunch of
Jennifer Messerly
2013/10/05 05:23:26
Sure, but then you're running them all serially. H
Søren Gjesse
2013/10/07 06:40:27
With async primitives you have the ability to easi
| |
| 281 } | 280 } |
| 282 } | 281 } |
| 283 return Future.wait(futures); | |
| 284 } | 282 } |
| 285 | 283 |
| 286 /** Ensure [dirpath] exists. */ | 284 /** Ensure [dirpath] exists. */ |
| 287 void _ensureDir(String dirpath) { | 285 void _ensureDir(String dirpath) { |
| 288 new Directory(dirpath).createSync(recursive: true); | 286 new Directory(dirpath).createSync(recursive: true); |
| 289 } | 287 } |
| 290 | 288 |
| 291 /** | 289 /** |
| 292 * Returns the first directory name on a url-style path, or null if there are no | 290 * Returns the first directory name on a url-style path, or null if there are no |
| 293 * slashes. | 291 * slashes. |
| 294 */ | 292 */ |
| 295 String _firstDir(String url) { | 293 String _firstDir(String url) { |
| 296 var firstSlash = url.indexOf('/'); | 294 var firstSlash = url.indexOf('/'); |
| 297 if (firstSlash == -1) return null; | 295 if (firstSlash == -1) return null; |
| 298 return url.substring(0, firstSlash); | 296 return url.substring(0, firstSlash); |
| 299 } | 297 } |
| 300 | 298 |
| 301 /** Copy a file from [inpath] to [outpath]. */ | 299 /** Copy a file from [inpath] to [outpath]. */ |
| 302 Future _copyFile(String inpath, String outpath) { | 300 void _copyFileSync(String inpath, String outpath) { |
| 303 _ensureDir(path.dirname(outpath)); | 301 _ensureDir(path.dirname(outpath)); |
| 304 var writer = new File(outpath).openWrite(); | 302 new File(outpath).writeAsBytesSync(new File(inpath).readAsBytesSync()); |
| 305 return writer.addStream(new File(inpath).openRead()) | |
| 306 .then((_) => writer.close()); | |
| 307 } | 303 } |
| 308 | 304 |
| 309 /** Write contents of an [asset] into a file at [filepath]. */ | 305 /** Write contents of an [asset] into a file at [filepath]. */ |
| 310 Future _writeAsset(String filepath, Asset asset) { | 306 Future _writeAsset(String filepath, Asset asset) { |
| 311 _ensureDir(path.dirname(filepath)); | 307 _ensureDir(path.dirname(filepath)); |
| 312 var writer = new File(filepath).openWrite(); | 308 var writer = new File(filepath).openWrite(); |
| 313 return writer.addStream(asset.read()).then((_) => writer.close()); | 309 return writer.addStream(asset.read()).then((_) => writer.close()); |
| 314 } | 310 } |
| OLD | NEW |