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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 /// | 116 /// |
117 /// [executables] is the names of the executables that should have binstubs. | 117 /// [executables] is the names of the executables that should have binstubs. |
118 /// If `null`, all executables in the package will get binstubs. If empty, no | 118 /// If `null`, all executables in the package will get binstubs. If empty, no |
119 /// binstubs will be created. | 119 /// binstubs will be created. |
120 /// | 120 /// |
121 /// if [overwriteBinStubs] is `true`, any binstubs that collide with | 121 /// if [overwriteBinStubs] is `true`, any binstubs that collide with |
122 /// existing binstubs in other packages will be overwritten by this one's. | 122 /// existing binstubs in other packages will be overwritten by this one's. |
123 /// Otherwise, the previous ones will be preserved. | 123 /// Otherwise, the previous ones will be preserved. |
124 Future activatePath(String path, List<String> executables, | 124 Future activatePath(String path, List<String> executables, |
125 {bool overwriteBinStubs}) async { | 125 {bool overwriteBinStubs}) async { |
126 var entrypoint = new Entrypoint(path, cache); | 126 var entrypoint = new Entrypoint(path, cache, isGlobal: true); |
127 | 127 |
128 // Get the package's dependencies. | 128 // Get the package's dependencies. |
129 await entrypoint.acquireDependencies(SolveType.GET); | 129 await entrypoint.acquireDependencies(SolveType.GET); |
130 var name = entrypoint.root.name; | 130 var name = entrypoint.root.name; |
131 | 131 |
132 // Call this just to log what the current active package is, if any. | 132 // Call this just to log what the current active package is, if any. |
133 _describeActive(name); | 133 _describeActive(name); |
134 | 134 |
135 // Write a lockfile that points to the local package. | 135 // Write a lockfile that points to the local package. |
136 var fullPath = canonicalize(entrypoint.root.dir); | 136 var fullPath = canonicalize(entrypoint.root.dir); |
(...skipping 28 matching lines...) Expand all Loading... |
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 var ids = await Future.wait(result.packages.map(_cacheDependency)); | 170 var ids = await Future.wait(result.packages.map(_cacheDependency)); |
171 var lockFile = new LockFile(ids, cache.sources); | 171 var lockFile = new LockFile(ids, cache.sources); |
172 | 172 |
173 // Load the package graph from [result] so we don't need to re-parse all | 173 // Load the package graph from [result] so we don't need to re-parse all |
174 // the pubspecs. | 174 // the pubspecs. |
175 var entrypoint = new Entrypoint.fromSolveResult(root, cache, result); | 175 var entrypoint = new Entrypoint.fromSolveResult(root, cache, result, |
| 176 isGlobal: true); |
176 var snapshots = await _precompileExecutables(entrypoint, dep.name); | 177 var snapshots = await _precompileExecutables(entrypoint, dep.name); |
177 _writeLockFile(dep.name, lockFile); | 178 _writeLockFile(dep.name, lockFile); |
178 writeTextFile(_getPackagesFilePath(dep.name), lockFile.packagesFile()); | 179 writeTextFile(_getPackagesFilePath(dep.name), lockFile.packagesFile()); |
179 | 180 |
180 _updateBinStubs(entrypoint.packageGraph.packages[dep.name], executables, | 181 _updateBinStubs(entrypoint.packageGraph.packages[dep.name], executables, |
181 overwriteBinStubs: overwriteBinStubs, snapshots: snapshots); | 182 overwriteBinStubs: overwriteBinStubs, snapshots: snapshots); |
182 } | 183 } |
183 | 184 |
184 /// Precompiles the executables for [package] and saves them in the global | 185 /// Precompiles the executables for [package] and saves them in the global |
185 /// cache. | 186 /// cache. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // doesn't expect to be in its own lockfile. | 306 // doesn't expect to be in its own lockfile. |
306 var id = lockFile.packages[name]; | 307 var id = lockFile.packages[name]; |
307 lockFile = lockFile.removePackage(name); | 308 lockFile = lockFile.removePackage(name); |
308 | 309 |
309 var source = cache.sources[id.source]; | 310 var source = cache.sources[id.source]; |
310 if (source is CachedSource) { | 311 if (source is CachedSource) { |
311 // For cached sources, the package itself is in the cache and the | 312 // For cached sources, the package itself is in the cache and the |
312 // lockfile is the one we just loaded. | 313 // lockfile is the one we just loaded. |
313 var dir = cache.sources[id.source].getDirectory(id); | 314 var dir = cache.sources[id.source].getDirectory(id); |
314 var package = new Package.load(name, dir, cache.sources); | 315 var package = new Package.load(name, dir, cache.sources); |
315 return new Entrypoint.inMemory(package, lockFile, cache); | 316 return new Entrypoint.inMemory(package, lockFile, cache, isGlobal: true); |
316 } | 317 } |
317 | 318 |
318 // For uncached sources (i.e. path), the ID just points to the real | 319 // For uncached sources (i.e. path), the ID just points to the real |
319 // directory for the package. | 320 // directory for the package. |
320 assert(id.source == "path"); | 321 assert(id.source == "path"); |
321 return new Entrypoint(PathSource.pathFromDescription(id.description), | 322 return new Entrypoint( |
322 cache); | 323 PathSource.pathFromDescription(id.description), cache, isGlobal: true); |
323 } | 324 } |
324 | 325 |
325 /// Runs [package]'s [executable] with [args]. | 326 /// Runs [package]'s [executable] with [args]. |
326 /// | 327 /// |
327 /// If [executable] is available in its precompiled form, that will be | 328 /// If [executable] is available in its precompiled form, that will be |
328 /// recompiled if the SDK has been upgraded since it was first compiled and | 329 /// recompiled if the SDK has been upgraded since it was first compiled and |
329 /// then run. Otherwise, it will be run from source. | 330 /// then run. Otherwise, it will be run from source. |
330 /// | 331 /// |
331 /// If [checked] is true, the program is run in checked mode. If [mode] is | 332 /// If [checked] is true, the program is run in checked mode. If [mode] is |
332 /// passed, it's used as the barback mode; it defaults to | 333 /// passed, it's used as the barback mode; it defaults to |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 } | 784 } |
784 | 785 |
785 /// Returns the value of the property named [name] in the bin stub script | 786 /// Returns the value of the property named [name] in the bin stub script |
786 /// [source]. | 787 /// [source]. |
787 String _binStubProperty(String source, String name) { | 788 String _binStubProperty(String source, String name) { |
788 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); | 789 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); |
789 var match = pattern.firstMatch(source); | 790 var match = pattern.firstMatch(source); |
790 return match == null ? null : match[1]; | 791 return match == null ? null : match[1]; |
791 } | 792 } |
792 } | 793 } |
OLD | NEW |