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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
127 | 127 |
128 // Get the package's dependencies. | 128 // Get the package's dependencies. |
129 await entrypoint.ensureLockFileIsUpToDate(); | 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); |
137 var id = new PackageId(name, "path", entrypoint.root.version, | 137 var id = new PackageId(name, "path", entrypoint.root.version, |
138 PathSource.describePath(fullPath)); | 138 PathSource.describePath(fullPath)); |
139 | 139 |
(...skipping 25 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 graph = await new Entrypoint.inMemory(root, lockFile, cache) | 175 var entrypoint = new Entrypoint.fromSolveResult(root, cache, result); |
176 .loadPackageGraph(result); | 176 var snapshots = await _precompileExecutables(entrypoint, dep.name); |
177 var snapshots = await _precompileExecutables(graph.entrypoint, dep.name); | |
178 _writeLockFile(dep.name, lockFile); | 177 _writeLockFile(dep.name, lockFile); |
179 writeTextFile(_getPackagesFilePath(dep.name), lockFile.packagesFile()); | 178 writeTextFile(_getPackagesFilePath(dep.name), lockFile.packagesFile()); |
180 | 179 |
181 _updateBinStubs(graph.packages[dep.name], executables, | 180 _updateBinStubs(entrypoint.packageGraph.packages[dep.name], executables, |
182 overwriteBinStubs: overwriteBinStubs, snapshots: snapshots); | 181 overwriteBinStubs: overwriteBinStubs, snapshots: snapshots); |
183 } | 182 } |
184 | 183 |
185 /// Precompiles the executables for [package] and saves them in the global | 184 /// Precompiles the executables for [package] and saves them in the global |
186 /// cache. | 185 /// cache. |
187 /// | 186 /// |
188 /// Returns a map from executable name to path for the snapshots that were | 187 /// Returns a map from executable name to path for the snapshots that were |
189 /// successfully precompiled. | 188 /// successfully precompiled. |
190 Future<Map<String, String>> _precompileExecutables(Entrypoint entrypoint, | 189 Future<Map<String, String>> _precompileExecutables(Entrypoint entrypoint, |
191 String package) { | 190 String package) { |
192 return log.progress("Precompiling executables", () async { | 191 return log.progress("Precompiling executables", () async { |
193 var binDir = p.join(_directory, package, 'bin'); | 192 var binDir = p.join(_directory, package, 'bin'); |
194 cleanDir(binDir); | 193 cleanDir(binDir); |
195 | 194 |
196 var graph = await entrypoint.loadPackageGraph(); | |
197 var environment = await AssetEnvironment.create( | 195 var environment = await AssetEnvironment.create( |
198 entrypoint, BarbackMode.RELEASE, | 196 entrypoint, BarbackMode.RELEASE, |
199 entrypoints: graph.packages[package].executableIds, | 197 entrypoints: entrypoint.packageGraph.packages[package].executableIds, |
200 useDart2JS: false); | 198 useDart2JS: false); |
201 environment.barback.errors.listen((error) { | 199 environment.barback.errors.listen((error) { |
202 log.error(log.red("Build error:\n$error")); | 200 log.error(log.red("Build error:\n$error")); |
203 }); | 201 }); |
204 | 202 |
205 return environment.precompileExecutables(package, binDir); | 203 return environment.precompileExecutables(package, binDir); |
206 }); | 204 }); |
207 } | 205 } |
208 | 206 |
209 /// Downloads [id] into the system cache if it's a cached package. | 207 /// Downloads [id] into the system cache if it's a cached package. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 log.verbosity = log.Verbosity.WARNING; | 350 log.verbosity = log.Verbosity.WARNING; |
353 } | 351 } |
354 | 352 |
355 var snapshotPath = p.join(binDir, '$executable.dart.snapshot'); | 353 var snapshotPath = p.join(binDir, '$executable.dart.snapshot'); |
356 return exe.runSnapshot(snapshotPath, args, | 354 return exe.runSnapshot(snapshotPath, args, |
357 checked: checked, | 355 checked: checked, |
358 packagesFile: _getPackagesFilePath(package), | 356 packagesFile: _getPackagesFilePath(package), |
359 recompile: () async { | 357 recompile: () async { |
360 log.fine("$package:$executable is out of date and needs to be " | 358 log.fine("$package:$executable is out of date and needs to be " |
361 "recompiled."); | 359 "recompiled."); |
362 var graph = await find(package).loadPackageGraph(); | 360 await _precompileExecutables( |
363 await _precompileExecutables(graph.entrypoint, package); | 361 find(package).packageGraph.entrypoint, package); |
364 }); | 362 }); |
365 } | 363 } |
366 | 364 |
367 /// Gets the path to the lock file for an activated cached package with | 365 /// Gets the path to the lock file for an activated cached package with |
368 /// [name]. | 366 /// [name]. |
369 String _getLockFilePath(String name) => | 367 String _getLockFilePath(String name) => |
370 p.join(_directory, name, "pubspec.lock"); | 368 p.join(_directory, name, "pubspec.lock"); |
371 | 369 |
372 /// Gets the path to the .packages file for an activated cached package with | 370 /// Gets the path to the .packages file for an activated cached package with |
373 /// [name]. | 371 /// [name]. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 var successes = []; | 450 var successes = []; |
453 var failures = []; | 451 var failures = []; |
454 if (dirExists(_directory)) { | 452 if (dirExists(_directory)) { |
455 for (var entry in listDir(_directory)) { | 453 for (var entry in listDir(_directory)) { |
456 var id; | 454 var id; |
457 try { | 455 try { |
458 id = _loadPackageId(entry); | 456 id = _loadPackageId(entry); |
459 log.message("Reactivating ${log.bold(id.name)} ${id.version}..."); | 457 log.message("Reactivating ${log.bold(id.name)} ${id.version}..."); |
460 | 458 |
461 var entrypoint = find(id.name); | 459 var entrypoint = find(id.name); |
462 var graph = await entrypoint.loadPackageGraph(); | |
463 var snapshots = await _precompileExecutables(entrypoint, id.name); | 460 var snapshots = await _precompileExecutables(entrypoint, id.name); |
464 var packageExecutables = executables.remove(id.name); | 461 var packageExecutables = executables.remove(id.name); |
465 if (packageExecutables == null) packageExecutables = []; | 462 if (packageExecutables == null) packageExecutables = []; |
466 _updateBinStubs(graph.packages[id.name], packageExecutables, | 463 _updateBinStubs( |
467 overwriteBinStubs: true, snapshots: snapshots, | 464 entrypoint.packageGraph.packages[id.name], |
| 465 packageExecutables, |
| 466 overwriteBinStubs: true, |
| 467 snapshots: snapshots, |
468 suggestIfNotOnPath: false); | 468 suggestIfNotOnPath: false); |
469 successes.add(id.name); | 469 successes.add(id.name); |
470 } catch (error, stackTrace) { | 470 } catch (error, stackTrace) { |
471 var message = "Failed to reactivate " | 471 var message = "Failed to reactivate " |
472 "${log.bold(p.basenameWithoutExtension(entry))}"; | 472 "${log.bold(p.basenameWithoutExtension(entry))}"; |
473 if (id != null) { | 473 if (id != null) { |
474 message += " ${id.version}"; | 474 message += " ${id.version}"; |
475 if (id.source != "hosted") message += " from ${id.source}"; | 475 if (id.source != "hosted") message += " from ${id.source}"; |
476 } | 476 } |
477 | 477 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 } | 784 } |
785 | 785 |
786 /// 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 |
787 /// [source]. | 787 /// [source]. |
788 String _binStubProperty(String source, String name) { | 788 String _binStubProperty(String source, String name) { |
789 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); | 789 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); |
790 var match = pattern.firstMatch(source); | 790 var match = pattern.firstMatch(source); |
791 return match == null ? null : match[1]; | 791 return match == null ? null : match[1]; |
792 } | 792 } |
793 } | 793 } |
OLD | NEW |