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('io.dart'); | 7 #import('io.dart'); |
8 #import('lock_file.dart'); | 8 #import('lock_file.dart'); |
9 #import('package.dart'); | 9 #import('package.dart'); |
10 #import('root_source.dart'); | 10 #import('root_source.dart'); |
(...skipping 13 matching lines...) Expand all Loading... |
24 * point either to the [SystemCache] or to some other location on the local | 24 * point either to the [SystemCache] or to some other location on the local |
25 * filesystem. | 25 * filesystem. |
26 * | 26 * |
27 * While entrypoints are typically applications, a pure library package may end | 27 * While entrypoints are typically applications, a pure library package may end |
28 * up being used as an entrypoint. Also, a single package may be used as an | 28 * up being used as an entrypoint. Also, a single package may be used as an |
29 * entrypoint in one context but not in another. For example, a package that | 29 * entrypoint in one context but not in another. For example, a package that |
30 * contains a reusable library may not be the entrypoint when used by an app, | 30 * contains a reusable library may not be the entrypoint when used by an app, |
31 * but may be the entrypoint when you're running its tests. | 31 * but may be the entrypoint when you're running its tests. |
32 */ | 32 */ |
33 class Entrypoint { | 33 class Entrypoint { |
34 // TODO(rnystrom): Get rid of this when #4820 is fixed. | |
35 static bool installSelfLink = false; | |
36 | |
37 /** | 34 /** |
38 * The root package this entrypoint is associated with. | 35 * The root package this entrypoint is associated with. |
39 */ | 36 */ |
40 final Package root; | 37 final Package root; |
41 | 38 |
42 /** | 39 /** |
43 * The system-wide cache which caches packages that need to be fetched over | 40 * The system-wide cache which caches packages that need to be fetched over |
44 * the network. | 41 * the network. |
45 */ | 42 */ |
46 final SystemCache cache; | 43 final SystemCache cache; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 var future = ensureDir(dirname(packageDir)).chain((_) { | 78 var future = ensureDir(dirname(packageDir)).chain((_) { |
82 return exists(packageDir); | 79 return exists(packageDir); |
83 }).chain((exists) { | 80 }).chain((exists) { |
84 if (!exists) return new Future.immediate(null); | 81 if (!exists) return new Future.immediate(null); |
85 // TODO(nweiz): figure out when to actually delete the directory, and when | 82 // TODO(nweiz): figure out when to actually delete the directory, and when |
86 // we can just re-use the existing symlink. | 83 // we can just re-use the existing symlink. |
87 return deleteDir(packageDir); | 84 return deleteDir(packageDir); |
88 }).chain((_) { | 85 }).chain((_) { |
89 if (id.source.shouldCache) { | 86 if (id.source.shouldCache) { |
90 return cache.install(id).chain( | 87 return cache.install(id).chain( |
91 (pkg) => createSymlink(pkg.dir, packageDir)); | 88 (pkg) => createPackageSymlink(id.name, pkg.dir, packageDir)); |
92 } else { | 89 } else { |
93 return id.source.install(id, packageDir).transform((found) { | 90 return id.source.install(id, packageDir).transform((found) { |
94 if (found) return null; | 91 if (found) return null; |
95 // TODO(nweiz): More robust error-handling. | 92 // TODO(nweiz): More robust error-handling. |
96 throw 'Package ${id.name} not found in source "${id.source.name}".'; | 93 throw 'Package ${id.name} not found in source "${id.source.name}".'; |
97 }); | 94 }); |
98 } | 95 } |
99 }).chain((_) => id.resolved); | 96 }).chain((_) => id.resolved); |
100 | 97 |
101 _installs[id] = future; | 98 _installs[id] = future; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); | 216 return writeTextFile(join(root.dir, 'pubspec.lock'), lockFile.serialize()); |
220 } | 217 } |
221 | 218 |
222 /** | 219 /** |
223 * Installs a self-referential symlink in the `packages` directory that will | 220 * Installs a self-referential symlink in the `packages` directory that will |
224 * allow a package to import its own files using `package:`. | 221 * allow a package to import its own files using `package:`. |
225 */ | 222 */ |
226 Future _installSelfReference(_) { | 223 Future _installSelfReference(_) { |
227 var linkPath = join(path, root.name); | 224 var linkPath = join(path, root.name); |
228 return exists(linkPath).chain((exists) { | 225 return exists(linkPath).chain((exists) { |
229 if (installSelfLink) { | 226 // Create the symlink if it doesn't exist. |
230 // Create the symlink if it doesn't exist. | 227 if (exists) return new Future.immediate(null); |
231 if (exists) return new Future.immediate(null); | 228 return ensureDir(path).chain( |
232 return ensureDir(path).chain((_) => createSymlink(root.dir, linkPath)); | 229 (_) => createPackageSymlink(root.name, root.dir, linkPath, |
233 } else { | 230 isSelfLink: true)); |
234 // TODO(rnystrom): Get rid of this branch when #4820 is fixed. | |
235 // Delete the old one if it's there. | |
236 return ensureDir(path).chain((_) { | |
237 if (!exists) return new Future.immediate(null); | |
238 return deleteDir(linkPath); | |
239 }); | |
240 } | |
241 }); | 231 }); |
242 } | 232 } |
243 | 233 |
244 /** | 234 /** |
245 * If `bin/`, `test/`, or `example/` directories exist, symlink `packages/` | 235 * If `bin/`, `test/`, or `example/` directories exist, symlink `packages/` |
246 * into them so that their entrypoints can be run. Do the same for any | 236 * into them so that their entrypoints can be run. Do the same for any |
247 * subdirectories of `test/` and `example/`. | 237 * subdirectories of `test/` and `example/`. |
248 */ | 238 */ |
249 Future _linkSecondaryPackageDirs(_) { | 239 Future _linkSecondaryPackageDirs(_) { |
250 var binDir = join(root.dir, 'bin'); | 240 var binDir = join(root.dir, 'bin'); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 }); | 313 }); |
324 } | 314 } |
325 | 315 |
326 return future.transform((_) { | 316 return future.transform((_) { |
327 if (root.pubspec.name != null) return; | 317 if (root.pubspec.name != null) return; |
328 throw '"pubspec.yaml" is missing the required "name" field (e.g. "name: ' | 318 throw '"pubspec.yaml" is missing the required "name" field (e.g. "name: ' |
329 '${root.name}").'; | 319 '${root.name}").'; |
330 }); | 320 }); |
331 } | 321 } |
332 } | 322 } |
OLD | NEW |