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

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

Issue 13332009: Make listDir and createSymlink synchronous in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.of(() {
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.immediate(id);
138 return install(id); 138 return install(id);
139 }).toList()); 139 }).toList());
140 }).then(_saveLockFile) 140 }).then((ids) {
141 .then(_installSelfReference) 141 _saveLockFile(ids);
142 .then(_linkSecondaryPackageDirs); 142 _installSelfReference();
143 _linkSecondaryPackageDirs();
144 });
143 } 145 }
144 146
145 /// 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
146 /// 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
147 /// successfully generated. 149 /// successfully generated.
148 Future<List<Pubspec>> walkDependencies() { 150 Future<List<Pubspec>> walkDependencies() {
149 return defer(() { 151 return defer(() {
150 var lockFile = loadLockFile(); 152 var lockFile = loadLockFile();
151 var group = new FutureGroup<Pubspec>(); 153 var group = new FutureGroup<Pubspec>();
152 var visited = new Set<String>(); 154 var visited = new Set<String>();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 for (var id in packageIds) { 222 for (var id in packageIds) {
221 if (!id.isRoot) lockFile.packages[id.name] = id; 223 if (!id.isRoot) lockFile.packages[id.name] = id;
222 } 224 }
223 225
224 var lockFilePath = path.join(root.dir, 'pubspec.lock'); 226 var lockFilePath = path.join(root.dir, 'pubspec.lock');
225 writeTextFile(lockFilePath, lockFile.serialize()); 227 writeTextFile(lockFilePath, lockFile.serialize());
226 } 228 }
227 229
228 /// Installs a self-referential symlink in the `packages` directory that will 230 /// Installs a self-referential symlink in the `packages` directory that will
229 /// allow a package to import its own files using `package:`. 231 /// allow a package to import its own files using `package:`.
230 Future _installSelfReference(_) { 232 void _installSelfReference() {
231 return defer(() { 233 var linkPath = path.join(packagesDir, root.name);
232 var linkPath = path.join(packagesDir, root.name); 234 // Create the symlink if it doesn't exist.
233 // Create the symlink if it doesn't exist. 235 if (entryExists(linkPath)) return;
234 if (entryExists(linkPath)) return; 236 ensureDir(packagesDir);
235 ensureDir(packagesDir); 237 createPackageSymlink(root.name, root.dir, linkPath,
236 return createPackageSymlink(root.name, root.dir, linkPath, 238 isSelfLink: true, relative: true);
237 isSelfLink: true, relative: true);
238 });
239 } 239 }
240 240
241 /// If `bin/`, `test/`, or `example/` directories exist, symlink `packages/` 241 /// If `bin/`, `test/`, or `example/` directories exist, symlink `packages/`
242 /// into them so that their entrypoints can be run. Do the same for any 242 /// into them so that their entrypoints can be run. Do the same for any
243 /// subdirectories of `test/` and `example/`. 243 /// subdirectories of `test/` and `example/`.
244 Future _linkSecondaryPackageDirs(_) { 244 void _linkSecondaryPackageDirs() {
245 var binDir = path.join(root.dir, 'bin'); 245 var binDir = path.join(root.dir, 'bin');
246 var exampleDir = path.join(root.dir, 'example'); 246 var exampleDir = path.join(root.dir, 'example');
247 var testDir = path.join(root.dir, 'test'); 247 var testDir = path.join(root.dir, 'test');
248 var toolDir = path.join(root.dir, 'tool'); 248 var toolDir = path.join(root.dir, 'tool');
249 var webDir = path.join(root.dir, 'web'); 249 var webDir = path.join(root.dir, 'web');
250 return defer(() { 250
251 if (!dirExists(binDir)) return; 251 if (dirExists(binDir)) _linkSecondaryPackageDir(binDir);
Bob Nystrom 2013/03/29 21:22:06 We can actually use a loop here now: for (var nam
nweiz 2013/03/29 22:09:02 Done.
252 return _linkSecondaryPackageDir(binDir); 252 _linkSecondaryPackageDirsRecursively(exampleDir);
253 }).then((_) => _linkSecondaryPackageDirsRecursively(exampleDir)) 253 _linkSecondaryPackageDirsRecursively(testDir);
254 .then((_) => _linkSecondaryPackageDirsRecursively(testDir)) 254 _linkSecondaryPackageDirsRecursively(toolDir);
255 .then((_) => _linkSecondaryPackageDirsRecursively(toolDir)) 255 _linkSecondaryPackageDirsRecursively(webDir);
256 .then((_) => _linkSecondaryPackageDirsRecursively(webDir));
257 } 256 }
258 257
259 /// Creates a symlink to the `packages` directory in [dir] and all its 258 /// Creates a symlink to the `packages` directory in [dir] and all its
260 /// subdirectories. 259 /// subdirectories.
261 Future _linkSecondaryPackageDirsRecursively(String dir) { 260 void _linkSecondaryPackageDirsRecursively(String dir) {
262 return defer(() { 261 print("linking $dir recursively");
Bob Nystrom 2013/03/29 21:22:06 Debug code.
nweiz 2013/03/29 22:09:02 Done.
263 if (!dirExists(dir)) return; 262 if (!dirExists(dir)) return;
264 return _linkSecondaryPackageDir(dir) 263 _linkSecondaryPackageDir(dir);
265 .then((_) => _listDirWithoutPackages(dir)) 264 _listDirWithoutPackages(dir)
266 .then((files) { 265 .where(dirExists)
267 return Future.wait(files.map((file) { 266 .forEach(_linkSecondaryPackageDir);
268 return defer(() {
269 if (!dirExists(file)) return;
270 return _linkSecondaryPackageDir(file);
271 });
272 }).toList());
273 });
274 });
275 } 267 }
276 268
277 // TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed. 269 // TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed.
278 /// Recursively lists the contents of [dir], excluding hidden `.DS_Store` 270 /// Recursively lists the contents of [dir], excluding hidden `.DS_Store`
279 /// files and `package` files. 271 /// files and `package` files.
280 Future<List<String>> _listDirWithoutPackages(dir) { 272 List<String> _listDirWithoutPackages(dir) {
281 return listDir(dir).then((files) { 273 return flatten(listDir(dir).map((file) {
282 return Future.wait(files.map((file) { 274 if (path.basename(file) == 'packages') return [];
283 if (path.basename(file) == 'packages') return new Future.immediate([]); 275 if (!dirExists(file)) return [];
284 return defer(() { 276 var fileAndSubfiles = [file];
285 if (!dirExists(file)) return []; 277 fileAndSubfiles.addAll(_listDirWithoutPackages(file));
286 return _listDirWithoutPackages(file); 278 return fileAndSubfiles;
287 }).then((subfiles) { 279 }));
288 var fileAndSubfiles = [file];
289 fileAndSubfiles.addAll(subfiles);
290 return fileAndSubfiles;
291 });
292 }).toList());
293 }).then(flatten);
294 } 280 }
295 281
296 /// Creates a symlink to the `packages` directory in [dir]. Will replace one 282 /// Creates a symlink to the `packages` directory in [dir]. Will replace one
297 /// if already there. 283 /// if already there.
298 Future _linkSecondaryPackageDir(String dir) { 284 void _linkSecondaryPackageDir(String dir) {
299 return defer(() { 285 print("linking $dir");
Bob Nystrom 2013/03/29 21:22:06 Debug.
nweiz 2013/03/29 22:09:02 Done.
300 var symlink = path.join(dir, 'packages'); 286 var symlink = path.join(dir, 'packages');
301 if (entryExists(symlink)) deleteEntry(symlink); 287 if (entryExists(symlink)) deleteEntry(symlink);
302 return createSymlink(packagesDir, symlink, relative: true); 288 createSymlink(packagesDir, symlink, relative: true);
303 });
304 } 289 }
305 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698