OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library pub.entrypoint; | 5 library pub.entrypoint; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 /// The path to the entrypoint's ".packages" file. | 79 /// The path to the entrypoint's ".packages" file. |
80 String get packagesFile => root.path('.packages'); | 80 String get packagesFile => root.path('.packages'); |
81 | 81 |
82 /// `true` if the entrypoint package currently has a lock file. | 82 /// `true` if the entrypoint package currently has a lock file. |
83 bool get lockFileExists => _lockFile != null || entryExists(lockFilePath); | 83 bool get lockFileExists => _lockFile != null || entryExists(lockFilePath); |
84 | 84 |
85 LockFile get lockFile { | 85 LockFile get lockFile { |
86 if (_lockFile != null) return _lockFile; | 86 if (_lockFile != null) return _lockFile; |
87 | 87 |
88 if (!lockFileExists) { | 88 if (!lockFileExists) { |
89 _lockFile = new LockFile.empty(); | 89 _lockFile = new LockFile.empty(cache.sources); |
90 } else { | 90 } else { |
91 _lockFile = new LockFile.load(lockFilePath, cache.sources); | 91 _lockFile = new LockFile.load(lockFilePath, cache.sources); |
92 } | 92 } |
93 | 93 |
94 return _lockFile; | 94 return _lockFile; |
95 } | 95 } |
96 | 96 |
97 /// The path to the entrypoint package's pubspec. | 97 /// The path to the entrypoint package's pubspec. |
98 String get pubspecPath => root.path('pubspec.yaml'); | 98 String get pubspecPath => root.path('pubspec.yaml'); |
99 | 99 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 if (result != null) { | 459 if (result != null) { |
460 var packages = new Map.fromIterable(result.packages, | 460 var packages = new Map.fromIterable(result.packages, |
461 key: (id) => id.name, | 461 key: (id) => id.name, |
462 value: (id) { | 462 value: (id) { |
463 if (id.name == root.name) return root; | 463 if (id.name == root.name) return root; |
464 | 464 |
465 return new Package(result.pubspecs[id.name], | 465 return new Package(result.pubspecs[id.name], |
466 cache.sources[id.source].getDirectory(id)); | 466 cache.sources[id.source].getDirectory(id)); |
467 }); | 467 }); |
468 | 468 |
469 return new PackageGraph(this, new LockFile(result.packages), packages); | 469 return new PackageGraph( |
| 470 this, |
| 471 new LockFile(result.packages, cache.sources), |
| 472 packages); |
470 } | 473 } |
471 | 474 |
472 await ensureLockFileIsUpToDate(); | 475 await ensureLockFileIsUpToDate(); |
473 var packages = new Map.fromIterable(lockFile.packages.values, | 476 var packages = new Map.fromIterable(lockFile.packages.values, |
474 key: (id) => id.name, | 477 key: (id) => id.name, |
475 value: (id) { | 478 value: (id) { |
476 var dir = cache.sources[id.source].getDirectory(id); | 479 var dir = cache.sources[id.source].getDirectory(id); |
477 return new Package.load(id.name, dir, cache.sources); | 480 return new Package.load(id.name, dir, cache.sources); |
478 }); | 481 }); |
479 packages[root.name] = root; | 482 packages[root.name] = root; |
480 return new PackageGraph(this, lockFile, packages); | 483 return new PackageGraph(this, lockFile, packages); |
481 }, fine: true); | 484 }, fine: true); |
482 | 485 |
483 _packageGraph = graph; | 486 _packageGraph = graph; |
484 return graph; | 487 return graph; |
485 } | 488 } |
486 | 489 |
487 /// Saves a list of concrete package versions to the `pubspec.lock` file. | 490 /// Saves a list of concrete package versions to the `pubspec.lock` file. |
488 void _saveLockFile(List<PackageId> packageIds) { | 491 void _saveLockFile(List<PackageId> packageIds) { |
489 _lockFile = new LockFile(packageIds); | 492 _lockFile = new LockFile(packageIds, cache.sources); |
490 var lockFilePath = root.path('pubspec.lock'); | 493 var lockFilePath = root.path('pubspec.lock'); |
491 writeTextFile(lockFilePath, _lockFile.serialize(root.dir, cache.sources)); | 494 writeTextFile(lockFilePath, _lockFile.serialize(root.dir)); |
492 } | 495 } |
493 | 496 |
494 /// Creates a self-referential symlink in the `packages` directory that allows | 497 /// Creates a self-referential symlink in the `packages` directory that allows |
495 /// a package to import its own files using `package:`. | 498 /// a package to import its own files using `package:`. |
496 void _linkSelf() { | 499 void _linkSelf() { |
497 var linkPath = path.join(packagesDir, root.name); | 500 var linkPath = path.join(packagesDir, root.name); |
498 // Create the symlink if it doesn't exist. | 501 // Create the symlink if it doesn't exist. |
499 if (entryExists(linkPath)) return; | 502 if (entryExists(linkPath)) return; |
500 ensureDir(packagesDir); | 503 ensureDir(packagesDir); |
501 createPackageSymlink(root.name, root.dir, linkPath, | 504 createPackageSymlink(root.name, root.dir, linkPath, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 /// If [packageSymlinks] is true, creates a symlink to the "packages" | 551 /// If [packageSymlinks] is true, creates a symlink to the "packages" |
549 /// directory in [dir]. | 552 /// directory in [dir]. |
550 /// | 553 /// |
551 /// Otherwise, deletes a "packages" directories in [dir] if one exists. | 554 /// Otherwise, deletes a "packages" directories in [dir] if one exists. |
552 void _linkOrDeleteSecondaryPackageDir(String dir) { | 555 void _linkOrDeleteSecondaryPackageDir(String dir) { |
553 var symlink = path.join(dir, 'packages'); | 556 var symlink = path.join(dir, 'packages'); |
554 if (entryExists(symlink)) deleteEntry(symlink); | 557 if (entryExists(symlink)) deleteEntry(symlink); |
555 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); | 558 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); |
556 } | 559 } |
557 } | 560 } |
OLD | NEW |