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

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

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. 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 | « utils/pub/command_uploader.dart ('k') | utils/pub/error_group.dart » ('j') | no next file with comments »
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
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 /// This will automatically install the package to the system-wide cache as 64 /// This will automatically install the package to the system-wide cache as
65 /// well if it requires network access to retrieve (specifically, if 65 /// well if it requires network access to retrieve (specifically, if
66 /// `id.source.shouldCache` is true). 66 /// `id.source.shouldCache` is true).
67 /// 67 ///
68 /// See also [installDependencies]. 68 /// See also [installDependencies].
69 Future<PackageId> install(PackageId id) { 69 Future<PackageId> install(PackageId id) {
70 var pendingOrCompleted = _installs[id]; 70 var pendingOrCompleted = _installs[id];
71 if (pendingOrCompleted != null) return pendingOrCompleted; 71 if (pendingOrCompleted != null) return pendingOrCompleted;
72 72
73 var packageDir = path.join(packagesDir, id.name); 73 var packageDir = path.join(packagesDir, id.name);
74 var future = new Future.of(() { 74 var future = new Future.sync(() {
75 ensureDir(path.dirname(packageDir)); 75 ensureDir(path.dirname(packageDir));
76 76
77 if (entryExists(packageDir)) { 77 if (entryExists(packageDir)) {
78 // TODO(nweiz): figure out when to actually delete the directory, and 78 // TODO(nweiz): figure out when to actually delete the directory, and
79 // when we can just re-use the existing symlink. 79 // when we can just re-use the existing symlink.
80 log.fine("Deleting package directory for ${id.name} before install."); 80 log.fine("Deleting package directory for ${id.name} before install.");
81 deleteEntry(packageDir); 81 deleteEntry(packageDir);
82 } 82 }
83 83
84 if (id.source.shouldCache) { 84 if (id.source.shouldCache) {
(...skipping 10 matching lines...) Expand all
95 95
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.of(() { 105 return new Future.sync(() {
106 return resolveVersions(cache.sources, root, loadLockFile()); 106 return resolveVersions(cache.sources, root, 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, new LockFile.empty())
115 .then(_installDependencies); 115 .then(_installDependencies);
116 } 116 }
117 117
118 /// Installs the latest available versions of [dependencies], while leaving 118 /// Installs the latest available versions of [dependencies], while leaving
119 /// other dependencies as specified by the [LockFile] if possible. Returns a 119 /// other dependencies as specified by the [LockFile] if possible. Returns a
120 /// [Future] that completes when all dependencies are installed. 120 /// [Future] that completes when all dependencies are installed.
121 Future updateDependencies(List<String> dependencies) { 121 Future updateDependencies(List<String> dependencies) {
122 return new Future.of(() { 122 return new Future.sync(() {
123 var solver = new VersionSolver(cache.sources, root, loadLockFile()); 123 var solver = new VersionSolver(cache.sources, root, loadLockFile());
124 for (var dependency in dependencies) { 124 for (var dependency in dependencies) {
125 solver.useLatestVersion(dependency); 125 solver.useLatestVersion(dependency);
126 } 126 }
127 return solver.solve(); 127 return solver.solve();
128 }).then(_installDependencies); 128 }).then(_installDependencies);
129 } 129 }
130 130
131 /// Removes the old packages directory, installs all dependencies listed in 131 /// Removes the old packages directory, installs all dependencies listed in
132 /// [packageVersions], and writes a [LockFile]. 132 /// [packageVersions], and writes a [LockFile].
133 Future _installDependencies(List<PackageId> packageVersions) { 133 Future _installDependencies(List<PackageId> packageVersions) {
134 return new Future.of(() { 134 return new Future.sync(() {
135 cleanDir(packagesDir); 135 cleanDir(packagesDir);
136 return Future.wait(packageVersions.map((id) { 136 return Future.wait(packageVersions.map((id) {
137 if (id.isRoot) return new Future.immediate(id); 137 if (id.isRoot) return new Future.value(id);
138 return install(id); 138 return install(id);
139 }).toList()); 139 }).toList());
140 }).then((ids) { 140 }).then((ids) {
141 _saveLockFile(ids); 141 _saveLockFile(ids);
142 _installSelfReference(); 142 _installSelfReference();
143 _linkSecondaryPackageDirs(); 143 _linkSecondaryPackageDirs();
144 }); 144 });
145 } 145 }
146 146
147 /// Traverses the root's package dependency graph and loads each of the 147 /// Traverses the root's package dependency graph and loads each of the
148 /// reached packages. This should only be called after the lockfile has been 148 /// reached packages. This should only be called after the lockfile has been
149 /// successfully generated. 149 /// successfully generated.
150 Future<List<Pubspec>> walkDependencies() { 150 Future<List<Pubspec>> walkDependencies() {
151 return new Future.of(() { 151 return new Future.sync(() {
152 var lockFile = loadLockFile(); 152 var lockFile = loadLockFile();
153 var group = new FutureGroup<Pubspec>(); 153 var group = new FutureGroup<Pubspec>();
154 var visited = new Set<String>(); 154 var visited = new Set<String>();
155 155
156 // Include the root package in the results. 156 // Include the root package in the results.
157 group.add(new Future.immediate(root.pubspec)); 157 group.add(new Future.value(root.pubspec));
158 158
159 visitPackage(Pubspec pubspec) { 159 visitPackage(Pubspec pubspec) {
160 for (var ref in pubspec.dependencies) { 160 for (var ref in pubspec.dependencies) {
161 if (visited.contains(ref.name)) continue; 161 if (visited.contains(ref.name)) continue;
162 162
163 // Look up the concrete version. 163 // Look up the concrete version.
164 var id = lockFile.packages[ref.name]; 164 var id = lockFile.packages[ref.name];
165 165
166 visited.add(ref.name); 166 visited.add(ref.name);
167 var future; 167 var future;
168 if (ref.name == root.name) { 168 if (ref.name == root.name) {
169 future = new Future<Pubspec>.immediate(root.pubspec); 169 future = new Future<Pubspec>.value(root.pubspec);
170 } else { 170 } else {
171 future = cache.describe(id); 171 future = cache.describe(id);
172 } 172 }
173 group.add(future.then(visitPackage)); 173 group.add(future.then(visitPackage));
174 } 174 }
175 175
176 return pubspec; 176 return pubspec;
177 } 177 }
178 178
179 visited.add(root.name); 179 visited.add(root.name);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 278 }
279 279
280 /// Creates a symlink to the `packages` directory in [dir]. Will replace one 280 /// Creates a symlink to the `packages` directory in [dir]. Will replace one
281 /// if already there. 281 /// if already there.
282 void _linkSecondaryPackageDir(String dir) { 282 void _linkSecondaryPackageDir(String dir) {
283 var symlink = path.join(dir, 'packages'); 283 var symlink = path.join(dir, 'packages');
284 if (entryExists(symlink)) deleteEntry(symlink); 284 if (entryExists(symlink)) deleteEntry(symlink);
285 createSymlink(packagesDir, symlink, relative: true); 285 createSymlink(packagesDir, symlink, relative: true);
286 } 286 }
287 } 287 }
OLDNEW
« no previous file with comments | « utils/pub/command_uploader.dart ('k') | utils/pub/error_group.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698