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 'root_source.dart'; | |
13 import 'system_cache.dart'; | 12 import 'system_cache.dart'; |
14 import 'utils.dart'; | 13 import 'utils.dart'; |
15 import 'version.dart'; | 14 import 'version.dart'; |
16 import 'version_solver.dart'; | 15 import 'version_solver.dart'; |
17 | 16 |
18 /// Pub operates over a directed graph of dependencies that starts at a root | 17 /// Pub operates over a directed graph of dependencies that starts at a root |
19 /// "entrypoint" package. This is typically the package where the current | 18 /// "entrypoint" package. This is typically the package where the current |
20 /// working directory is located. An entrypoint knows the [root] package it is | 19 /// working directory is located. An entrypoint knows the [root] package it is |
21 /// associated with and is responsible for managing the "packages" directory | 20 /// associated with and is responsible for managing the "packages" directory |
22 /// for it. | 21 /// for it. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 124 } |
126 return versionSolver.solve(); | 125 return versionSolver.solve(); |
127 }).then(_installDependencies); | 126 }).then(_installDependencies); |
128 } | 127 } |
129 | 128 |
130 /// Removes the old packages directory, installs all dependencies listed in | 129 /// Removes the old packages directory, installs all dependencies listed in |
131 /// [packageVersions], and writes a [LockFile]. | 130 /// [packageVersions], and writes a [LockFile]. |
132 Future _installDependencies(List<PackageId> packageVersions) { | 131 Future _installDependencies(List<PackageId> packageVersions) { |
133 return cleanDir(path).then((_) { | 132 return cleanDir(path).then((_) { |
134 return Future.wait(packageVersions.mappedBy((id) { | 133 return Future.wait(packageVersions.mappedBy((id) { |
135 if (id.source is RootSource) return new Future.immediate(id); | 134 if (id.isRoot) return new Future.immediate(id); |
136 return install(id); | 135 return install(id); |
137 })); | 136 })); |
138 }).then(_saveLockFile) | 137 }).then(_saveLockFile) |
139 .then(_installSelfReference) | 138 .then(_installSelfReference) |
140 .then(_linkSecondaryPackageDirs); | 139 .then(_linkSecondaryPackageDirs); |
141 } | 140 } |
142 | 141 |
143 /// Loads the list of concrete package versions from the `pubspec.lock`, if it | 142 /// Loads the list of concrete package versions from the `pubspec.lock`, if it |
144 /// exists. If it doesn't, this completes to an empty [LockFile]. | 143 /// exists. If it doesn't, this completes to an empty [LockFile]. |
145 Future<LockFile> loadLockFile() { | 144 Future<LockFile> loadLockFile() { |
146 var lockFilePath = join(root.dir, 'pubspec.lock'); | 145 var lockFilePath = join(root.dir, 'pubspec.lock'); |
147 | 146 |
148 log.fine("Loading lockfile."); | 147 log.fine("Loading lockfile."); |
149 return fileExists(lockFilePath).then((exists) { | 148 return fileExists(lockFilePath).then((exists) { |
150 if (!exists) { | 149 if (!exists) { |
151 log.fine("No lock file at $lockFilePath, creating empty one."); | 150 log.fine("No lock file at $lockFilePath, creating empty one."); |
152 return new LockFile.empty(); | 151 return new LockFile.empty(); |
153 } | 152 } |
154 | 153 |
155 return readTextFile(lockFilePath).then((text) => | 154 return readTextFile(lockFilePath).then((text) => |
156 new LockFile.parse(text, cache.sources)); | 155 new LockFile.parse(text, cache.sources)); |
157 }); | 156 }); |
158 } | 157 } |
159 | 158 |
160 /// Saves a list of concrete package versions to the `pubspec.lock` file. | 159 /// Saves a list of concrete package versions to the `pubspec.lock` file. |
161 Future _saveLockFile(List<PackageId> packageIds) { | 160 Future _saveLockFile(List<PackageId> packageIds) { |
162 var lockFile = new LockFile.empty(); | 161 var lockFile = new LockFile.empty(); |
163 for (var id in packageIds) { | 162 for (var id in packageIds) { |
164 if (id.source is! RootSource) lockFile.packages[id.name] = id; | 163 if (!id.isRoot) lockFile.packages[id.name] = id; |
165 } | 164 } |
166 | 165 |
167 var lockFilePath = join(root.dir, 'pubspec.lock'); | 166 var lockFilePath = join(root.dir, 'pubspec.lock'); |
168 log.fine("Saving lockfile."); | 167 log.fine("Saving lockfile."); |
169 return writeTextFile(lockFilePath, lockFile.serialize()); | 168 return writeTextFile(lockFilePath, lockFile.serialize()); |
170 } | 169 } |
171 | 170 |
172 /// Installs a self-referential symlink in the `packages` directory that will | 171 /// Installs a self-referential symlink in the `packages` directory that will |
173 /// allow a package to import its own files using `package:`. | 172 /// allow a package to import its own files using `package:`. |
174 Future _installSelfReference(_) { | 173 Future _installSelfReference(_) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 238 |
240 /// Creates a symlink to the `packages` directory in [dir] if none exists. | 239 /// Creates a symlink to the `packages` directory in [dir] if none exists. |
241 Future _linkSecondaryPackageDir(String dir) { | 240 Future _linkSecondaryPackageDir(String dir) { |
242 var to = join(dir, 'packages'); | 241 var to = join(dir, 'packages'); |
243 return exists(to).then((exists) { | 242 return exists(to).then((exists) { |
244 if (exists) return; | 243 if (exists) return; |
245 return createSymlink(path, to); | 244 return createSymlink(path, to); |
246 }); | 245 }); |
247 } | 246 } |
248 } | 247 } |
OLD | NEW |