| 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; |
| 11 import 'package:pub_semver/pub_semver.dart'; | 11 import 'package:pub_semver/pub_semver.dart'; |
| 12 | 12 |
| 13 import 'barback/asset_environment.dart'; | 13 import 'barback/asset_environment.dart'; |
| 14 import 'exceptions.dart'; |
| 14 import 'io.dart'; | 15 import 'io.dart'; |
| 15 import 'lock_file.dart'; | 16 import 'lock_file.dart'; |
| 16 import 'log.dart' as log; | 17 import 'log.dart' as log; |
| 17 import 'package.dart'; | 18 import 'package.dart'; |
| 18 import 'package_graph.dart'; | 19 import 'package_graph.dart'; |
| 19 import 'sdk.dart' as sdk; | 20 import 'sdk.dart' as sdk; |
| 20 import 'solver/version_solver.dart'; | 21 import 'solver/version_solver.dart'; |
| 21 import 'source/cached.dart'; | 22 import 'source/cached.dart'; |
| 22 import 'source/unknown.dart'; | 23 import 'source/unknown.dart'; |
| 23 import 'system_cache.dart'; | 24 import 'system_cache.dart'; |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 // and this is on the hot path for "pub run". | 460 // and this is on the hot path for "pub run". |
| 460 var lockFileText = readTextFile(lockFilePath); | 461 var lockFileText = readTextFile(lockFilePath); |
| 461 var hasPathDependencies = lockFileText.contains("\n source: path\n"); | 462 var hasPathDependencies = lockFileText.contains("\n source: path\n"); |
| 462 | 463 |
| 463 var pubspecModified = new File(pubspecPath).lastModifiedSync(); | 464 var pubspecModified = new File(pubspecPath).lastModifiedSync(); |
| 464 var lockFileModified = new File(lockFilePath).lastModifiedSync(); | 465 var lockFileModified = new File(lockFilePath).lastModifiedSync(); |
| 465 | 466 |
| 466 var touchedLockFile = false; | 467 var touchedLockFile = false; |
| 467 if (lockFileModified.isBefore(pubspecModified) || | 468 if (lockFileModified.isBefore(pubspecModified) || |
| 468 hasPathDependencies) { | 469 hasPathDependencies) { |
| 469 if (_isLockFileUpToDate() && _arePackagesAvailable()) { | 470 _assertLockFileUpToDate(); |
| 471 if (_arePackagesAvailable()) { |
| 470 touchedLockFile = true; | 472 touchedLockFile = true; |
| 471 touch(lockFilePath); | 473 touch(lockFilePath); |
| 472 } else { | 474 } else { |
| 473 dataError('The pubspec.yaml file has changed since the pubspec.lock ' | 475 dataError('The pubspec.yaml file has changed since the pubspec.lock ' |
| 474 'file was generated, please run "pub get" again.'); | 476 'file was generated, please run "pub get" again.'); |
| 475 } | 477 } |
| 476 } | 478 } |
| 477 | 479 |
| 478 var packagesModified = new File(packagesFile).lastModifiedSync(); | 480 var packagesModified = new File(packagesFile).lastModifiedSync(); |
| 479 if (packagesModified.isBefore(lockFileModified)) { | 481 if (packagesModified.isBefore(lockFileModified)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 493 if (!parsedConstraint.allows(sdk.version)) { | 495 if (!parsedConstraint.allows(sdk.version)) { |
| 494 dataError("Dart ${sdk.version} is incompatible with your dependencies' " | 496 dataError("Dart ${sdk.version} is incompatible with your dependencies' " |
| 495 "SDK constraints. Please run \"pub get\" again."); | 497 "SDK constraints. Please run \"pub get\" again."); |
| 496 } | 498 } |
| 497 } | 499 } |
| 498 } | 500 } |
| 499 | 501 |
| 500 /// Determines whether or not the lockfile is out of date with respect to the | 502 /// Determines whether or not the lockfile is out of date with respect to the |
| 501 /// pubspec. | 503 /// pubspec. |
| 502 /// | 504 /// |
| 503 /// This will be `false` if any mutable pubspec contains dependencies that are | 505 /// If any mutable pubspec contains dependencies that are not in the lockfile |
| 504 /// not in the lockfile or that don't match what's in there. | 506 /// or that don't match what's in there, this will throw a [DataError] |
| 505 bool _isLockFileUpToDate() { | 507 /// describing the issue. |
| 506 if (!root.immediateDependencies.every(_isDependencyUpToDate)) return false; | 508 void _assertLockFileUpToDate() { |
| 509 if (!root.immediateDependencies.every(_isDependencyUpToDate)) { |
| 510 dataError('The pubspec.yaml file has changed since the pubspec.lock ' |
| 511 'file was generated, please run "pub get" again.'); |
| 512 } |
| 507 | 513 |
| 508 var overrides = root.dependencyOverrides.map((dep) => dep.name).toSet(); | 514 var overrides = root.dependencyOverrides.map((dep) => dep.name).toSet(); |
| 509 | 515 |
| 510 // Check that uncached dependencies' pubspecs are also still satisfied, | 516 // Check that uncached dependencies' pubspecs are also still satisfied, |
| 511 // since they're mutable and may have changed since the last get. | 517 // since they're mutable and may have changed since the last get. |
| 512 return lockFile.packages.values.every((id) { | 518 for (var id in lockFile.packages.values) { |
| 513 var source = cache.sources[id.name]; | 519 var source = cache.sources[id.source]; |
| 514 if (source is! CachedSource) return true; | 520 if (source is CachedSource) continue; |
| 515 | 521 |
| 516 return cache.sources.load(id).dependencies.every((dep) => | 522 try { |
| 517 overrides.contains(dep.name) || _isDependencyUpToDate(dep)); | 523 if (cache.sources.load(id).dependencies.every((dep) => |
| 518 }); | 524 overrides.contains(dep.name) || _isDependencyUpToDate(dep))) { |
| 525 continue; |
| 526 } |
| 527 } on FileException { |
| 528 // If we can't load the pubpsec, the user needs to re-run "pub get". |
| 529 } |
| 530 |
| 531 dataError('${p.join(source.getDirectory(id), 'pubspec.yaml')} has ' |
| 532 'changed since the pubspec.lock file was generated, please run "pub ' |
| 533 'get" again.'); |
| 534 } |
| 519 } | 535 } |
| 520 | 536 |
| 521 /// Returns whether the locked version of [dep] matches the dependency. | 537 /// Returns whether the locked version of [dep] matches the dependency. |
| 522 bool _isDependencyUpToDate(PackageDep dep) { | 538 bool _isDependencyUpToDate(PackageDep dep) { |
| 523 var locked = lockFile.packages[dep.name]; | 539 var locked = lockFile.packages[dep.name]; |
| 524 if (locked == null) return false; | 540 if (locked == null) return false; |
| 525 | 541 |
| 526 if (dep.source != locked.source) return false; | 542 if (dep.source != locked.source) return false; |
| 527 | 543 |
| 528 if (!dep.constraint.allows(locked.version)) return false; | 544 if (!dep.constraint.allows(locked.version)) return false; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 /// If [packageSymlinks] is true, creates a symlink to the "packages" | 680 /// If [packageSymlinks] is true, creates a symlink to the "packages" |
| 665 /// directory in [dir]. | 681 /// directory in [dir]. |
| 666 /// | 682 /// |
| 667 /// Otherwise, deletes a "packages" directories in [dir] if one exists. | 683 /// Otherwise, deletes a "packages" directories in [dir] if one exists. |
| 668 void _linkOrDeleteSecondaryPackageDir(String dir) { | 684 void _linkOrDeleteSecondaryPackageDir(String dir) { |
| 669 var symlink = p.join(dir, 'packages'); | 685 var symlink = p.join(dir, 'packages'); |
| 670 if (entryExists(symlink)) deleteEntry(symlink); | 686 if (entryExists(symlink)) deleteEntry(symlink); |
| 671 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); | 687 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); |
| 672 } | 688 } |
| 673 } | 689 } |
| OLD | NEW |