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

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

Issue 11437019: Add logging system to pub and sprinkle some logging in. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: print() -> log.message(). 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
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 var pendingOrCompleted = _installs[id]; 75 var pendingOrCompleted = _installs[id];
75 if (pendingOrCompleted != null) return pendingOrCompleted; 76 if (pendingOrCompleted != null) return pendingOrCompleted;
76 77
77 var packageDir = join(path, id.name); 78 var packageDir = join(path, id.name);
78 var future = ensureDir(dirname(packageDir)).chain((_) { 79 var future = ensureDir(dirname(packageDir)).chain((_) {
79 return exists(packageDir); 80 return exists(packageDir);
80 }).chain((exists) { 81 }).chain((exists) {
81 if (!exists) return new Future.immediate(null); 82 if (!exists) return new Future.immediate(null);
82 // TODO(nweiz): figure out when to actually delete the directory, and when 83 // TODO(nweiz): figure out when to actually delete the directory, and when
83 // we can just re-use the existing symlink. 84 // we can just re-use the existing symlink.
85 log.fine("Deleting package directory $packageDir.");
nweiz 2012/12/05 23:56:54 Redundant with deleteDir.
Bob Nystrom 2012/12/06 01:33:26 Replaced path with package name in log. I still wa
84 return deleteDir(packageDir); 86 return deleteDir(packageDir);
85 }).chain((_) { 87 }).chain((_) {
86 if (id.source.shouldCache) { 88 if (id.source.shouldCache) {
87 return cache.install(id).chain( 89 return cache.install(id).chain(
88 (pkg) => createPackageSymlink(id.name, pkg.dir, packageDir)); 90 (pkg) => createPackageSymlink(id.name, pkg.dir, packageDir));
89 } else { 91 } else {
90 return id.source.install(id, packageDir).transform((found) { 92 return id.source.install(id, packageDir).transform((found) {
91 if (found) return null; 93 if (found) return null;
92 // TODO(nweiz): More robust error-handling. 94 // TODO(nweiz): More robust error-handling.
93 throw 'Package ${id.name} not found in source "${id.source.name}".'; 95 throw 'Package ${id.name} not found in source "${id.source.name}".';
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 /** 156 /**
155 * Loads the list of concrete package versions from the `pubspec.lock`, if it 157 * Loads the list of concrete package versions from the `pubspec.lock`, if it
156 * exists. If it doesn't, this completes to an empty [LockFile]. 158 * exists. If it doesn't, this completes to an empty [LockFile].
157 * 159 *
158 * If there's an error reading the `pubspec.lock` file, this will print a 160 * If there's an error reading the `pubspec.lock` file, this will print a
159 * warning message and act as though the file doesn't exist. 161 * warning message and act as though the file doesn't exist.
160 */ 162 */
161 Future<LockFile> _loadLockFile() { 163 Future<LockFile> _loadLockFile() {
162 var completer = new Completer<LockFile>(); 164 var completer = new Completer<LockFile>();
163 var lockFilePath = join(root.dir, 'pubspec.lock'); 165 var lockFilePath = join(root.dir, 'pubspec.lock');
166
167 log.fine("Loading lockfile $lockFilePath.");
nweiz 2012/12/05 23:56:54 "$lockFilePath" is redundant.
Bob Nystrom 2012/12/06 01:33:26 Done.
164 var future = readTextFile(lockFilePath); 168 var future = readTextFile(lockFilePath);
165 169
166 future.handleException((_) { 170 future.handleException((_) {
167 // If we failed to load the lockfile but it does exist, something's 171 // If we failed to load the lockfile but it does exist, something's
168 // probably wrong and we should notify the user. 172 // probably wrong and we should notify the user.
169 fileExists(lockFilePath).transform((exists) { 173 fileExists(lockFilePath).transform((exists) {
170 if (!exists) return; 174 if (!exists) return;
171 printError("Error reading pubspec.lock: ${future.exception}"); 175 log.error("Error reading pubspec.lock: ${future.exception}");
172 }).then((_) { 176 }).then((_) {
177 log.fine("No lock file at $lockFilePath, creating empty one.");
173 completer.complete(new LockFile.empty()); 178 completer.complete(new LockFile.empty());
174 }); 179 });
175 180
176 return true; 181 return true;
177 }); 182 });
178 183
179 future.then((text) => 184 future.then((text) =>
180 completer.complete(new LockFile.parse(text, cache.sources))); 185 completer.complete(new LockFile.parse(text, cache.sources)));
181 return completer.future; 186 return completer.future;
182 } 187 }
183 188
184 /** 189 /**
185 * Saves a list of concrete package versions to the `pubspec.lock` file. 190 * Saves a list of concrete package versions to the `pubspec.lock` file.
186 */ 191 */
187 Future _saveLockFile(List<PackageId> packageIds) { 192 Future _saveLockFile(List<PackageId> packageIds) {
188 var lockFile = new LockFile.empty(); 193 var lockFile = new LockFile.empty();
189 for (var id in packageIds) { 194 for (var id in packageIds) {
190 if (id.source is! RootSource) lockFile.packages[id.name] = id; 195 if (id.source is! RootSource) lockFile.packages[id.name] = id;
191 } 196 }
192 197
193 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); 198 var lockFilePath = join(root.dir, 'pubspec.lock');
199 log.fine("Saving lockfile $lockFilePath.");
nweiz 2012/12/05 23:56:54 "$lockFilePath" is redundant.
200 return writeTextFile(lockFilePath, lockFile.serialize());
194 } 201 }
195 202
196 /** 203 /**
197 * Installs a self-referential symlink in the `packages` directory that will 204 * Installs a self-referential symlink in the `packages` directory that will
198 * allow a package to import its own files using `package:`. 205 * allow a package to import its own files using `package:`.
199 */ 206 */
200 Future _installSelfReference(_) { 207 Future _installSelfReference(_) {
201 var linkPath = join(path, root.name); 208 var linkPath = join(path, root.name);
202 return exists(linkPath).chain((exists) { 209 return exists(linkPath).chain((exists) {
203 // Create the symlink if it doesn't exist. 210 // Create the symlink if it doesn't exist.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 * Creates a symlink to the `packages` directory in [dir] if none exists. 280 * Creates a symlink to the `packages` directory in [dir] if none exists.
274 */ 281 */
275 Future _linkSecondaryPackageDir(String dir) { 282 Future _linkSecondaryPackageDir(String dir) {
276 var to = join(dir, 'packages'); 283 var to = join(dir, 'packages');
277 return exists(to).chain((exists) { 284 return exists(to).chain((exists) {
278 if (exists) return new Future.immediate(null); 285 if (exists) return new Future.immediate(null);
279 return createSymlink(path, to); 286 return createSymlink(path, to);
280 }); 287 });
281 } 288 }
282 } 289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698