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

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

Issue 11470031: Finish integrating logging. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years 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/curl_client.dart ('k') | utils/pub/io.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 'io.dart'; 7 import 'io.dart';
8 import 'lock_file.dart'; 8 import 'lock_file.dart';
9 import 'log.dart' as log;
9 import 'package.dart'; 10 import 'package.dart';
10 import 'root_source.dart'; 11 import 'root_source.dart';
11 import 'system_cache.dart'; 12 import 'system_cache.dart';
12 import 'version.dart'; 13 import 'version.dart';
13 import 'version_solver.dart'; 14 import 'version_solver.dart';
14 import 'utils.dart'; 15 import 'utils.dart';
15 16
16 /** 17 /**
17 * Pub operates over a directed graph of dependencies that starts at a root 18 * Pub operates over a directed graph of dependencies that starts at a root
18 * "entrypoint" package. This is typically the package where the current 19 * "entrypoint" package. This is typically the package where the current
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 var pendingOrCompleted = _installs[id]; 81 var pendingOrCompleted = _installs[id];
81 if (pendingOrCompleted != null) return pendingOrCompleted; 82 if (pendingOrCompleted != null) return pendingOrCompleted;
82 83
83 var packageDir = join(path, id.name); 84 var packageDir = join(path, id.name);
84 var future = ensureDir(dirname(packageDir)).chain((_) { 85 var future = ensureDir(dirname(packageDir)).chain((_) {
85 return exists(packageDir); 86 return exists(packageDir);
86 }).chain((exists) { 87 }).chain((exists) {
87 if (!exists) return new Future.immediate(null); 88 if (!exists) return new Future.immediate(null);
88 // TODO(nweiz): figure out when to actually delete the directory, and when 89 // TODO(nweiz): figure out when to actually delete the directory, and when
89 // we can just re-use the existing symlink. 90 // we can just re-use the existing symlink.
91 log.fine("Deleting package directory for ${id.name} before install.");
90 return deleteDir(packageDir); 92 return deleteDir(packageDir);
91 }).chain((_) { 93 }).chain((_) {
92 if (id.source.shouldCache) { 94 if (id.source.shouldCache) {
93 return cache.install(id).chain( 95 return cache.install(id).chain(
94 (pkg) => createPackageSymlink(id.name, pkg.dir, packageDir)); 96 (pkg) => createPackageSymlink(id.name, pkg.dir, packageDir));
95 } else { 97 } else {
96 return id.source.install(id, packageDir).transform((found) { 98 return id.source.install(id, packageDir).transform((found) {
97 if (found) return null; 99 if (found) return null;
98 // TODO(nweiz): More robust error-handling. 100 // TODO(nweiz): More robust error-handling.
99 throw 'Package ${id.name} not found in source "${id.source.name}".'; 101 throw 'Package ${id.name} not found in source "${id.source.name}".';
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 /** 162 /**
161 * Loads the list of concrete package versions from the `pubspec.lock`, if it 163 * Loads the list of concrete package versions from the `pubspec.lock`, if it
162 * exists. If it doesn't, this completes to an empty [LockFile]. 164 * exists. If it doesn't, this completes to an empty [LockFile].
163 * 165 *
164 * If there's an error reading the `pubspec.lock` file, this will print a 166 * If there's an error reading the `pubspec.lock` file, this will print a
165 * warning message and act as though the file doesn't exist. 167 * warning message and act as though the file doesn't exist.
166 */ 168 */
167 Future<LockFile> _loadLockFile() { 169 Future<LockFile> _loadLockFile() {
168 var completer = new Completer<LockFile>(); 170 var completer = new Completer<LockFile>();
169 var lockFilePath = join(root.dir, 'pubspec.lock'); 171 var lockFilePath = join(root.dir, 'pubspec.lock');
172
173 log.fine("Loading lockfile.");
170 var future = readTextFile(lockFilePath); 174 var future = readTextFile(lockFilePath);
171 175
172 future.handleException((_) { 176 future.handleException((_) {
173 // If we failed to load the lockfile but it does exist, something's 177 // If we failed to load the lockfile but it does exist, something's
174 // probably wrong and we should notify the user. 178 // probably wrong and we should notify the user.
175 fileExists(lockFilePath).transform((exists) { 179 fileExists(lockFilePath).transform((exists) {
176 if (!exists) return; 180 if (!exists) return;
177 printError("Error reading pubspec.lock: ${future.exception}"); 181 log.error("Error reading pubspec.lock: ${future.exception}");
178 }).then((_) { 182 }).then((_) {
183 log.fine("No lock file at $lockFilePath, creating empty one.");
179 completer.complete(new LockFile.empty()); 184 completer.complete(new LockFile.empty());
180 }); 185 });
181 186
182 return true; 187 return true;
183 }); 188 });
184 189
185 future.then((text) => 190 future.then((text) =>
186 completer.complete(new LockFile.parse(text, cache.sources))); 191 completer.complete(new LockFile.parse(text, cache.sources)));
187 return completer.future; 192 return completer.future;
188 } 193 }
189 194
190 /** 195 /**
191 * Saves a list of concrete package versions to the `pubspec.lock` file. 196 * Saves a list of concrete package versions to the `pubspec.lock` file.
192 */ 197 */
193 Future _saveLockFile(List<PackageId> packageIds) { 198 Future _saveLockFile(List<PackageId> packageIds) {
194 var lockFile = new LockFile.empty(); 199 var lockFile = new LockFile.empty();
195 for (var id in packageIds) { 200 for (var id in packageIds) {
196 if (id.source is! RootSource) lockFile.packages[id.name] = id; 201 if (id.source is! RootSource) lockFile.packages[id.name] = id;
197 } 202 }
198 203
199 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); 204 var lockFilePath = join(root.dir, 'pubspec.lock');
205 log.fine("Saving lockfile.");
206 return writeTextFile(lockFilePath, lockFile.serialize());
200 } 207 }
201 208
202 /** 209 /**
203 * Installs a self-referential symlink in the `packages` directory that will 210 * Installs a self-referential symlink in the `packages` directory that will
204 * allow a package to import its own files using `package:`. 211 * allow a package to import its own files using `package:`.
205 */ 212 */
206 Future _installSelfReference(_) { 213 Future _installSelfReference(_) {
207 var linkPath = join(path, root.name); 214 var linkPath = join(path, root.name);
208 return exists(linkPath).chain((exists) { 215 return exists(linkPath).chain((exists) {
209 // Create the symlink if it doesn't exist. 216 // Create the symlink if it doesn't exist.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 * Creates a symlink to the `packages` directory in [dir] if none exists. 286 * Creates a symlink to the `packages` directory in [dir] if none exists.
280 */ 287 */
281 Future _linkSecondaryPackageDir(String dir) { 288 Future _linkSecondaryPackageDir(String dir) {
282 var to = join(dir, 'packages'); 289 var to = join(dir, 'packages');
283 return exists(to).chain((exists) { 290 return exists(to).chain((exists) {
284 if (exists) return new Future.immediate(null); 291 if (exists) return new Future.immediate(null);
285 return createSymlink(path, to); 292 return createSymlink(path, to);
286 }); 293 });
287 } 294 }
288 } 295 }
OLDNEW
« no previous file with comments | « utils/pub/curl_client.dart ('k') | utils/pub/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698