| 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:convert'; | |
| 9 import 'dart:io'; | 8 import 'dart:io'; |
| 10 | 9 |
| 11 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| 12 import 'package:barback/barback.dart'; | 11 import 'package:barback/barback.dart'; |
| 13 import 'package:pub_semver/pub_semver.dart'; | 12 import 'package:pub_semver/pub_semver.dart'; |
| 14 | 13 |
| 15 import 'barback/asset_environment.dart'; | 14 import 'barback/asset_environment.dart'; |
| 16 import 'entrypoint.dart'; | 15 import 'entrypoint.dart'; |
| 17 import 'exceptions.dart'; | 16 import 'exceptions.dart'; |
| 18 import 'executable.dart' as exe; | 17 import 'executable.dart' as exe; |
| 19 import 'io.dart'; | 18 import 'io.dart'; |
| 20 import 'lock_file.dart'; | 19 import 'lock_file.dart'; |
| 21 import 'log.dart' as log; | 20 import 'log.dart' as log; |
| 22 import 'package.dart'; | 21 import 'package.dart'; |
| 22 import 'package_locations.dart'; |
| 23 import 'pubspec.dart'; | 23 import 'pubspec.dart'; |
| 24 import 'sdk.dart' as sdk; | 24 import 'sdk.dart' as sdk; |
| 25 import 'solver/version_solver.dart'; | 25 import 'solver/version_solver.dart'; |
| 26 import 'source/cached.dart'; | 26 import 'source/cached.dart'; |
| 27 import 'source/git.dart'; | 27 import 'source/git.dart'; |
| 28 import 'source/path.dart'; | 28 import 'source/path.dart'; |
| 29 import 'system_cache.dart'; | 29 import 'system_cache.dart'; |
| 30 import 'utils.dart'; | 30 import 'utils.dart'; |
| 31 | 31 |
| 32 /// Maintains the set of packages that have been globally activated. | 32 /// Maintains the set of packages that have been globally activated. |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // Make sure all of the dependencies are locally installed. | 170 // Make sure all of the dependencies are locally installed. |
| 171 var ids = await Future.wait(result.packages.map(_cacheDependency)); | 171 var ids = await Future.wait(result.packages.map(_cacheDependency)); |
| 172 var lockFile = new LockFile(ids); | 172 var lockFile = new LockFile(ids); |
| 173 | 173 |
| 174 // Load the package graph from [result] so we don't need to re-parse all | 174 // Load the package graph from [result] so we don't need to re-parse all |
| 175 // the pubspecs. | 175 // the pubspecs. |
| 176 var graph = await new Entrypoint.inMemory(root, lockFile, cache) | 176 var graph = await new Entrypoint.inMemory(root, lockFile, cache) |
| 177 .loadPackageGraph(result); | 177 .loadPackageGraph(result); |
| 178 var snapshots = await _precompileExecutables(graph.entrypoint, dep.name); | 178 var snapshots = await _precompileExecutables(graph.entrypoint, dep.name); |
| 179 _writeLockFile(dep.name, lockFile); | 179 _writeLockFile(dep.name, lockFile); |
| 180 writePackagesMap(graph, _getPackagesFilePath(dep.name)); |
| 180 | 181 |
| 181 _updateBinStubs(graph.packages[dep.name], executables, | 182 _updateBinStubs(graph.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 /// |
| 188 /// Returns a map from executable name to path for the snapshots that were | 189 /// Returns a map from executable name to path for the snapshots that were |
| 189 /// successfully precompiled. | 190 /// successfully precompiled. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 }); | 348 }); |
| 348 } | 349 } |
| 349 | 350 |
| 350 // Unless the user overrides the verbosity, we want to filter out the | 351 // Unless the user overrides the verbosity, we want to filter out the |
| 351 // normal pub output shown while loading the environment. | 352 // normal pub output shown while loading the environment. |
| 352 if (log.verbosity == log.Verbosity.NORMAL) { | 353 if (log.verbosity == log.Verbosity.NORMAL) { |
| 353 log.verbosity = log.Verbosity.WARNING; | 354 log.verbosity = log.Verbosity.WARNING; |
| 354 } | 355 } |
| 355 | 356 |
| 356 var snapshotPath = p.join(binDir, '$executable.dart.snapshot'); | 357 var snapshotPath = p.join(binDir, '$executable.dart.snapshot'); |
| 357 return exe.runSnapshot(snapshotPath, args, checked: checked, recompile: () { | 358 return exe.runSnapshot(snapshotPath, args, |
| 359 checked: checked, |
| 360 packagesFile: _getPackagesFilePath(package), |
| 361 recompile: () { |
| 358 log.fine("$package:$executable is out of date and needs to be " | 362 log.fine("$package:$executable is out of date and needs to be " |
| 359 "recompiled."); | 363 "recompiled."); |
| 360 return find(package) | 364 return find(package) |
| 361 .then((entrypoint) => entrypoint.loadPackageGraph()) | 365 .then((entrypoint) => entrypoint.loadPackageGraph()) |
| 362 .then((graph) => _precompileExecutables(graph.entrypoint, package)); | 366 .then((graph) => _precompileExecutables(graph.entrypoint, package)); |
| 363 }); | 367 }); |
| 364 } | 368 } |
| 365 | 369 |
| 366 /// Gets the path to the lock file for an activated cached package with | 370 /// Gets the path to the lock file for an activated cached package with |
| 367 /// [name]. | 371 /// [name]. |
| 368 String _getLockFilePath(String name) => | 372 String _getLockFilePath(String name) => |
| 369 p.join(_directory, name, "pubspec.lock"); | 373 p.join(_directory, name, "pubspec.lock"); |
| 370 | 374 |
| 375 /// Gets the path to the .packages file for an activated cached package with |
| 376 /// [name]. |
| 377 String _getPackagesFilePath(String name) => |
| 378 p.join(_directory, name, ".packages"); |
| 379 |
| 371 /// Shows the user a formatted list of globally activated packages. | 380 /// Shows the user a formatted list of globally activated packages. |
| 372 void listActivePackages() { | 381 void listActivePackages() { |
| 373 if (!dirExists(_directory)) return; | 382 if (!dirExists(_directory)) return; |
| 374 | 383 |
| 375 listDir(_directory).map(_loadPackageId).toList() | 384 listDir(_directory).map(_loadPackageId).toList() |
| 376 ..sort((id1, id2) => id1.name.compareTo(id2.name)) | 385 ..sort((id1, id2) => id1.name.compareTo(id2.name)) |
| 377 ..forEach((id) => log.message(_formatPackage(id))); | 386 ..forEach((id) => log.message(_formatPackage(id))); |
| 378 } | 387 } |
| 379 | 388 |
| 380 /// Returns the [PackageId] for the globally-activated package at [path]. | 389 /// Returns the [PackageId] for the globally-activated package at [path]. |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 } | 788 } |
| 780 | 789 |
| 781 /// Returns the value of the property named [name] in the bin stub script | 790 /// Returns the value of the property named [name] in the bin stub script |
| 782 /// [source]. | 791 /// [source]. |
| 783 String _binStubProperty(String source, String name) { | 792 String _binStubProperty(String source, String name) { |
| 784 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); | 793 var pattern = new RegExp(quoteRegExp(name) + r": ([a-zA-Z0-9_-]+)"); |
| 785 var match = pattern.firstMatch(source); | 794 var match = pattern.firstMatch(source); |
| 786 return match == null ? null : match[1]; | 795 return match == null ? null : match[1]; |
| 787 } | 796 } |
| 788 } | 797 } |
| OLD | NEW |