| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
| 9 import 'package:package_config/packages_file.dart' as packages_file; | 9 import 'package:package_config/packages_file.dart' as packages_file; |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 /// Whether this is an entrypoint for a globally-activated package. | 63 /// Whether this is an entrypoint for a globally-activated package. |
| 64 final bool isGlobal; | 64 final bool isGlobal; |
| 65 | 65 |
| 66 /// The lockfile for the entrypoint. | 66 /// The lockfile for the entrypoint. |
| 67 /// | 67 /// |
| 68 /// If not provided to the entrypoint, it will be loaded lazily from disk. | 68 /// If not provided to the entrypoint, it will be loaded lazily from disk. |
| 69 LockFile get lockFile { | 69 LockFile get lockFile { |
| 70 if (_lockFile != null) return _lockFile; | 70 if (_lockFile != null) return _lockFile; |
| 71 | 71 |
| 72 if (!fileExists(lockFilePath)) { | 72 if (!fileExists(lockFilePath)) { |
| 73 _lockFile = new LockFile.empty(cache.sources); | 73 _lockFile = new LockFile.empty(); |
| 74 } else { | 74 } else { |
| 75 _lockFile = new LockFile.load(lockFilePath, cache.sources); | 75 _lockFile = new LockFile.load(lockFilePath, cache.sources); |
| 76 } | 76 } |
| 77 | 77 |
| 78 return _lockFile; | 78 return _lockFile; |
| 79 } | 79 } |
| 80 LockFile _lockFile; | 80 LockFile _lockFile; |
| 81 | 81 |
| 82 /// The package graph for the application and all of its transitive | 82 /// The package graph for the application and all of its transitive |
| 83 /// dependencies. | 83 /// dependencies. |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 'changed since the pubspec.lock file was generated, please run "pub ' | 532 'changed since the pubspec.lock file was generated, please run "pub ' |
| 533 'get" again.'); | 533 'get" again.'); |
| 534 } | 534 } |
| 535 } | 535 } |
| 536 | 536 |
| 537 /// Returns whether the locked version of [dep] matches the dependency. | 537 /// Returns whether the locked version of [dep] matches the dependency. |
| 538 bool _isDependencyUpToDate(PackageDep dep) { | 538 bool _isDependencyUpToDate(PackageDep dep) { |
| 539 if (dep.name == root.name) return true; | 539 if (dep.name == root.name) return true; |
| 540 | 540 |
| 541 var locked = lockFile.packages[dep.name]; | 541 var locked = lockFile.packages[dep.name]; |
| 542 if (locked == null) return false; | 542 return locked != null && dep.allows(locked); |
| 543 | |
| 544 if (dep.source != locked.source) return false; | |
| 545 | |
| 546 if (!dep.constraint.allows(locked.version)) return false; | |
| 547 | |
| 548 var source = cache.sources[dep.source]; | |
| 549 if (source == null) return false; | |
| 550 | |
| 551 return source.descriptionsEqual(dep.description, locked.description); | |
| 552 } | 543 } |
| 553 | 544 |
| 554 /// Determines whether all of the packages in the lockfile are already | 545 /// Determines whether all of the packages in the lockfile are already |
| 555 /// installed and available. | 546 /// installed and available. |
| 556 bool _arePackagesAvailable() { | 547 bool _arePackagesAvailable() { |
| 557 return lockFile.packages.values.every((package) { | 548 return lockFile.packages.values.every((package) { |
| 558 var source = cache.sources[package.source]; | 549 if (package.source is UnknownSource) return false; |
| 559 if (source is UnknownSource) return false; | |
| 560 | 550 |
| 561 // We only care about cached sources. Uncached sources aren't "installed". | 551 // We only care about cached sources. Uncached sources aren't "installed". |
| 562 // If one of those is missing, we want to show the user the file not | 552 // If one of those is missing, we want to show the user the file not |
| 563 // found error later since installing won't accomplish anything. | 553 // found error later since installing won't accomplish anything. |
| 564 var boundSource = cache.source(package.source); | 554 var source = cache.source(package.source); |
| 565 if (boundSource is! CachedSource) return true; | 555 if (source is! CachedSource) return true; |
| 566 | 556 |
| 567 // Get the directory. | 557 // Get the directory. |
| 568 var dir = boundSource.getDirectory(package); | 558 var dir = source.getDirectory(package); |
| 569 // See if the directory is there and looks like a package. | 559 // See if the directory is there and looks like a package. |
| 570 return dirExists(dir) && fileExists(p.join(dir, "pubspec.yaml")); | 560 return dirExists(dir) && fileExists(p.join(dir, "pubspec.yaml")); |
| 571 }); | 561 }); |
| 572 } | 562 } |
| 573 | 563 |
| 574 /// Determines whether or not the `.packages` file is out of date with respect | 564 /// Determines whether or not the `.packages` file is out of date with respect |
| 575 /// to the lockfile. | 565 /// to the lockfile. |
| 576 /// | 566 /// |
| 577 /// This will be `false` if the packages file contains dependencies that are | 567 /// This will be `false` if the packages file contains dependencies that are |
| 578 /// not in the lockfile or that don't match what's in there. | 568 /// not in the lockfile or that don't match what's in there. |
| 579 bool _isPackagesFileUpToDate() { | 569 bool _isPackagesFileUpToDate() { |
| 580 var packages = packages_file.parse( | 570 var packages = packages_file.parse( |
| 581 new File(packagesFile).readAsBytesSync(), | 571 new File(packagesFile).readAsBytesSync(), |
| 582 p.toUri(packagesFile)); | 572 p.toUri(packagesFile)); |
| 583 | 573 |
| 584 return lockFile.packages.values.every((lockFileId) { | 574 return lockFile.packages.values.every((lockFileId) { |
| 585 var source = cache.source(lockFileId.source); | |
| 586 | |
| 587 // It's very unlikely that the lockfile is invalid here, but it's not | 575 // It's very unlikely that the lockfile is invalid here, but it's not |
| 588 // impossible—for example, the user may have a very old application | 576 // impossible—for example, the user may have a very old application |
| 589 // package with a checked-in lockfile that's newer than the pubspec, but | 577 // package with a checked-in lockfile that's newer than the pubspec, but |
| 590 // that contains sdk dependencies. | 578 // that contains sdk dependencies. |
| 591 if (source.source is UnknownSource) return false; | 579 if (lockFileId.source is UnknownSource) return false; |
| 592 | 580 |
| 593 var packagesFileUri = packages[lockFileId.name]; | 581 var packagesFileUri = packages[lockFileId.name]; |
| 594 if (packagesFileUri == null) return false; | 582 if (packagesFileUri == null) return false; |
| 595 | 583 |
| 596 // Pub only generates "file:" and relative URIs. | 584 // Pub only generates "file:" and relative URIs. |
| 597 if (packagesFileUri.scheme != 'file' && | 585 if (packagesFileUri.scheme != 'file' && |
| 598 packagesFileUri.scheme.isNotEmpty) { | 586 packagesFileUri.scheme.isNotEmpty) { |
| 599 return false; | 587 return false; |
| 600 } | 588 } |
| 601 | 589 |
| 590 var source = cache.source(lockFileId.source); |
| 591 |
| 602 // Get the dirname of the .packages path, since it's pointing to lib/. | 592 // Get the dirname of the .packages path, since it's pointing to lib/. |
| 603 var packagesFilePath = p.dirname( | 593 var packagesFilePath = p.dirname( |
| 604 p.join(root.dir, p.fromUri(packagesFileUri))); | 594 p.join(root.dir, p.fromUri(packagesFileUri))); |
| 605 var lockFilePath = p.join(root.dir, source.getDirectory(lockFileId)); | 595 var lockFilePath = p.join(root.dir, source.getDirectory(lockFileId)); |
| 606 | 596 |
| 607 // For cached sources, make sure the directory exists and looks like a | 597 // For cached sources, make sure the directory exists and looks like a |
| 608 // package. This is also done by [_arePackagesAvailable] but that may not | 598 // package. This is also done by [_arePackagesAvailable] but that may not |
| 609 // be run if the lockfile is newer than the pubspec. | 599 // be run if the lockfile is newer than the pubspec. |
| 610 if (source is CachedSource && | 600 if (source is CachedSource && |
| 611 !dirExists(packagesFilePath) || | 601 !dirExists(packagesFilePath) || |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 /// If [packageSymlinks] is true, creates a symlink to the "packages" | 673 /// If [packageSymlinks] is true, creates a symlink to the "packages" |
| 684 /// directory in [dir]. | 674 /// directory in [dir]. |
| 685 /// | 675 /// |
| 686 /// Otherwise, deletes a "packages" directories in [dir] if one exists. | 676 /// Otherwise, deletes a "packages" directories in [dir] if one exists. |
| 687 void _linkOrDeleteSecondaryPackageDir(String dir) { | 677 void _linkOrDeleteSecondaryPackageDir(String dir) { |
| 688 var symlink = p.join(dir, 'packages'); | 678 var symlink = p.join(dir, 'packages'); |
| 689 if (entryExists(symlink)) deleteEntry(symlink); | 679 if (entryExists(symlink)) deleteEntry(symlink); |
| 690 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); | 680 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); |
| 691 } | 681 } |
| 692 } | 682 } |
| OLD | NEW |