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

Unified Diff: lib/src/solver/backtracking_solver.dart

Issue 1459733002: Move pubspec caching into each source. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/command/cache_add.dart ('k') | lib/src/solver/version_solver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/solver/backtracking_solver.dart
diff --git a/lib/src/solver/backtracking_solver.dart b/lib/src/solver/backtracking_solver.dart
index da0dbec45e753b96f45bd675c69a78a2d08f46df..6b831ee5bbdf8ae61b543d2999a09c9502448f69 100644
--- a/lib/src/solver/backtracking_solver.dart
+++ b/lib/src/solver/backtracking_solver.dart
@@ -66,7 +66,8 @@ class BacktrackingSolver {
/// The lockfile that was present before solving.
final LockFile lockFile;
- final PubspecCache cache;
+ /// A cache of data requested during solving.
+ final SolverCache cache;
/// The set of packages that are being explicitly upgraded.
///
@@ -117,11 +118,21 @@ class BacktrackingSolver {
/// The number of solutions the solver has tried so far.
var _attemptedSolutions = 1;
+ /// A pubspec for pub's implicit dependencies on barback and related packages.
+ final Pubspec _implicitPubspec = () {
+ var dependencies = [];
+ barback.pubConstraints.forEach((name, constraint) {
+ dependencies.add(new PackageDep(name, "hosted", constraint, name));
+ });
+
+ return new Pubspec("pub itself", dependencies: dependencies);
+ }();
+
BacktrackingSolver(SolveType type, SourceRegistry sources, this.root,
this.lockFile, List<String> useLatest)
: type = type,
sources = sources,
- cache = new PubspecCache(type, sources) {
+ cache = new SolverCache(type, sources) {
_selection = new VersionSelection(this);
for (var package in useLatest) {
@@ -151,8 +162,6 @@ class BacktrackingSolver {
// Pre-cache the root package's known pubspec.
var rootID = new PackageId.root(root);
- cache.cache(rootID, root.pubspec);
- cache.cache(new PackageId.magic('pub itself'), _implicitPubspec());
await _selection.select(rootID);
_validateSdkConstraint(root.pubspec);
@@ -160,9 +169,10 @@ class BacktrackingSolver {
logSolve();
var packages = await _solve();
- var pubspecs = new Map.fromIterable(packages,
- key: (id) => id.name,
- value: (id) => cache.getCachedPubspec(id));
+ var pubspecs = {};
+ for (var id in packages) {
+ pubspecs[id.name] = await _getPubspec(id);
+ }
var resolved = await Future.wait(
packages.map((id) => sources[id.source].resolveId(id)));
@@ -183,17 +193,6 @@ class BacktrackingSolver {
}
}
- /// Creates a pubspec for pub's implicit dependencies on barback and related
- /// packages.
- Pubspec _implicitPubspec() {
- var dependencies = [];
- barback.pubConstraints.forEach((name, constraint) {
- dependencies.add(new PackageDep(name, "hosted", constraint, name));
- });
-
- return new Pubspec("pub itself", dependencies: dependencies);
- }
-
/// Generates a map containing all of the known available versions for each
/// package in [packages].
///
@@ -476,7 +475,7 @@ class BacktrackingSolver {
var pubspec;
try {
- pubspec = await cache.getPubspec(id);
+ pubspec = await _getPubspec(id);
} on PackageNotFoundException {
// We can only get here if the lockfile refers to a specific package
// version that doesn't exist (probably because it was yanked).
@@ -569,7 +568,7 @@ class BacktrackingSolver {
///
/// This takes overrides and dev dependencies into account when neccessary.
Future<Set<PackageDep>> depsFor(PackageId id) async {
- var pubspec = await cache.getPubspec(id);
+ var pubspec = await _getPubspec(id);
var deps = pubspec.dependencies.toSet();
if (id.isRoot) {
// Include dev dependencies of the root package.
@@ -606,6 +605,15 @@ class BacktrackingSolver {
return deps;
}
+ /// Loads and returns the pubspec for [id].
+ Future<Pubspec> _getPubspec(PackageId id) async {
+ if (id.isRoot) return root.pubspec;
+ if (id.isMagic && id.name == 'pub itself') return _implicitPubspec;
+
+ var source = sources[id.source];
+ return await source.describe(id);
+ }
+
/// Logs the initial parameters to the solver.
void _logParameters() {
var buffer = new StringBuffer();
« no previous file with comments | « lib/src/command/cache_add.dart ('k') | lib/src/solver/version_solver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698