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; |
11 import 'package:pub_semver/pub_semver.dart'; | 11 import 'package:pub_semver/pub_semver.dart'; |
12 | 12 |
13 import 'barback/asset_environment.dart'; | 13 import 'barback/asset_environment.dart'; |
14 import 'exceptions.dart'; | 14 import 'exceptions.dart'; |
| 15 import 'flutter.dart' as flutter; |
15 import 'io.dart'; | 16 import 'io.dart'; |
16 import 'lock_file.dart'; | 17 import 'lock_file.dart'; |
17 import 'log.dart' as log; | 18 import 'log.dart' as log; |
18 import 'package.dart'; | 19 import 'package.dart'; |
19 import 'package_graph.dart'; | 20 import 'package_graph.dart'; |
20 import 'sdk.dart' as sdk; | 21 import 'sdk.dart' as sdk; |
21 import 'solver/version_solver.dart'; | 22 import 'solver/version_solver.dart'; |
22 import 'source/cached.dart'; | 23 import 'source/cached.dart'; |
23 import 'source/unknown.dart'; | 24 import 'source/unknown.dart'; |
24 import 'system_cache.dart'; | 25 import 'system_cache.dart'; |
25 import 'utils.dart'; | 26 import 'utils.dart'; |
26 | 27 |
27 /// A RegExp to match the SDK constraint in a lock file. | 28 /// A RegExp to match the Dart SDK constraint in a lock file. |
28 final _sdkConstraint = new RegExp(r'^sdk: "?([^"]*)"?$', multiLine: true); | 29 /// |
| 30 /// This matches both the old-style constraint: |
| 31 /// |
| 32 /// ```yaml |
| 33 /// sdk: ">=1.2.3 <2.0.0" |
| 34 /// ``` |
| 35 /// |
| 36 /// and the new-style constraint: |
| 37 /// |
| 38 /// ```yaml |
| 39 /// sdks: |
| 40 /// dart: ">=1.2.3 <2.0.0" |
| 41 /// ``` |
| 42 final _dartSdkConstraint = |
| 43 new RegExp(r'^( dart|sdk): "?([^"]*)"?$', multiLine: true); |
| 44 |
| 45 /// A RegExp to match the Flutter SDK constraint in a lock file. |
| 46 final _flutterSdkConstraint = |
| 47 new RegExp(r'^ flutter: "?([^"]*)"?$', multiLine: true); |
29 | 48 |
30 /// The context surrounding the root package pub is operating on. | 49 /// The context surrounding the root package pub is operating on. |
31 /// | 50 /// |
32 /// Pub operates over a directed graph of dependencies that starts at a root | 51 /// Pub operates over a directed graph of dependencies that starts at a root |
33 /// "entrypoint" package. This is typically the package where the current | 52 /// "entrypoint" package. This is typically the package where the current |
34 /// working directory is located. An entrypoint knows the [root] package it is | 53 /// working directory is located. An entrypoint knows the [root] package it is |
35 /// associated with and is responsible for managing the "packages" directory | 54 /// associated with and is responsible for managing the "packages" directory |
36 /// for it. | 55 /// for it. |
37 /// | 56 /// |
38 /// That directory contains symlinks to all packages used by an app. These links | 57 /// That directory contains symlinks to all packages used by an app. These links |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 if (_isPackagesFileUpToDate()) { | 501 if (_isPackagesFileUpToDate()) { |
483 touch(packagesFile); | 502 touch(packagesFile); |
484 } else { | 503 } else { |
485 dataError('The pubspec.lock file has changed since the .packages file ' | 504 dataError('The pubspec.lock file has changed since the .packages file ' |
486 'was generated, please run "pub get" again.'); | 505 'was generated, please run "pub get" again.'); |
487 } | 506 } |
488 } else if (touchedLockFile) { | 507 } else if (touchedLockFile) { |
489 touch(packagesFile); | 508 touch(packagesFile); |
490 } | 509 } |
491 | 510 |
492 var sdkConstraint = _sdkConstraint.firstMatch(lockFileText); | 511 var dartSdkConstraint = _dartSdkConstraint.firstMatch(lockFileText); |
493 if (sdkConstraint != null) { | 512 if (dartSdkConstraint != null) { |
494 var parsedConstraint = new VersionConstraint.parse(sdkConstraint[1]); | 513 var parsedConstraint = new VersionConstraint.parse(dartSdkConstraint[2]); |
495 if (!parsedConstraint.allows(sdk.version)) { | 514 if (!parsedConstraint.allows(sdk.version)) { |
496 dataError("Dart ${sdk.version} is incompatible with your dependencies' " | 515 dataError("Dart ${sdk.version} is incompatible with your dependencies' " |
497 "SDK constraints. Please run \"pub get\" again."); | 516 "SDK constraints. Please run \"pub get\" again."); |
498 } | 517 } |
499 } | 518 } |
| 519 |
| 520 // Don't complain if there's a Flutter constraint but Flutter is |
| 521 // unavailable. Flutter being unavailable just means that we aren't running |
| 522 // from within the `flutter` executable, and we want users to be able to |
| 523 // `pub run` non-Flutter tools even in a Flutter app. |
| 524 var flutterSdkConstraint = _flutterSdkConstraint.firstMatch(lockFileText); |
| 525 if (flutterSdkConstraint != null && flutter.isAvailable) { |
| 526 var parsedConstraint = new VersionConstraint.parse( |
| 527 flutterSdkConstraint[1]); |
| 528 |
| 529 if (!parsedConstraint.allows(flutter.version)) { |
| 530 dataError("Flutter ${flutter.version} is incompatible with your " |
| 531 "dependencies' SDK constraints. Please run \"pub get\" again."); |
| 532 } |
| 533 } |
500 } | 534 } |
501 | 535 |
502 /// Determines whether or not the lockfile is out of date with respect to the | 536 /// Determines whether or not the lockfile is out of date with respect to the |
503 /// pubspec. | 537 /// pubspec. |
504 /// | 538 /// |
505 /// If any mutable pubspec contains dependencies that are not in the lockfile | 539 /// If any mutable pubspec contains dependencies that are not in the lockfile |
506 /// or that don't match what's in there, this will throw a [DataError] | 540 /// or that don't match what's in there, this will throw a [DataError] |
507 /// describing the issue. | 541 /// describing the issue. |
508 void _assertLockFileUpToDate() { | 542 void _assertLockFileUpToDate() { |
509 if (!root.immediateDependencies.every(_isDependencyUpToDate)) { | 543 if (!root.immediateDependencies.every(_isDependencyUpToDate)) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 /// If [packageSymlinks] is true, creates a symlink to the "packages" | 707 /// If [packageSymlinks] is true, creates a symlink to the "packages" |
674 /// directory in [dir]. | 708 /// directory in [dir]. |
675 /// | 709 /// |
676 /// Otherwise, deletes a "packages" directories in [dir] if one exists. | 710 /// Otherwise, deletes a "packages" directories in [dir] if one exists. |
677 void _linkOrDeleteSecondaryPackageDir(String dir) { | 711 void _linkOrDeleteSecondaryPackageDir(String dir) { |
678 var symlink = p.join(dir, 'packages'); | 712 var symlink = p.join(dir, 'packages'); |
679 if (entryExists(symlink)) deleteEntry(symlink); | 713 if (entryExists(symlink)) deleteEntry(symlink); |
680 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); | 714 if (_packageSymlinks) createSymlink(packagesDir, symlink, relative: true); |
681 } | 715 } |
682 } | 716 } |
OLD | NEW |