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

Side by Side Diff: sdk/lib/_internal/pub_generated/lib/src/entrypoint.dart

Issue 583853002: Use precompiled dependencies in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 3 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
OLDNEW
1 library pub.entrypoint; 1 library pub.entrypoint;
2 import 'dart:async'; 2 import 'dart:async';
3 import 'package:path/path.dart' as path; 3 import 'package:path/path.dart' as path;
4 import 'package:barback/barback.dart'; 4 import 'package:barback/barback.dart';
5 import 'barback/asset_environment.dart'; 5 import 'barback/asset_environment.dart';
6 import 'io.dart'; 6 import 'io.dart';
7 import 'lock_file.dart'; 7 import 'lock_file.dart';
8 import 'log.dart' as log; 8 import 'log.dart' as log;
9 import 'package.dart'; 9 import 'package.dart';
10 import 'package_graph.dart'; 10 import 'package_graph.dart';
11 import 'sdk.dart' as sdk; 11 import 'sdk.dart' as sdk;
12 import 'solver/version_solver.dart'; 12 import 'solver/version_solver.dart';
13 import 'source/cached.dart'; 13 import 'source/cached.dart';
14 import 'system_cache.dart'; 14 import 'system_cache.dart';
15 import 'utils.dart'; 15 import 'utils.dart';
16 class Entrypoint { 16 class Entrypoint {
17 final Package root; 17 final Package root;
18 final SystemCache cache; 18 final SystemCache cache;
19 final bool _packageSymlinks; 19 final bool _packageSymlinks;
20 LockFile _lockFile; 20 LockFile _lockFile;
21 PackageGraph _packageGraph; 21 PackageGraph _packageGraph;
22 Entrypoint(String rootDir, SystemCache cache, {bool packageSymlinks: true}) 22 Entrypoint(String rootDir, SystemCache cache, {bool packageSymlinks: true})
23 : root = new Package.load(null, rootDir, cache.sources), 23 : root = new Package.load(null, rootDir, cache.sources),
24 cache = cache, 24 cache = cache,
25 _packageSymlinks = packageSymlinks; 25 _packageSymlinks = packageSymlinks;
26 Entrypoint.inMemory(this.root, this._lockFile, this.cache) 26 Entrypoint.inMemory(this.root, this._lockFile, this.cache)
27 : _packageSymlinks = false; 27 : _packageSymlinks = false;
28 String get packagesDir => path.join(root.dir, 'packages'); 28 String get packagesDir => root.path('packages');
29 bool get lockFileExists => _lockFile != null || entryExists(lockFilePath); 29 bool get lockFileExists => _lockFile != null || entryExists(lockFilePath);
30 LockFile get lockFile { 30 LockFile get lockFile {
31 if (_lockFile != null) return _lockFile; 31 if (_lockFile != null) return _lockFile;
32 if (!lockFileExists) { 32 if (!lockFileExists) {
33 _lockFile = new LockFile.empty(); 33 _lockFile = new LockFile.empty();
34 } else { 34 } else {
35 _lockFile = new LockFile.load(lockFilePath, cache.sources); 35 _lockFile = new LockFile.load(lockFilePath, cache.sources);
36 } 36 }
37 return _lockFile; 37 return _lockFile;
38 } 38 }
39 String get pubspecPath => path.join(root.dir, 'pubspec.yaml'); 39 String get pubspecPath => root.path('pubspec.yaml');
40 String get lockFilePath => path.join(root.dir, 'pubspec.lock'); 40 String get lockFilePath => root.path('pubspec.lock');
41 Future acquireDependencies(SolveType type, {List<String> useLatest, 41 Future acquireDependencies(SolveType type, {List<String> useLatest,
42 bool dryRun: false}) { 42 bool dryRun: false}) {
43 final completer0 = new Completer(); 43 final completer0 = new Completer();
44 scheduleMicrotask(() { 44 scheduleMicrotask(() {
45 try { 45 try {
46 resolveVersions( 46 resolveVersions(
47 type, 47 type,
48 cache.sources, 48 cache.sources,
49 root, 49 root,
50 lockFile: lockFile, 50 lockFile: lockFile,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 changed); 147 changed);
148 })).map(((package) => package.name)).toSet(); 148 })).map(((package) => package.name)).toSet();
149 join1() { 149 join1() {
150 log.progress("Precompiling dependencies", (() { 150 log.progress("Precompiling dependencies", (() {
151 final completer0 = new Completer(); 151 final completer0 = new Completer();
152 scheduleMicrotask(() { 152 scheduleMicrotask(() {
153 try { 153 try {
154 var packagesToLoad = unionAll( 154 var packagesToLoad = unionAll(
155 dependenciesToPrecompile.map( 155 dependenciesToPrecompile.map(
156 graph.transitiveDependencies)).map(((package) => p ackage.name)).toSet(); 156 graph.transitiveDependencies)).map(((package) => p ackage.name)).toSet();
157 AssetEnvironment.create( 157 var it0 = dependenciesToPrecompile.iterator;
158 this, 158 break0(x4) {
159 BarbackMode.DEBUG, 159 AssetEnvironment.create(
160 packages: packagesToLoad, 160 this,
161 useDart2JS: false).then((x0) { 161 BarbackMode.DEBUG,
162 try { 162 packages: packagesToLoad,
163 var environment = x0; 163 useDart2JS: false).then((x0) {
164 environment.barback.errors.listen(((_) {})); 164 try {
165 var it0 = dependenciesToPrecompile.iterator; 165 var environment = x0;
166 break0(x4) { 166 environment.barback.errors.listen(((_) {}));
167 environment.barback.getAllAssets().then((x1) { 167 environment.barback.getAllAssets().then((x1) {
168 try { 168 try {
169 var assets = x1; 169 var assets = x1;
170 waitAndPrintErrors(assets.map(((asset) { 170 waitAndPrintErrors(assets.map(((asset) {
171 final completer0 = new Completer(); 171 final completer0 = new Completer();
172 scheduleMicrotask(() { 172 scheduleMicrotask(() {
173 try { 173 try {
174 join0() { 174 join0() {
175 var destPath = 175 var destPath =
176 path.join(depsDir, asset.id.package, path.fromUri(asset.id.path)); 176 path.join(depsDir, asset.id.package, path.fromUri(asset.id.path));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 212 }
213 }, onError: (e3) { 213 }, onError: (e3) {
214 completer0.completeError(e3); 214 completer0.completeError(e3);
215 }); 215 });
216 } catch (e1) { 216 } catch (e1) {
217 completer0.completeError(e1); 217 completer0.completeError(e1);
218 } 218 }
219 }, onError: (e4) { 219 }, onError: (e4) {
220 completer0.completeError(e4); 220 completer0.completeError(e4);
221 }); 221 });
222 } catch (e0) {
223 completer0.completeError(e0);
222 } 224 }
223 continue0(x5) { 225 }, onError: (e5) {
224 if (it0.moveNext()) { 226 completer0.completeError(e5);
225 Future.wait([]).then((x3) { 227 });
226 var package = it0.current; 228 }
227 cleanDir(path.join(depsDir, package)); 229 continue0(x5) {
228 continue0(null); 230 if (it0.moveNext()) {
229 }); 231 Future.wait([]).then((x3) {
230 } else { 232 var package = it0.current;
231 break0(null); 233 deleteEntry(path.join(depsDir, package));
232 } 234 continue0(null);
233 } 235 });
234 continue0(null); 236 } else {
235 } catch (e0) { 237 break0(null);
236 completer0.completeError(e0);
237 } 238 }
238 }, onError: (e5) { 239 }
239 completer0.completeError(e5); 240 continue0(null);
240 });
241 } catch (e6) { 241 } catch (e6) {
242 completer0.completeError(e6); 242 completer0.completeError(e6);
243 } 243 }
244 }); 244 });
245 return completer0.future; 245 return completer0.future;
246 })).catchError(((error) { 246 })).catchError(((error) {
247 for (var package in dependenciesToPrecompile) { 247 for (var package in dependenciesToPrecompile) {
248 deleteEntry(path.join(depsDir, package)); 248 deleteEntry(path.join(depsDir, package));
249 } 249 }
250 throw error; 250 throw error;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 dir, 323 dir,
324 executableIds: executables[package]); 324 executableIds: executables[package]);
325 })); 325 }));
326 }); 326 });
327 }); 327 });
328 }); 328 });
329 } 329 }
330 List<AssetId> _executablesForPackage(PackageGraph graph, String packageName, 330 List<AssetId> _executablesForPackage(PackageGraph graph, String packageName,
331 Set<String> changed) { 331 Set<String> changed) {
332 var package = graph.packages[packageName]; 332 var package = graph.packages[packageName];
333 var binDir = path.join(package.dir, 'bin'); 333 var binDir = package.path('bin');
334 if (!dirExists(binDir)) return []; 334 if (!dirExists(binDir)) return [];
335 if (graph.isPackageMutable(packageName)) return []; 335 if (graph.isPackageMutable(packageName)) return [];
336 var executables = package.executableIds; 336 var executables = package.executableIds;
337 if (changed == null) return executables; 337 if (changed == null) return executables;
338 if (graph.transitiveDependencies( 338 if (graph.transitiveDependencies(
339 packageName).any((package) => changed.contains(package.name))) { 339 packageName).any((package) => changed.contains(package.name))) {
340 return executables; 340 return executables;
341 } 341 }
342 var executablesExist = executables.every( 342 var executablesExist = executables.every(
343 (executable) => 343 (executable) =>
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 }); 436 });
437 }); 437 });
438 } 438 }
439 }).then((graph) { 439 }).then((graph) {
440 _packageGraph = graph; 440 _packageGraph = graph;
441 return graph; 441 return graph;
442 }); 442 });
443 } 443 }
444 void _saveLockFile(List<PackageId> packageIds) { 444 void _saveLockFile(List<PackageId> packageIds) {
445 _lockFile = new LockFile(packageIds); 445 _lockFile = new LockFile(packageIds);
446 var lockFilePath = path.join(root.dir, 'pubspec.lock'); 446 var lockFilePath = root.path('pubspec.lock');
447 writeTextFile(lockFilePath, _lockFile.serialize(root.dir, cache.sources)); 447 writeTextFile(lockFilePath, _lockFile.serialize(root.dir, cache.sources));
448 } 448 }
449 void _linkSelf() { 449 void _linkSelf() {
450 var linkPath = path.join(packagesDir, root.name); 450 var linkPath = path.join(packagesDir, root.name);
451 if (entryExists(linkPath)) return; 451 if (entryExists(linkPath)) return;
452 ensureDir(packagesDir); 452 ensureDir(packagesDir);
453 createPackageSymlink( 453 createPackageSymlink(
454 root.name, 454 root.name,
455 root.dir, 455 root.dir,
456 linkPath, 456 linkPath,
457 isSelfLink: true, 457 isSelfLink: true,
458 relative: true); 458 relative: true);
459 } 459 }
460 void _linkOrDeleteSecondaryPackageDirs() { 460 void _linkOrDeleteSecondaryPackageDirs() {
461 var binDir = path.join(root.dir, 'bin'); 461 var binDir = root.path('bin');
462 if (dirExists(binDir)) _linkOrDeleteSecondaryPackageDir(binDir); 462 if (dirExists(binDir)) _linkOrDeleteSecondaryPackageDir(binDir);
463 for (var dir in ['benchmark', 'example', 'test', 'tool', 'web']) { 463 for (var dir in ['benchmark', 'example', 'test', 'tool', 'web']) {
464 _linkOrDeleteSecondaryPackageDirsRecursively(path.join(root.dir, dir)); 464 _linkOrDeleteSecondaryPackageDirsRecursively(root.path(dir));
465 } 465 }
466 } 466 }
467 void _linkOrDeleteSecondaryPackageDirsRecursively(String dir) { 467 void _linkOrDeleteSecondaryPackageDirsRecursively(String dir) {
468 if (!dirExists(dir)) return; 468 if (!dirExists(dir)) return;
469 _linkOrDeleteSecondaryPackageDir(dir); 469 _linkOrDeleteSecondaryPackageDir(dir);
470 _listDirWithoutPackages( 470 _listDirWithoutPackages(
471 dir).where(dirExists).forEach(_linkOrDeleteSecondaryPackageDir); 471 dir).where(dirExists).forEach(_linkOrDeleteSecondaryPackageDir);
472 } 472 }
473 List<String> _listDirWithoutPackages(dir) { 473 List<String> _listDirWithoutPackages(dir) {
474 return flatten(listDir(dir).map((file) { 474 return flatten(listDir(dir).map((file) {
475 if (path.basename(file) == 'packages') return []; 475 if (path.basename(file) == 'packages') return [];
476 if (!dirExists(file)) return []; 476 if (!dirExists(file)) return [];
477 var fileAndSubfiles = [file]; 477 var fileAndSubfiles = [file];
478 fileAndSubfiles.addAll(_listDirWithoutPackages(file)); 478 fileAndSubfiles.addAll(_listDirWithoutPackages(file));
479 return fileAndSubfiles; 479 return fileAndSubfiles;
480 })); 480 }));
481 } 481 }
482 void _linkOrDeleteSecondaryPackageDir(String dir) { 482 void _linkOrDeleteSecondaryPackageDir(String dir) {
483 var symlink = path.join(dir, 'packages'); 483 var symlink = path.join(dir, 'packages');
484 if (entryExists(symlink)) deleteEntry(symlink); 484 if (entryExists(symlink)) deleteEntry(symlink);
485 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); 485 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true);
486 } 486 }
487 } 487 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698