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

Side by Side Diff: utils/pub/entrypoint.dart

Issue 13095015: Use backtracking when solving dependency constraints. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise, update to latest corelib, and make backtracker default. Created 7 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/pub/log.dart » ('j') | utils/pub/solver/backtracking_solver.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 entrypoint; 5 library entrypoint;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:pathos/path.dart' as path; 9 import 'package:pathos/path.dart' as path;
10 10
11 import 'io.dart'; 11 import 'io.dart';
12 import 'lock_file.dart'; 12 import 'lock_file.dart';
13 import 'log.dart' as log; 13 import 'log.dart' as log;
14 import 'package.dart'; 14 import 'package.dart';
15 import 'pubspec.dart'; 15 import 'pubspec.dart';
16 import 'sdk.dart' as sdk; 16 import 'sdk.dart' as sdk;
17 import 'system_cache.dart'; 17 import 'system_cache.dart';
18 import 'utils.dart'; 18 import 'utils.dart';
19 import 'version.dart'; 19 import 'version.dart';
20 import 'version_solver.dart'; 20 import 'solver/version_solver.dart';
21 21
22 /// Pub operates over a directed graph of dependencies that starts at a root 22 /// Pub operates over a directed graph of dependencies that starts at a root
23 /// "entrypoint" package. This is typically the package where the current 23 /// "entrypoint" package. This is typically the package where the current
24 /// working directory is located. An entrypoint knows the [root] package it is 24 /// working directory is located. An entrypoint knows the [root] package it is
25 /// associated with and is responsible for managing the "packages" directory 25 /// associated with and is responsible for managing the "packages" directory
26 /// for it. 26 /// for it.
27 /// 27 ///
28 /// That directory contains symlinks to all packages used by an app. These links 28 /// That directory contains symlinks to all packages used by an app. These links
29 /// point either to the [SystemCache] or to some other location on the local 29 /// point either to the [SystemCache] or to some other location on the local
30 /// filesystem. 30 /// filesystem.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 _installs[id] = future; 96 _installs[id] = future;
97 97
98 return future; 98 return future;
99 } 99 }
100 100
101 /// Installs all dependencies of the [root] package to its "packages" 101 /// Installs all dependencies of the [root] package to its "packages"
102 /// directory, respecting the [LockFile] if present. Returns a [Future] that 102 /// directory, respecting the [LockFile] if present. Returns a [Future] that
103 /// completes when all dependencies are installed. 103 /// completes when all dependencies are installed.
104 Future installDependencies() { 104 Future installDependencies() {
105 return new Future.sync(() { 105 return new Future.sync(() {
106 return resolveVersions(cache.sources, root, loadLockFile()); 106 return resolveVersions(cache.sources, root, lockFile: loadLockFile());
107 }).then(_installDependencies); 107 }).then(_installDependencies);
108 } 108 }
109 109
110 /// Installs the latest available versions of all dependencies of the [root] 110 /// Installs the latest available versions of all dependencies of the [root]
111 /// package to its "package" directory, writing a new [LockFile]. Returns a 111 /// package to its "package" directory, writing a new [LockFile]. Returns a
112 /// [Future] that completes when all dependencies are installed. 112 /// [Future] that completes when all dependencies are installed.
113 Future updateAllDependencies() { 113 Future updateAllDependencies() {
114 return resolveVersions(cache.sources, root, new LockFile.empty()) 114 return resolveVersions(cache.sources, root).then(_installDependencies);
115 .then(_installDependencies);
116 } 115 }
117 116
118 /// Installs the latest available versions of [dependencies], while leaving 117 /// Installs the latest available versions of [dependencies], while leaving
119 /// other dependencies as specified by the [LockFile] if possible. Returns a 118 /// other dependencies as specified by the [LockFile] if possible. Returns a
120 /// [Future] that completes when all dependencies are installed. 119 /// [Future] that completes when all dependencies are installed.
121 Future updateDependencies(List<String> dependencies) { 120 Future updateDependencies(List<String> dependencies) {
122 return new Future.sync(() { 121 return new Future.sync(() {
123 var solver = new VersionSolver(cache.sources, root, loadLockFile()); 122 return resolveVersions(cache.sources, root,
124 for (var dependency in dependencies) { 123 lockFile: loadLockFile(), useLatest: dependencies);
125 solver.useLatestVersion(dependency);
126 }
127 return solver.solve();
128 }).then(_installDependencies); 124 }).then(_installDependencies);
129 } 125 }
130 126
131 /// Removes the old packages directory, installs all dependencies listed in 127 /// Removes the old packages directory, installs all dependencies listed in
132 /// [packageVersions], and writes a [LockFile]. 128 /// [result], and writes a [LockFile].
133 Future _installDependencies(List<PackageId> packageVersions) { 129 Future _installDependencies(SolveResult result) {
134 return new Future.sync(() { 130 return new Future.sync(() {
131 if (!result.succeeded) throw result.error;
132
135 cleanDir(packagesDir); 133 cleanDir(packagesDir);
136 return Future.wait(packageVersions.map((id) { 134 return Future.wait(result.packages.map((id) {
137 if (id.isRoot) return new Future.value(id); 135 if (id.isRoot) return new Future.value(id);
138 return install(id); 136 return install(id);
139 }).toList()); 137 }).toList());
140 }).then((ids) { 138 }).then((ids) {
141 _saveLockFile(ids); 139 _saveLockFile(ids);
142 _installSelfReference(); 140 _installSelfReference();
143 _linkSecondaryPackageDirs(); 141 _linkSecondaryPackageDirs();
144 }); 142 });
145 } 143 }
146 144
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 276 }
279 277
280 /// Creates a symlink to the `packages` directory in [dir]. Will replace one 278 /// Creates a symlink to the `packages` directory in [dir]. Will replace one
281 /// if already there. 279 /// if already there.
282 void _linkSecondaryPackageDir(String dir) { 280 void _linkSecondaryPackageDir(String dir) {
283 var symlink = path.join(dir, 'packages'); 281 var symlink = path.join(dir, 'packages');
284 if (entryExists(symlink)) deleteEntry(symlink); 282 if (entryExists(symlink)) deleteEntry(symlink);
285 createSymlink(packagesDir, symlink, relative: true); 283 createSymlink(packagesDir, symlink, relative: true);
286 } 284 }
287 } 285 }
OLDNEW
« no previous file with comments | « no previous file | utils/pub/log.dart » ('j') | utils/pub/solver/backtracking_solver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698