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

Unified Diff: sdk/lib/_internal/pub/lib/src/solver/version_solver.dart

Issue 15347004: Gracefully handle pubspecs with dependencies using unknown sources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests for unknown sources in lockfiles. Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/pub/lib/src/solver/version_solver.dart
diff --git a/sdk/lib/_internal/pub/lib/src/solver/version_solver.dart b/sdk/lib/_internal/pub/lib/src/solver/version_solver.dart
index 885acdc55659b5529140d2cdece9e102d6219af5..1ae8d3e33a78b563b582516d39a8e81d8b8c1346 100644
--- a/sdk/lib/_internal/pub/lib/src/solver/version_solver.dart
+++ b/sdk/lib/_internal/pub/lib/src/solver/version_solver.dart
@@ -14,6 +14,7 @@ import '../pubspec.dart';
import '../source.dart';
import '../source_registry.dart';
import '../version.dart';
+import '../utils.dart';
import 'backtracking_solver.dart';
/// Attempts to select the best concrete versions for all of the transitive
@@ -70,7 +71,11 @@ class SolveResult {
/// Used to avoid requesting the same pubspec from the server repeatedly.
class PubspecCache {
final SourceRegistry _sources;
+
+ /// The already-requested cached version lists.
final _versions = new Map<PackageRef, List<PackageId>>();
+
+ /// The already-requested cached pubspecs.
final _pubspecs = new Map<PackageId, Pubspec>();
/// The number of times a version list was requested and it wasn't cached and
@@ -105,10 +110,9 @@ class PubspecCache {
}
pubspecCacheMisses++;
- return id.describe().then((pubspec) {
- log.solver('requested $id pubspec');
- // Cache it.
+ var source = _sources[id.source];
+ return source.describe(id).then((pubspec) {
_pubspecs[id] = pubspec;
return pubspec;
});
@@ -120,6 +124,10 @@ class PubspecCache {
/// Gets the list of versions for [package] in descending order.
Future<List<PackageId>> getVersions(PackageRef package) {
+ if (package.isRoot) {
+ throw new StateError("Cannot get versions for root package $package.");
+ }
+
// See if we have it cached.
var versions = _versions[package];
if (versions != null) {
@@ -128,11 +136,14 @@ class PubspecCache {
}
versionCacheMisses++;
- return package.getVersions().then((ids) {
+
+ var source = _sources[package.source];
+ return source.getVersions(package.name, package.description)
+ .then((versions) {
// Sort by descending version so we try newer versions first.
- ids.sort((a, b) => b.version.compareTo(a.version));
+ versions.sort((a, b) => b.compareTo(a));
- log.solver('requested $package version list');
+ var ids = versions.map((version) => package.atVersion(version)).toList();
_versions[package] = ids;
return ids;
});
@@ -153,7 +164,7 @@ class Dependency {
}
/// Base class for all failures that can occur while trying to resolve versions.
-class SolveFailure implements Exception {
+abstract class SolveFailure implements ApplicationException {
/// The name of the package whose version could not be solved. Will be `null`
/// if the failure is not specific to one package.
final String package;
@@ -270,7 +281,6 @@ class DisjointConstraintException extends SolveFailure {
/// Exception thrown when two packages with the same name but different sources
/// are depended upon.
class SourceMismatchException extends SolveFailure {
-
SourceMismatchException(String package, Iterable<Dependency> dependencies)
: super(package, dependencies);
@@ -280,6 +290,18 @@ class SourceMismatchException extends SolveFailure {
"depends on it from source ${dep.source}";
}
+/// Exception thrown when a dependency on an unknown source name is found.
+class UnknownSourceException extends SolveFailure {
+ UnknownSourceException(String package, Iterable<Dependency> dependencies)
+ : super(package, dependencies);
+
+ String toString() {
+ var dep = only(dependencies);
+ return "Package '${dep.depender}' depends on '${dep.dep.name}' from "
+ "unknown source '${dep.dep.source}'.";
+ }
+}
+
/// Exception thrown when two packages with the same name and source but
/// different descriptions are depended upon.
class DescriptionMismatchException extends SolveFailure {
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/solver/backtracking_solver.dart ('k') | sdk/lib/_internal/pub/lib/src/source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698