OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:barback/barback.dart'; | 8 import 'package:barback/barback.dart'; |
9 import 'package:package_config/packages_file.dart' as packages_file; | 9 import 'package:package_config/packages_file.dart' as packages_file; |
10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 /// dependencies. | 83 /// dependencies. |
84 /// | 84 /// |
85 /// Throws a [DataError] if the `.packages` file isn't up-to-date relative to | 85 /// Throws a [DataError] if the `.packages` file isn't up-to-date relative to |
86 /// the pubspec and the lockfile. | 86 /// the pubspec and the lockfile. |
87 PackageGraph get packageGraph { | 87 PackageGraph get packageGraph { |
88 if (_packageGraph != null) return _packageGraph; | 88 if (_packageGraph != null) return _packageGraph; |
89 | 89 |
90 assertUpToDate(); | 90 assertUpToDate(); |
91 var packages = new Map.fromIterable(lockFile.packages.values, | 91 var packages = new Map.fromIterable(lockFile.packages.values, |
92 key: (id) => id.name, | 92 key: (id) => id.name, |
93 value: (id) => cache.sources.load(id)); | 93 value: (id) => cache.load(id)); |
94 packages[root.name] = root; | 94 packages[root.name] = root; |
95 | 95 |
96 _packageGraph = new PackageGraph(this, lockFile, packages); | 96 _packageGraph = new PackageGraph(this, lockFile, packages); |
97 return _packageGraph; | 97 return _packageGraph; |
98 } | 98 } |
99 PackageGraph _packageGraph; | 99 PackageGraph _packageGraph; |
100 | 100 |
101 /// The path to the entrypoint's "packages" directory. | 101 /// The path to the entrypoint's "packages" directory. |
102 String get packagesDir => root.path('packages'); | 102 String get packagesDir => root.path('packages'); |
103 | 103 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 /// this is an upgrade or downgrade, all transitive dependencies are shown in | 162 /// this is an upgrade or downgrade, all transitive dependencies are shown in |
163 /// the report. Otherwise, only dependencies that were changed are shown. If | 163 /// the report. Otherwise, only dependencies that were changed are shown. If |
164 /// [dryRun] is `true`, no physical changes are made. | 164 /// [dryRun] is `true`, no physical changes are made. |
165 /// | 165 /// |
166 /// If [precompile] is `true` (the default), this snapshots dependencies' | 166 /// If [precompile] is `true` (the default), this snapshots dependencies' |
167 /// executables and runs transformers on transformed dependencies. | 167 /// executables and runs transformers on transformed dependencies. |
168 /// | 168 /// |
169 /// Updates [lockFile] and [packageRoot] accordingly. | 169 /// Updates [lockFile] and [packageRoot] accordingly. |
170 Future acquireDependencies(SolveType type, {List<String> useLatest, | 170 Future acquireDependencies(SolveType type, {List<String> useLatest, |
171 bool dryRun: false, bool precompile: true}) async { | 171 bool dryRun: false, bool precompile: true}) async { |
172 var result = await resolveVersions(type, cache.sources, root, | 172 var result = await resolveVersions(type, cache, root, |
173 lockFile: lockFile, useLatest: useLatest); | 173 lockFile: lockFile, useLatest: useLatest); |
174 if (!result.succeeded) throw result.error; | 174 if (!result.succeeded) throw result.error; |
175 | 175 |
176 result.showReport(type); | 176 result.showReport(type); |
177 | 177 |
178 if (dryRun) { | 178 if (dryRun) { |
179 result.summarizeChanges(type, dryRun: dryRun); | 179 result.summarizeChanges(type, dryRun: dryRun); |
180 return; | 180 return; |
181 } | 181 } |
182 | 182 |
(...skipping 27 matching lines...) Expand all Loading... |
210 _deletePrecompiledDependencies( | 210 _deletePrecompiledDependencies( |
211 _dependenciesToPrecompile(changed: result.changedPackages)); | 211 _dependenciesToPrecompile(changed: result.changedPackages)); |
212 _deleteExecutableSnapshots(changed: result.changedPackages); | 212 _deleteExecutableSnapshots(changed: result.changedPackages); |
213 } | 213 } |
214 } catch (error, stackTrace) { | 214 } catch (error, stackTrace) { |
215 // Just log exceptions here. Since the method is just about acquiring | 215 // Just log exceptions here. Since the method is just about acquiring |
216 // dependencies, it shouldn't fail unless that fails. | 216 // dependencies, it shouldn't fail unless that fails. |
217 log.exception(error, stackTrace); | 217 log.exception(error, stackTrace); |
218 } | 218 } |
219 | 219 |
220 writeTextFile(packagesFile, lockFile.packagesFile(root.name)); | 220 writeTextFile(packagesFile, lockFile.packagesFile(cache, root.name)); |
221 } | 221 } |
222 | 222 |
223 /// Precompile any transformed dependencies of the entrypoint. | 223 /// Precompile any transformed dependencies of the entrypoint. |
224 /// | 224 /// |
225 /// If [changed] is passed, only dependencies whose contents might be changed | 225 /// If [changed] is passed, only dependencies whose contents might be changed |
226 /// if one of the given packages changes will be recompiled. | 226 /// if one of the given packages changes will be recompiled. |
227 Future _precompileDependencies({Iterable<String> changed}) async { | 227 Future _precompileDependencies({Iterable<String> changed}) async { |
228 if (changed != null) changed = changed.toSet(); | 228 if (changed != null) changed = changed.toSet(); |
229 | 229 |
230 var dependenciesToPrecompile = _dependenciesToPrecompile(changed: changed); | 230 var dependenciesToPrecompile = _dependenciesToPrecompile(changed: changed); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 } | 425 } |
426 | 426 |
427 /// Makes sure the package at [id] is locally available. | 427 /// Makes sure the package at [id] is locally available. |
428 /// | 428 /// |
429 /// This automatically downloads the package to the system-wide cache as well | 429 /// This automatically downloads the package to the system-wide cache as well |
430 /// if it requires network access to retrieve (specifically, if the package's | 430 /// if it requires network access to retrieve (specifically, if the package's |
431 /// source is a [CachedSource]). | 431 /// source is a [CachedSource]). |
432 Future _get(PackageId id) async { | 432 Future _get(PackageId id) async { |
433 if (id.isRoot) return; | 433 if (id.isRoot) return; |
434 | 434 |
435 var source = cache.sources[id.source]; | 435 var source = cache.source(id.source); |
436 if (!_packageSymlinks) { | 436 if (!_packageSymlinks) { |
437 if (source is CachedSource) await source.downloadToSystemCache(id); | 437 if (source is CachedSource) await source.downloadToSystemCache(id); |
438 return; | 438 return; |
439 } | 439 } |
440 | 440 |
441 var packageDir = p.join(packagesDir, id.name); | 441 var packageDir = p.join(packagesDir, id.name); |
442 if (entryExists(packageDir)) deleteEntry(packageDir); | 442 if (entryExists(packageDir)) deleteEntry(packageDir); |
443 await source.get(id, packageDir); | 443 await source.get(id, packageDir); |
444 } | 444 } |
445 | 445 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 if (!root.immediateDependencies.every(_isDependencyUpToDate)) { | 509 if (!root.immediateDependencies.every(_isDependencyUpToDate)) { |
510 dataError('The pubspec.yaml file has changed since the pubspec.lock ' | 510 dataError('The pubspec.yaml file has changed since the pubspec.lock ' |
511 'file was generated, please run "pub get" again.'); | 511 'file was generated, please run "pub get" again.'); |
512 } | 512 } |
513 | 513 |
514 var overrides = root.dependencyOverrides.map((dep) => dep.name).toSet(); | 514 var overrides = root.dependencyOverrides.map((dep) => dep.name).toSet(); |
515 | 515 |
516 // Check that uncached dependencies' pubspecs are also still satisfied, | 516 // Check that uncached dependencies' pubspecs are also still satisfied, |
517 // since they're mutable and may have changed since the last get. | 517 // since they're mutable and may have changed since the last get. |
518 for (var id in lockFile.packages.values) { | 518 for (var id in lockFile.packages.values) { |
519 var source = cache.sources[id.source]; | 519 var source = cache.source(id.source); |
520 if (source is CachedSource) continue; | 520 if (source is CachedSource) continue; |
521 | 521 |
522 try { | 522 try { |
523 if (cache.sources.load(id).dependencies.every((dep) => | 523 if (cache.load(id).dependencies.every((dep) => |
524 overrides.contains(dep.name) || _isDependencyUpToDate(dep))) { | 524 overrides.contains(dep.name) || _isDependencyUpToDate(dep))) { |
525 continue; | 525 continue; |
526 } | 526 } |
527 } on FileException { | 527 } on FileException { |
528 // If we can't load the pubpsec, the user needs to re-run "pub get". | 528 // If we can't load the pubpsec, the user needs to re-run "pub get". |
529 } | 529 } |
530 | 530 |
531 dataError('${p.join(source.getDirectory(id), 'pubspec.yaml')} has ' | 531 dataError('${p.join(source.getDirectory(id), 'pubspec.yaml')} has ' |
532 'changed since the pubspec.lock file was generated, please run "pub ' | 532 'changed since the pubspec.lock file was generated, please run "pub ' |
533 'get" again.'); | 533 'get" again.'); |
(...skipping 20 matching lines...) Expand all Loading... |
554 /// Determines whether all of the packages in the lockfile are already | 554 /// Determines whether all of the packages in the lockfile are already |
555 /// installed and available. | 555 /// installed and available. |
556 bool _arePackagesAvailable() { | 556 bool _arePackagesAvailable() { |
557 return lockFile.packages.values.every((package) { | 557 return lockFile.packages.values.every((package) { |
558 var source = cache.sources[package.source]; | 558 var source = cache.sources[package.source]; |
559 if (source is UnknownSource) return false; | 559 if (source is UnknownSource) return false; |
560 | 560 |
561 // We only care about cached sources. Uncached sources aren't "installed". | 561 // We only care about cached sources. Uncached sources aren't "installed". |
562 // If one of those is missing, we want to show the user the file not | 562 // If one of those is missing, we want to show the user the file not |
563 // found error later since installing won't accomplish anything. | 563 // found error later since installing won't accomplish anything. |
564 if (source is! CachedSource) return true; | 564 var boundSource = cache.source(package.source); |
| 565 if (boundSource is! CachedSource) return true; |
565 | 566 |
566 // Get the directory. | 567 // Get the directory. |
567 var dir = source.getDirectory(package); | 568 var dir = boundSource.getDirectory(package); |
568 // See if the directory is there and looks like a package. | 569 // See if the directory is there and looks like a package. |
569 return dirExists(dir) && fileExists(p.join(dir, "pubspec.yaml")); | 570 return dirExists(dir) && fileExists(p.join(dir, "pubspec.yaml")); |
570 }); | 571 }); |
571 } | 572 } |
572 | 573 |
573 /// Determines whether or not the `.packages` file is out of date with respect | 574 /// Determines whether or not the `.packages` file is out of date with respect |
574 /// to the lockfile. | 575 /// to the lockfile. |
575 /// | 576 /// |
576 /// This will be `false` if the packages file contains dependencies that are | 577 /// This will be `false` if the packages file contains dependencies that are |
577 /// not in the lockfile or that don't match what's in there. | 578 /// not in the lockfile or that don't match what's in there. |
578 bool _isPackagesFileUpToDate() { | 579 bool _isPackagesFileUpToDate() { |
579 var packages = packages_file.parse( | 580 var packages = packages_file.parse( |
580 new File(packagesFile).readAsBytesSync(), | 581 new File(packagesFile).readAsBytesSync(), |
581 p.toUri(packagesFile)); | 582 p.toUri(packagesFile)); |
582 | 583 |
583 return lockFile.packages.values.every((lockFileId) { | 584 return lockFile.packages.values.every((lockFileId) { |
584 var source = cache.sources[lockFileId.source]; | 585 var source = cache.source(lockFileId.source); |
585 | 586 |
586 // It's very unlikely that the lockfile is invalid here, but it's not | 587 // It's very unlikely that the lockfile is invalid here, but it's not |
587 // impossible—for example, the user may have a very old application | 588 // impossible—for example, the user may have a very old application |
588 // package with a checked-in lockfile that's newer than the pubspec, but | 589 // package with a checked-in lockfile that's newer than the pubspec, but |
589 // that contains sdk dependencies. | 590 // that contains sdk dependencies. |
590 if (source == null) return false; | 591 if (source.source is UnknownSource) return false; |
591 | 592 |
592 var packagesFileUri = packages[lockFileId.name]; | 593 var packagesFileUri = packages[lockFileId.name]; |
593 if (packagesFileUri == null) return false; | 594 if (packagesFileUri == null) return false; |
594 | 595 |
595 // Pub only generates "file:" and relative URIs. | 596 // Pub only generates "file:" and relative URIs. |
596 if (packagesFileUri.scheme != 'file' && | 597 if (packagesFileUri.scheme != 'file' && |
597 packagesFileUri.scheme.isNotEmpty) { | 598 packagesFileUri.scheme.isNotEmpty) { |
598 return false; | 599 return false; |
599 } | 600 } |
600 | 601 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 /// If [packageSymlinks] is true, creates a symlink to the "packages" | 683 /// If [packageSymlinks] is true, creates a symlink to the "packages" |
683 /// directory in [dir]. | 684 /// directory in [dir]. |
684 /// | 685 /// |
685 /// Otherwise, deletes a "packages" directories in [dir] if one exists. | 686 /// Otherwise, deletes a "packages" directories in [dir] if one exists. |
686 void _linkOrDeleteSecondaryPackageDir(String dir) { | 687 void _linkOrDeleteSecondaryPackageDir(String dir) { |
687 var symlink = p.join(dir, 'packages'); | 688 var symlink = p.join(dir, 'packages'); |
688 if (entryExists(symlink)) deleteEntry(symlink); | 689 if (entryExists(symlink)) deleteEntry(symlink); |
689 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); | 690 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); |
690 } | 691 } |
691 } | 692 } |
OLD | NEW |