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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 /** | 141 /** |
142 * Installs all dependencies listed in [packageVersions] and writes a | 142 * Installs all dependencies listed in [packageVersions] and writes a |
143 * [LockFile]. | 143 * [LockFile]. |
144 */ | 144 */ |
145 Future _installDependencies(List<PackageId> packageVersions) { | 145 Future _installDependencies(List<PackageId> packageVersions) { |
146 return _removeUnusedDependencies(packageVersions).chain((_) { | 146 return _removeUnusedDependencies(packageVersions).chain((_) { |
147 return Futures.wait(packageVersions.map((id) { | 147 return Futures.wait(packageVersions.map((id) { |
148 if (id.source is RootSource) return new Future.immediate(id); | 148 if (id.source is RootSource) return new Future.immediate(id); |
149 return install(id); | 149 return install(id); |
150 })); | 150 })); |
151 }).chain(_saveLockFile).chain(_installSelfReference); | 151 }).chain(_saveLockFile) |
152 .chain(_installSelfReference) | |
153 .chain(_linkSecondaryPackageDirs); | |
152 } | 154 } |
153 | 155 |
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() { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 */ | 222 */ |
221 Future _installSelfReference(_) { | 223 Future _installSelfReference(_) { |
222 var linkPath = join(path, root.name); | 224 var linkPath = join(path, root.name); |
223 return exists(linkPath).chain((exists) { | 225 return exists(linkPath).chain((exists) { |
224 if (exists) return new Future.immediate(null); | 226 if (exists) return new Future.immediate(null); |
225 return ensureDir(path).chain((_) => createSymlink(root.dir, linkPath)); | 227 return ensureDir(path).chain((_) => createSymlink(root.dir, linkPath)); |
226 }); | 228 }); |
227 } | 229 } |
228 | 230 |
229 /** | 231 /** |
232 * If `bin/` or `test/` directories exist, symlink `packages/` into them so | |
233 * that their entrypoints can be run. Do the same for any subdirectories of | |
234 * `test/`. | |
235 */ | |
236 Future _linkSecondaryPackageDirs(_) { | |
237 var binDir = join(root.dir, 'bin'); | |
238 var testDir = join(root.dir, 'test'); | |
239 return dirExists(binDir).chain((exists) { | |
240 if (!exists) return new Future.immediate(null); | |
241 return _linkSecondaryPackageDir(binDir); | |
242 }).chain((_) => dirExists(testDir)).chain((exists) { | |
243 if (!exists) return new Future.immediate(null); | |
244 return _linkSecondaryPackageDir(testDir) | |
245 .chain((_) => _listDirWithoutPackages(testDir)) | |
246 .chain((testFiles) { | |
247 return Futures.wait(testFiles.map((testFile) { | |
248 return dirExists(testFile).chain((isDir) { | |
249 if (!isDir) return new Future.immediate(null); | |
250 return _linkSecondaryPackageDir(testFile); | |
251 }); | |
252 })); | |
253 }); | |
254 }); | |
255 } | |
256 | |
257 // TODO(nweiz): roll this into [listDir] in io.dart once issue 4775 is fixed. | |
258 /** | |
259 * Recursively lists the contents of [dir], excluding hidden `.DS_Store` files | |
260 * and `package` files. | |
261 */ | |
262 Future<List<String>> _listDirWithoutPackages(dir) { | |
Bob Nystrom
2012/08/29 16:56:48
Instead of recurisively building up a list of dire
nweiz
2012/08/29 19:57:58
I didn't do that because it doesn't seem like that
| |
263 return listDir(dir).chain((files) { | |
264 return Futures.wait(files.map((file) { | |
265 if (basename(file) == 'packages') return new Future.immediate([]); | |
266 return dirExists(file).chain((isDir) { | |
267 if (!isDir) return new Future.immediate([]); | |
268 return _listDirWithoutPackages(file); | |
269 }).transform((subfiles) { | |
270 var fileAndSubfiles = [file]; | |
271 fileAndSubfiles.addAll(subfiles); | |
272 return fileAndSubfiles; | |
273 }); | |
274 })); | |
275 }).transform(flatten); | |
276 } | |
277 | |
278 /** | |
279 * Creates a symlink to the `packages` directory in [dir] if none exists. | |
280 */ | |
281 Future _linkSecondaryPackageDir(String dir) { | |
282 var to = join(dir, 'packages'); | |
283 return exists(to).chain((exists) { | |
284 if (exists) return new Future.immediate(null); | |
285 return createSymlink(path, to); | |
286 }); | |
287 } | |
288 | |
289 /** | |
230 * Validate that the pubspec for the entrypoint exists and specifies the name | 290 * Validate that the pubspec for the entrypoint exists and specifies the name |
231 * of the root package. | 291 * of the root package. |
232 */ | 292 */ |
233 Future _validatePubspec() { | 293 Future _validatePubspec() { |
234 var future = new Future.immediate(null);; | 294 var future = new Future.immediate(null);; |
235 if (root.pubspec.isEmpty) { | 295 if (root.pubspec.isEmpty) { |
236 future = exists(join(path, "pubspec.yaml")).transform((exists) { | 296 future = exists(join(path, "pubspec.yaml")).transform((exists) { |
237 if (exists) return; | 297 if (exists) return; |
238 throw 'Could not find a file named "pubspec.yaml" in the directory' | 298 throw 'Could not find a file named "pubspec.yaml" in the directory' |
239 '$path.'; | 299 '$path.'; |
240 }); | 300 }); |
241 } | 301 } |
242 | 302 |
243 return future.transform((_) { | 303 return future.transform((_) { |
244 if (root.pubspec.name != null) return; | 304 if (root.pubspec.name != null) return; |
245 throw '"pubspec.yaml" must contain a "name" key.'; | 305 throw '"pubspec.yaml" must contain a "name" key.'; |
246 }); | 306 }); |
247 } | 307 } |
248 } | 308 } |
OLD | NEW |