Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Unified Diff: lib/src/entrypoint.dart

Issue 2165423002: Add support for Flutter SDK constraints. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/cached_package.dart ('k') | lib/src/flutter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/entrypoint.dart
diff --git a/lib/src/entrypoint.dart b/lib/src/entrypoint.dart
index 360a6ca5d0c44eba2cf382b05ae2fb5f640d4f45..cc58a3e3ed214e8278c9390c7a4091a890eb2c0c 100644
--- a/lib/src/entrypoint.dart
+++ b/lib/src/entrypoint.dart
@@ -12,6 +12,7 @@ import 'package:pub_semver/pub_semver.dart';
import 'barback/asset_environment.dart';
import 'exceptions.dart';
+import 'flutter.dart' as flutter;
import 'io.dart';
import 'lock_file.dart';
import 'log.dart' as log;
@@ -24,8 +25,26 @@ import 'source/unknown.dart';
import 'system_cache.dart';
import 'utils.dart';
-/// A RegExp to match the SDK constraint in a lock file.
-final _sdkConstraint = new RegExp(r'^sdk: "?([^"]*)"?$', multiLine: true);
+/// A RegExp to match the Dart SDK constraint in a lock file.
+///
+/// This matches both the old-style constraint:
+///
+/// ```yaml
+/// sdk: ">=1.2.3 <2.0.0"
+/// ```
+///
+/// and the new-style constraint:
+///
+/// ```yaml
+/// sdks:
+/// dart: ">=1.2.3 <2.0.0"
+/// ```
+final _dartSdkConstraint =
+ new RegExp(r'^( dart|sdk): "?([^"]*)"?$', multiLine: true);
+
+/// A RegExp to match the Flutter SDK constraint in a lock file.
+final _flutterSdkConstraint =
+ new RegExp(r'^ flutter: "?([^"]*)"?$', multiLine: true);
/// The context surrounding the root package pub is operating on.
///
@@ -489,14 +508,29 @@ class Entrypoint {
touch(packagesFile);
}
- var sdkConstraint = _sdkConstraint.firstMatch(lockFileText);
- if (sdkConstraint != null) {
- var parsedConstraint = new VersionConstraint.parse(sdkConstraint[1]);
+ var dartSdkConstraint = _dartSdkConstraint.firstMatch(lockFileText);
+ if (dartSdkConstraint != null) {
+ var parsedConstraint = new VersionConstraint.parse(dartSdkConstraint[2]);
if (!parsedConstraint.allows(sdk.version)) {
dataError("Dart ${sdk.version} is incompatible with your dependencies' "
"SDK constraints. Please run \"pub get\" again.");
}
}
+
+ // Don't complain if there's a Flutter constraint but Flutter is
+ // unavailable. Flutter being unavailable just means that we aren't running
+ // from within the `flutter` executable, and we want users to be able to
+ // `pub run` non-Flutter tools even in a Flutter app.
+ var flutterSdkConstraint = _flutterSdkConstraint.firstMatch(lockFileText);
+ if (flutterSdkConstraint != null && flutter.isAvailable) {
+ var parsedConstraint = new VersionConstraint.parse(
+ flutterSdkConstraint[1]);
+
+ if (!parsedConstraint.allows(flutter.version)) {
+ dataError("Flutter ${flutter.version} is incompatible with your "
+ "dependencies' SDK constraints. Please run \"pub get\" again.");
+ }
+ }
}
/// Determines whether or not the lockfile is out of date with respect to the
« no previous file with comments | « lib/src/cached_package.dart ('k') | lib/src/flutter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698