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

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

Issue 12253054: Get rid of join() and encapsulate File and Directory in io.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 7 years, 10 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_lish.dart ('k') | utils/pub/git_source.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 '../../pkg/path/lib/path.dart' as path; 9 import '../../pkg/path/lib/path.dart' as path;
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 /// directory, or have already been installed. 46 /// directory, or have already been installed.
47 final _installs = new Map<PackageId, Future<PackageId>>(); 47 final _installs = new Map<PackageId, Future<PackageId>>();
48 48
49 /// Loads the entrypoint from a package at [rootDir]. 49 /// Loads the entrypoint from a package at [rootDir].
50 Entrypoint(String rootDir, SystemCache cache) 50 Entrypoint(String rootDir, SystemCache cache)
51 : root = new Package.load(null, rootDir, cache.sources), 51 : root = new Package.load(null, rootDir, cache.sources),
52 cache = cache; 52 cache = cache;
53 53
54 // TODO(rnystrom): Make this path configurable. 54 // TODO(rnystrom): Make this path configurable.
55 /// The path to the entrypoint's "packages" directory. 55 /// The path to the entrypoint's "packages" directory.
56 String get packagesDir => join(root.dir, 'packages'); 56 String get packagesDir => path.join(root.dir, 'packages');
57 57
58 /// Ensures that the package identified by [id] is installed to the directory. 58 /// Ensures that the package identified by [id] is installed to the directory.
59 /// Returns the resolved [PackageId]. 59 /// Returns the resolved [PackageId].
60 /// 60 ///
61 /// If this completes successfully, the package is guaranteed to be importable 61 /// If this completes successfully, the package is guaranteed to be importable
62 /// using the `package:` scheme. 62 /// using the `package:` scheme.
63 /// 63 ///
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 = join(packagesDir, id.name); 73 var packageDir = path.join(packagesDir, id.name);
74 var future = defer(() { 74 var future = defer(() {
75 ensureDir(path.dirname(packageDir)); 75 ensureDir(path.dirname(packageDir));
76 if (!dirExists(packageDir)) return; 76 if (!dirExists(packageDir)) return;
77 77
78 // TODO(nweiz): figure out when to actually delete the directory, and when 78 // TODO(nweiz): figure out when to actually delete the directory, and when
79 // we can just re-use the existing symlink. 79 // 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 return deleteDir(packageDir); 81 return deleteDir(packageDir);
82 }).then((_) { 82 }).then((_) {
83 if (id.source.shouldCache) { 83 if (id.source.shouldCache) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 "SDK\n" 200 "SDK\n"
201 "or adding a version constraint to use an older version of a " 201 "or adding a version constraint to use an older version of a "
202 "package."); 202 "package.");
203 } 203 }
204 }); 204 });
205 } 205 }
206 206
207 /// Loads the list of concrete package versions from the `pubspec.lock`, if it 207 /// Loads the list of concrete package versions from the `pubspec.lock`, if it
208 /// exists. If it doesn't, this completes to an empty [LockFile]. 208 /// exists. If it doesn't, this completes to an empty [LockFile].
209 LockFile loadLockFile() { 209 LockFile loadLockFile() {
210 var lockFilePath = join(root.dir, 'pubspec.lock'); 210 var lockFilePath = path.join(root.dir, 'pubspec.lock');
211 if (!fileExists(lockFilePath)) return new LockFile.empty(); 211 if (!fileExists(lockFilePath)) return new LockFile.empty();
212 return new LockFile.parse(readTextFile(lockFilePath), cache.sources); 212 return new LockFile.parse(readTextFile(lockFilePath), cache.sources);
213 } 213 }
214 214
215 /// Saves a list of concrete package versions to the `pubspec.lock` file. 215 /// Saves a list of concrete package versions to the `pubspec.lock` file.
216 void _saveLockFile(List<PackageId> packageIds) { 216 void _saveLockFile(List<PackageId> packageIds) {
217 var lockFile = new LockFile.empty(); 217 var lockFile = new LockFile.empty();
218 for (var id in packageIds) { 218 for (var id in packageIds) {
219 if (!id.isRoot) lockFile.packages[id.name] = id; 219 if (!id.isRoot) lockFile.packages[id.name] = id;
220 } 220 }
221 221
222 var lockFilePath = join(root.dir, 'pubspec.lock'); 222 var lockFilePath = path.join(root.dir, 'pubspec.lock');
223 writeTextFile(lockFilePath, lockFile.serialize()); 223 writeTextFile(lockFilePath, lockFile.serialize());
224 } 224 }
225 225
226 /// Installs a self-referential symlink in the `packages` directory that will 226 /// Installs a self-referential symlink in the `packages` directory that will
227 /// allow a package to import its own files using `package:`. 227 /// allow a package to import its own files using `package:`.
228 Future _installSelfReference(_) { 228 Future _installSelfReference(_) {
229 return defer(() { 229 return defer(() {
230 var linkPath = join(packagesDir, root.name); 230 var linkPath = path.join(packagesDir, root.name);
231 // Create the symlink if it doesn't exist. 231 // Create the symlink if it doesn't exist.
232 if (entryExists(linkPath)) return; 232 if (entryExists(linkPath)) return;
233 ensureDir(packagesDir); 233 ensureDir(packagesDir);
234 return createPackageSymlink(root.name, root.dir, linkPath, 234 return createPackageSymlink(root.name, root.dir, linkPath,
235 isSelfLink: true); 235 isSelfLink: true);
236 }); 236 });
237 } 237 }
238 238
239 /// If `bin/`, `test/`, or `example/` directories exist, symlink `packages/` 239 /// If `bin/`, `test/`, or `example/` directories exist, symlink `packages/`
240 /// into them so that their entrypoints can be run. Do the same for any 240 /// into them so that their entrypoints can be run. Do the same for any
241 /// subdirectories of `test/` and `example/`. 241 /// subdirectories of `test/` and `example/`.
242 Future _linkSecondaryPackageDirs(_) { 242 Future _linkSecondaryPackageDirs(_) {
243 var binDir = join(root.dir, 'bin'); 243 var binDir = path.join(root.dir, 'bin');
244 var exampleDir = join(root.dir, 'example'); 244 var exampleDir = path.join(root.dir, 'example');
245 var testDir = join(root.dir, 'test'); 245 var testDir = path.join(root.dir, 'test');
246 var toolDir = join(root.dir, 'tool'); 246 var toolDir = path.join(root.dir, 'tool');
247 var webDir = join(root.dir, 'web'); 247 var webDir = path.join(root.dir, 'web');
248 return defer(() { 248 return defer(() {
249 if (!dirExists(binDir)) return; 249 if (!dirExists(binDir)) return;
250 return _linkSecondaryPackageDir(binDir); 250 return _linkSecondaryPackageDir(binDir);
251 }).then((_) => _linkSecondaryPackageDirsRecursively(exampleDir)) 251 }).then((_) => _linkSecondaryPackageDirsRecursively(exampleDir))
252 .then((_) => _linkSecondaryPackageDirsRecursively(testDir)) 252 .then((_) => _linkSecondaryPackageDirsRecursively(testDir))
253 .then((_) => _linkSecondaryPackageDirsRecursively(toolDir)) 253 .then((_) => _linkSecondaryPackageDirsRecursively(toolDir))
254 .then((_) => _linkSecondaryPackageDirsRecursively(webDir)); 254 .then((_) => _linkSecondaryPackageDirsRecursively(webDir));
255 } 255 }
256 256
257 /// Creates a symlink to the `packages` directory in [dir] and all its 257 /// Creates a symlink to the `packages` directory in [dir] and all its
(...skipping 29 matching lines...) Expand all
287 fileAndSubfiles.addAll(subfiles); 287 fileAndSubfiles.addAll(subfiles);
288 return fileAndSubfiles; 288 return fileAndSubfiles;
289 }); 289 });
290 })); 290 }));
291 }).then(flatten); 291 }).then(flatten);
292 } 292 }
293 293
294 /// Creates a symlink to the `packages` directory in [dir] if none exists. 294 /// Creates a symlink to the `packages` directory in [dir] if none exists.
295 Future _linkSecondaryPackageDir(String dir) { 295 Future _linkSecondaryPackageDir(String dir) {
296 return defer(() { 296 return defer(() {
297 var to = join(dir, 'packages'); 297 var to = path.join(dir, 'packages');
298 if (entryExists(to)) return; 298 if (entryExists(to)) return;
299 return createSymlink(packagesDir, to); 299 return createSymlink(packagesDir, to);
300 }); 300 });
301 } 301 }
302 } 302 }
OLDNEW
« no previous file with comments | « utils/pub/command_lish.dart ('k') | utils/pub/git_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698