Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 import 'io.dart'; | 8 import 'io.dart'; |
| 9 import 'lock_file.dart'; | 9 import 'lock_file.dart'; |
| 10 import 'log.dart' as log; | 10 import 'log.dart' as log; |
| 11 import 'package.dart'; | 11 import 'package.dart'; |
| 12 import 'system_cache.dart'; | 12 import 'system_cache.dart'; |
| 13 import 'utils.dart'; | 13 import 'utils.dart'; |
| 14 import 'version.dart'; | 14 import 'version.dart'; |
| 15 import 'version_solver.dart'; | 15 import 'version_solver.dart'; |
| 16 | 16 |
| 17 final _README_REGEXP = new RegExp(r"^README($|\.)", caseSensitive: false); | |
| 18 | |
| 17 /// Pub operates over a directed graph of dependencies that starts at a root | 19 /// Pub operates over a directed graph of dependencies that starts at a root |
| 18 /// "entrypoint" package. This is typically the package where the current | 20 /// "entrypoint" package. This is typically the package where the current |
| 19 /// working directory is located. An entrypoint knows the [root] package it is | 21 /// working directory is located. An entrypoint knows the [root] package it is |
| 20 /// associated with and is responsible for managing the "packages" directory | 22 /// associated with and is responsible for managing the "packages" directory |
| 21 /// for it. | 23 /// for it. |
| 22 /// | 24 /// |
| 23 /// That directory contains symlinks to all packages used by an app. These links | 25 /// That directory contains symlinks to all packages used by an app. These links |
| 24 /// point either to the [SystemCache] or to some other location on the local | 26 /// point either to the [SystemCache] or to some other location on the local |
| 25 /// filesystem. | 27 /// filesystem. |
| 26 /// | 28 /// |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 47 /// Loads the entrypoint from a package at [rootDir]. | 49 /// Loads the entrypoint from a package at [rootDir]. |
| 48 static Future<Entrypoint> load(String rootDir, SystemCache cache) { | 50 static Future<Entrypoint> load(String rootDir, SystemCache cache) { |
| 49 return Package.load(null, rootDir, cache.sources).then((package) => | 51 return Package.load(null, rootDir, cache.sources).then((package) => |
| 50 new Entrypoint(package, cache)); | 52 new Entrypoint(package, cache)); |
| 51 } | 53 } |
| 52 | 54 |
| 53 // TODO(rnystrom): Make this path configurable. | 55 // TODO(rnystrom): Make this path configurable. |
| 54 /// The path to this "packages" directory. | 56 /// The path to this "packages" directory. |
| 55 String get path => join(root.dir, 'packages'); | 57 String get path => join(root.dir, 'packages'); |
| 56 | 58 |
| 59 /// Returns the path to the README file at the root of the entrypoint, or null | |
| 60 /// if no README file is found. If multiple READMEs are found, this uses the | |
| 61 /// same conventions as pub.dartlang.org for choosing the primary one: the | |
| 62 /// README with the fewest extensions that is lexically ordered first is | |
| 63 /// chosen. | |
|
Bob Nystrom
2013/01/31 19:08:29
How about moving this to Package? It's not specifi
nweiz
2013/01/31 21:39:10
Done.
| |
| 64 Future<String> get readmePath { | |
| 65 return listDir(root.dir).then((entries) { | |
| 66 var readmes = entries.where((entry) => entry.contains(_README_REGEXP)); | |
| 67 if (readmes.isEmpty) return; | |
| 68 | |
| 69 return readmes.min((readme1, readme2) { | |
| 70 var extensions1 = ".".allMatches(readme1).length; | |
| 71 var extensions2 = ".".allMatches(readme2).length; | |
| 72 var comparison = extensions1.compareTo(extensions2); | |
| 73 if (comparison != 0) return comparison; | |
| 74 return readme1.compareTo(readme2); | |
| 75 }); | |
| 76 }); | |
| 77 } | |
| 78 | |
| 57 /// Ensures that the package identified by [id] is installed to the directory. | 79 /// Ensures that the package identified by [id] is installed to the directory. |
| 58 /// Returns the resolved [PackageId]. | 80 /// Returns the resolved [PackageId]. |
| 59 /// | 81 /// |
| 60 /// If this completes successfully, the package is guaranteed to be importable | 82 /// If this completes successfully, the package is guaranteed to be importable |
| 61 /// using the `package:` scheme. | 83 /// using the `package:` scheme. |
| 62 /// | 84 /// |
| 63 /// This will automatically install the package to the system-wide cache as | 85 /// This will automatically install the package to the system-wide cache as |
| 64 /// well if it requires network access to retrieve (specifically, if | 86 /// well if it requires network access to retrieve (specifically, if |
| 65 /// `id.source.shouldCache` is true). | 87 /// `id.source.shouldCache` is true). |
| 66 /// | 88 /// |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 | 260 |
| 239 /// Creates a symlink to the `packages` directory in [dir] if none exists. | 261 /// Creates a symlink to the `packages` directory in [dir] if none exists. |
| 240 Future _linkSecondaryPackageDir(String dir) { | 262 Future _linkSecondaryPackageDir(String dir) { |
| 241 var to = join(dir, 'packages'); | 263 var to = join(dir, 'packages'); |
| 242 return exists(to).then((exists) { | 264 return exists(to).then((exists) { |
| 243 if (exists) return; | 265 if (exists) return; |
| 244 return createSymlink(path, to); | 266 return createSymlink(path, to); |
| 245 }); | 267 }); |
| 246 } | 268 } |
| 247 } | 269 } |
| OLD | NEW |