OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 pub.global_packages; | 5 library pub.global_packages; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // If the package specified by the user doesn't exist, we want to | 161 // If the package specified by the user doesn't exist, we want to |
162 // surface that as a [DataError] with the associated exit code. | 162 // surface that as a [DataError] with the associated exit code. |
163 if (result.error.package != dep.name) throw result.error; | 163 if (result.error.package != dep.name) throw result.error; |
164 if (result.error is NoVersionException) dataError(result.error.message); | 164 if (result.error is NoVersionException) dataError(result.error.message); |
165 throw result.error; | 165 throw result.error; |
166 } | 166 } |
167 result.showReport(SolveType.GET); | 167 result.showReport(SolveType.GET); |
168 | 168 |
169 // Make sure all of the dependencies are locally installed. | 169 // Make sure all of the dependencies are locally installed. |
170 await Future.wait(result.packages.map(_cacheDependency)); | 170 await Future.wait(result.packages.map(_cacheDependency)); |
171 var lockFile = new LockFile(result.packages, cache.sources); | |
172 | 171 |
173 // Load the package graph from [result] so we don't need to re-parse all | 172 // Load the package graph from [result] so we don't need to re-parse all |
174 // the pubspecs. | 173 // the pubspecs. |
175 var entrypoint = new Entrypoint.fromSolveResult(root, cache, result, | 174 var entrypoint = new Entrypoint.fromSolveResult(root, cache, result, |
176 isGlobal: true); | 175 isGlobal: true); |
177 var snapshots = await _precompileExecutables(entrypoint, dep.name); | 176 var snapshots = await _precompileExecutables(entrypoint, dep.name); |
| 177 |
| 178 var lockFile = result.lockFile; |
178 _writeLockFile(dep.name, lockFile); | 179 _writeLockFile(dep.name, lockFile); |
179 writeTextFile(_getPackagesFilePath(dep.name), lockFile.packagesFile()); | 180 writeTextFile(_getPackagesFilePath(dep.name), lockFile.packagesFile()); |
180 | 181 |
181 _updateBinStubs(entrypoint.packageGraph.packages[dep.name], executables, | 182 _updateBinStubs(entrypoint.packageGraph.packages[dep.name], executables, |
182 overwriteBinStubs: overwriteBinStubs, snapshots: snapshots); | 183 overwriteBinStubs: overwriteBinStubs, snapshots: snapshots); |
183 } | 184 } |
184 | 185 |
185 /// Precompiles the executables for [package] and saves them in the global | 186 /// Precompiles the executables for [package] and saves them in the global |
186 /// cache. | 187 /// cache. |
187 /// | 188 /// |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // could find and load the [Package] object, but normally an entrypoint | 303 // could find and load the [Package] object, but normally an entrypoint |
303 // doesn't expect to be in its own lockfile. | 304 // doesn't expect to be in its own lockfile. |
304 var id = lockFile.packages[name]; | 305 var id = lockFile.packages[name]; |
305 lockFile = lockFile.removePackage(name); | 306 lockFile = lockFile.removePackage(name); |
306 | 307 |
307 var source = cache.sources[id.source]; | 308 var source = cache.sources[id.source]; |
308 var entrypoint; | 309 var entrypoint; |
309 if (source is CachedSource) { | 310 if (source is CachedSource) { |
310 // For cached sources, the package itself is in the cache and the | 311 // For cached sources, the package itself is in the cache and the |
311 // lockfile is the one we just loaded. | 312 // lockfile is the one we just loaded. |
312 var dir = cache.sources[id.source].getDirectory(id); | |
313 var package = new Package.load(name, dir, cache.sources); | |
314 entrypoint = new Entrypoint.inMemory( | 313 entrypoint = new Entrypoint.inMemory( |
315 package, lockFile, cache, isGlobal: true); | 314 cache.sources.load(id), lockFile, cache, isGlobal: true); |
316 } else { | 315 } else { |
317 // For uncached sources (i.e. path), the ID just points to the real | 316 // For uncached sources (i.e. path), the ID just points to the real |
318 // directory for the package. | 317 // directory for the package. |
319 assert(id.source == "path"); | 318 assert(id.source == "path"); |
320 entrypoint = new Entrypoint( | 319 entrypoint = new Entrypoint( |
321 PathSource.pathFromDescription(id.description), cache, | 320 PathSource.pathFromDescription(id.description), cache, |
322 isGlobal: true); | 321 isGlobal: true); |
323 } | 322 } |
324 | 323 |
325 if (entrypoint.root.pubspec.environment.sdkVersion.allows(sdk.version)) { | 324 if (entrypoint.root.pubspec.environment.sdkVersion.allows(sdk.version)) { |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 } | 790 } |
792 | 791 |
793 /// Returns the value of the property named [name] in the bin stub script | 792 /// Returns the value of the property named [name] in the bin stub script |
794 /// [source]. | 793 /// [source]. |
795 String _binStubProperty(String source, String name) { | 794 String _binStubProperty(String source, String name) { |
796 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); | 795 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); |
797 var match = pattern.firstMatch(source); | 796 var match = pattern.firstMatch(source); |
798 return match == null ? null : match[1]; | 797 return match == null ? null : match[1]; |
799 } | 798 } |
800 } | 799 } |
OLD | NEW |