| 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 | 8 |
| 9 import 'package:pathos/path.dart' as path; | 9 import 'package:pathos/path.dart' as path; |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = path.join(packagesDir, id.name); | 73 var packageDir = path.join(packagesDir, id.name); |
| 74 var future = defer(() { | 74 var future = new Future.of(() { |
| 75 ensureDir(path.dirname(packageDir)); | 75 ensureDir(path.dirname(packageDir)); |
| 76 | 76 |
| 77 if (entryExists(packageDir)) { | 77 if (entryExists(packageDir)) { |
| 78 // TODO(nweiz): figure out when to actually delete the directory, and | 78 // TODO(nweiz): figure out when to actually delete the directory, and |
| 79 // when we can just re-use the existing symlink. | 79 // when 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 deleteEntry(packageDir); | 81 deleteEntry(packageDir); |
| 82 } | 82 } |
| 83 | 83 |
| 84 if (id.source.shouldCache) { | 84 if (id.source.shouldCache) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 95 | 95 |
| 96 _installs[id] = future; | 96 _installs[id] = future; |
| 97 | 97 |
| 98 return future; | 98 return future; |
| 99 } | 99 } |
| 100 | 100 |
| 101 /// Installs all dependencies of the [root] package to its "packages" | 101 /// Installs all dependencies of the [root] package to its "packages" |
| 102 /// directory, respecting the [LockFile] if present. Returns a [Future] that | 102 /// directory, respecting the [LockFile] if present. Returns a [Future] that |
| 103 /// completes when all dependencies are installed. | 103 /// completes when all dependencies are installed. |
| 104 Future installDependencies() { | 104 Future installDependencies() { |
| 105 return defer(() { | 105 return new Future.of(() { |
| 106 return resolveVersions(cache.sources, root, loadLockFile()); | 106 return resolveVersions(cache.sources, root, loadLockFile()); |
| 107 }).then(_installDependencies); | 107 }).then(_installDependencies); |
| 108 } | 108 } |
| 109 | 109 |
| 110 /// Installs the latest available versions of all dependencies of the [root] | 110 /// Installs the latest available versions of all dependencies of the [root] |
| 111 /// package to its "package" directory, writing a new [LockFile]. Returns a | 111 /// package to its "package" directory, writing a new [LockFile]. Returns a |
| 112 /// [Future] that completes when all dependencies are installed. | 112 /// [Future] that completes when all dependencies are installed. |
| 113 Future updateAllDependencies() { | 113 Future updateAllDependencies() { |
| 114 return resolveVersions(cache.sources, root, new LockFile.empty()) | 114 return resolveVersions(cache.sources, root, new LockFile.empty()) |
| 115 .then(_installDependencies); | 115 .then(_installDependencies); |
| 116 } | 116 } |
| 117 | 117 |
| 118 /// Installs the latest available versions of [dependencies], while leaving | 118 /// Installs the latest available versions of [dependencies], while leaving |
| 119 /// other dependencies as specified by the [LockFile] if possible. Returns a | 119 /// other dependencies as specified by the [LockFile] if possible. Returns a |
| 120 /// [Future] that completes when all dependencies are installed. | 120 /// [Future] that completes when all dependencies are installed. |
| 121 Future updateDependencies(List<String> dependencies) { | 121 Future updateDependencies(List<String> dependencies) { |
| 122 return defer(() { | 122 return new Future.of(() { |
| 123 var solver = new VersionSolver(cache.sources, root, loadLockFile()); | 123 var solver = new VersionSolver(cache.sources, root, loadLockFile()); |
| 124 for (var dependency in dependencies) { | 124 for (var dependency in dependencies) { |
| 125 solver.useLatestVersion(dependency); | 125 solver.useLatestVersion(dependency); |
| 126 } | 126 } |
| 127 return solver.solve(); | 127 return solver.solve(); |
| 128 }).then(_installDependencies); | 128 }).then(_installDependencies); |
| 129 } | 129 } |
| 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((ids) { | 140 }).then((ids) { |
| 141 _saveLockFile(ids); | 141 _saveLockFile(ids); |
| 142 _installSelfReference(); | 142 _installSelfReference(); |
| 143 _linkSecondaryPackageDirs(); | 143 _linkSecondaryPackageDirs(); |
| 144 }); | 144 }); |
| 145 } | 145 } |
| 146 | 146 |
| 147 /// 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 |
| 148 /// 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 |
| 149 /// successfully generated. | 149 /// successfully generated. |
| 150 Future<List<Pubspec>> walkDependencies() { | 150 Future<List<Pubspec>> walkDependencies() { |
| 151 return defer(() { | 151 return new Future.of(() { |
| 152 var lockFile = loadLockFile(); | 152 var lockFile = loadLockFile(); |
| 153 var group = new FutureGroup<Pubspec>(); | 153 var group = new FutureGroup<Pubspec>(); |
| 154 var visited = new Set<String>(); | 154 var visited = new Set<String>(); |
| 155 | 155 |
| 156 // Include the root package in the results. | 156 // Include the root package in the results. |
| 157 group.add(new Future.immediate(root.pubspec)); | 157 group.add(new Future.immediate(root.pubspec)); |
| 158 | 158 |
| 159 visitPackage(Pubspec pubspec) { | 159 visitPackage(Pubspec pubspec) { |
| 160 for (var ref in pubspec.dependencies) { | 160 for (var ref in pubspec.dependencies) { |
| 161 if (visited.contains(ref.name)) continue; | 161 if (visited.contains(ref.name)) continue; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 } | 278 } |
| 279 | 279 |
| 280 /// Creates a symlink to the `packages` directory in [dir]. Will replace one | 280 /// Creates a symlink to the `packages` directory in [dir]. Will replace one |
| 281 /// if already there. | 281 /// if already there. |
| 282 void _linkSecondaryPackageDir(String dir) { | 282 void _linkSecondaryPackageDir(String dir) { |
| 283 var symlink = path.join(dir, 'packages'); | 283 var symlink = path.join(dir, 'packages'); |
| 284 if (entryExists(symlink)) deleteEntry(symlink); | 284 if (entryExists(symlink)) deleteEntry(symlink); |
| 285 createSymlink(packagesDir, symlink, relative: true); | 285 createSymlink(packagesDir, symlink, relative: true); |
| 286 } | 286 } |
| 287 } | 287 } |
| OLD | NEW |