| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:path/path.dart' as p; | 8 import 'package:path/path.dart' as p; |
| 9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 10 import 'package:pub_semver/pub_semver.dart'; | 10 import 'package:pub_semver/pub_semver.dart'; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 return environment.precompileExecutables(package, binDir); | 205 return environment.precompileExecutables(package, binDir); |
| 206 }); | 206 }); |
| 207 } | 207 } |
| 208 | 208 |
| 209 /// Downloads [id] into the system cache if it's a cached package. | 209 /// Downloads [id] into the system cache if it's a cached package. |
| 210 Future _cacheDependency(PackageId id) async { | 210 Future _cacheDependency(PackageId id) async { |
| 211 if (id.isRoot) return; | 211 if (id.isRoot) return; |
| 212 | 212 |
| 213 var source = cache.source(id.source); | 213 var source = cache.source(id.source); |
| 214 if (source is! CachedSource) return; | 214 if (source is CachedSource) await source.downloadToSystemCache(id); |
| 215 | |
| 216 await source.downloadToSystemCache(id); | |
| 217 } | 215 } |
| 218 | 216 |
| 219 /// Finishes activating package [package] by saving [lockFile] in the cache. | 217 /// Finishes activating package [package] by saving [lockFile] in the cache. |
| 220 void _writeLockFile(String package, LockFile lockFile) { | 218 void _writeLockFile(String package, LockFile lockFile) { |
| 221 ensureDir(p.join(_directory, package)); | 219 ensureDir(p.join(_directory, package)); |
| 222 | 220 |
| 223 // TODO(nweiz): This cleans up Dart 1.6's old lockfile location. Remove it | 221 // TODO(nweiz): This cleans up Dart 1.6's old lockfile location. Remove it |
| 224 // when Dart 1.6 is old enough that we don't think anyone will have these | 222 // when Dart 1.6 is old enough that we don't think anyone will have these |
| 225 // lockfiles anymore (issue 20703). | 223 // lockfiles anymore (issue 20703). |
| 226 var oldPath = p.join(_directory, "$package.lock"); | 224 var oldPath = p.join(_directory, "$package.lock"); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 return '${log.bold(id.name)} ${id.version}'; | 423 return '${log.bold(id.name)} ${id.version}'; |
| 426 } | 424 } |
| 427 } | 425 } |
| 428 | 426 |
| 429 /// Repairs any corrupted globally-activated packages and their binstubs. | 427 /// Repairs any corrupted globally-activated packages and their binstubs. |
| 430 /// | 428 /// |
| 431 /// Returns a pair of two lists of strings. The first indicates which packages | 429 /// Returns a pair of two lists of strings. The first indicates which packages |
| 432 /// were successfully re-activated; the second indicates which failed. | 430 /// were successfully re-activated; the second indicates which failed. |
| 433 Future<Pair<List<String>, List<String>>> repairActivatedPackages() | 431 Future<Pair<List<String>, List<String>>> repairActivatedPackages() |
| 434 async { | 432 async { |
| 435 var executables = {}; | 433 var executables = <String, List<String>>{}; |
| 436 if (dirExists(_binStubDir)) { | 434 if (dirExists(_binStubDir)) { |
| 437 for (var entry in listDir(_binStubDir)) { | 435 for (var entry in listDir(_binStubDir)) { |
| 438 try { | 436 try { |
| 439 var binstub = readTextFile(entry); | 437 var binstub = readTextFile(entry); |
| 440 var package = _binStubProperty(binstub, "Package"); | 438 var package = _binStubProperty(binstub, "Package"); |
| 441 if (package == null) { | 439 if (package == null) { |
| 442 throw new ApplicationException("No 'Package' property."); | 440 throw new ApplicationException("No 'Package' property."); |
| 443 } | 441 } |
| 444 | 442 |
| 445 var executable = _binStubProperty(binstub, "Executable"); | 443 var executable = _binStubProperty(binstub, "Executable"); |
| 446 if (executable == null) { | 444 if (executable == null) { |
| 447 throw new ApplicationException("No 'Executable' property."); | 445 throw new ApplicationException("No 'Executable' property."); |
| 448 } | 446 } |
| 449 | 447 |
| 450 executables.putIfAbsent(package, () => []).add(executable); | 448 executables.putIfAbsent(package, () => []).add(executable); |
| 451 } catch (error, stackTrace) { | 449 } catch (error, stackTrace) { |
| 452 log.error( | 450 log.error( |
| 453 "Error reading binstub for " | 451 "Error reading binstub for " |
| 454 "\"${p.basenameWithoutExtension(entry)}\"", | 452 "\"${p.basenameWithoutExtension(entry)}\"", |
| 455 error, stackTrace); | 453 error, stackTrace); |
| 456 | 454 |
| 457 tryDeleteEntry(entry); | 455 tryDeleteEntry(entry); |
| 458 } | 456 } |
| 459 } | 457 } |
| 460 } | 458 } |
| 461 | 459 |
| 462 var successes = []; | 460 var successes = <String>[]; |
| 463 var failures = []; | 461 var failures = <String>[]; |
| 464 if (dirExists(_directory)) { | 462 if (dirExists(_directory)) { |
| 465 for (var entry in listDir(_directory)) { | 463 for (var entry in listDir(_directory)) { |
| 466 var id; | 464 var id; |
| 467 try { | 465 try { |
| 468 id = _loadPackageId(entry); | 466 id = _loadPackageId(entry); |
| 469 log.message("Reactivating ${log.bold(id.name)} ${id.version}..."); | 467 log.message("Reactivating ${log.bold(id.name)} ${id.version}..."); |
| 470 | 468 |
| 471 var entrypoint = find(id.name); | 469 var entrypoint = find(id.name); |
| 472 var snapshots = await _precompileExecutables(entrypoint, id.name); | 470 var snapshots = await _precompileExecutables(entrypoint, id.name); |
| 473 var packageExecutables = executables.remove(id.name); | 471 var packageExecutables = executables.remove(id.name); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 // list of executables has changed. | 542 // list of executables has changed. |
| 545 _deleteBinStubs(package.name); | 543 _deleteBinStubs(package.name); |
| 546 | 544 |
| 547 if ((executables != null && executables.isEmpty) || | 545 if ((executables != null && executables.isEmpty) || |
| 548 package.pubspec.executables.isEmpty) { | 546 package.pubspec.executables.isEmpty) { |
| 549 return; | 547 return; |
| 550 } | 548 } |
| 551 | 549 |
| 552 ensureDir(_binStubDir); | 550 ensureDir(_binStubDir); |
| 553 | 551 |
| 554 var installed = []; | 552 var installed = <String>[]; |
| 555 var collided = {}; | 553 var collided = <String, String>{}; |
| 556 var allExecutables = ordered(package.pubspec.executables.keys); | 554 var allExecutables = ordered(package.pubspec.executables.keys); |
| 557 for (var executable in allExecutables) { | 555 for (var executable in allExecutables) { |
| 558 if (executables != null && !executables.contains(executable)) continue; | 556 if (executables != null && !executables.contains(executable)) continue; |
| 559 | 557 |
| 560 var script = package.pubspec.executables[executable]; | 558 var script = package.pubspec.executables[executable]; |
| 561 | 559 |
| 562 var previousPackage = _createBinStub(package, executable, script, | 560 var previousPackage = _createBinStub(package, executable, script, |
| 563 overwrite: overwriteBinStubs, snapshot: snapshots[script]); | 561 overwrite: overwriteBinStubs, snapshot: snapshots[script]); |
| 564 if (previousPackage != null) { | 562 if (previousPackage != null) { |
| 565 collided[executable] = previousPackage; | 563 collided[executable] = previousPackage; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 798 } |
| 801 | 799 |
| 802 /// Returns the value of the property named [name] in the bin stub script | 800 /// Returns the value of the property named [name] in the bin stub script |
| 803 /// [source]. | 801 /// [source]. |
| 804 String _binStubProperty(String source, String name) { | 802 String _binStubProperty(String source, String name) { |
| 805 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); | 803 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); |
| 806 var match = pattern.firstMatch(source); | 804 var match = pattern.firstMatch(source); |
| 807 return match == null ? null : match[1]; | 805 return match == null ? null : match[1]; |
| 808 } | 806 } |
| 809 } | 807 } |
| OLD | NEW |