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

Side by Side Diff: lib/src/validator/sdk_constraint.dart

Issue 2172883002: Add validation for Flutter constraints. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | test/validator/sdk_constraint_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 6
7 import 'package:pub_semver/pub_semver.dart';
8
7 import '../entrypoint.dart'; 9 import '../entrypoint.dart';
8 import '../validator.dart'; 10 import '../validator.dart';
9 11
12 /// The range of all Dart SDK versions that don't support Flutter SDK
13 /// constraints.
14 final _preFlutterSupport = new VersionConstraint.parse("<1.19.0");
15
10 /// A validator that validates that a package's SDK constraint doesn't use the 16 /// A validator that validates that a package's SDK constraint doesn't use the
11 /// "^" syntax. 17 /// "^" syntax.
12 class SdkConstraintValidator extends Validator { 18 class SdkConstraintValidator extends Validator {
13 SdkConstraintValidator(Entrypoint entrypoint) 19 SdkConstraintValidator(Entrypoint entrypoint)
14 : super(entrypoint); 20 : super(entrypoint);
15 21
16 Future validate() async { 22 Future validate() async {
17 var constraint = entrypoint.root.pubspec.dartSdkConstraint; 23 var dartConstraint = entrypoint.root.pubspec.dartSdkConstraint;
18 if (!constraint.toString().startsWith("^")) return; 24 if (dartConstraint.toString().startsWith("^")) {
25 errors.add(
26 "^ version constraints aren't allowed for SDK constraints since "
27 "older versions of pub don't support them.\n"
28 "Expand it manually instead:\n"
29 "\n"
30 "environment:\n"
31 " sdk: \">=${dartConstraint.min} <${dartConstraint.max}\"");
32 }
19 33
20 errors.add( 34 if (entrypoint.root.pubspec.flutterSdkConstraint != null &&
21 "^ version constraints aren't allowed for SDK constraints since " 35 dartConstraint.allowsAny(_preFlutterSupport)) {
22 "older versions of pub don't support them.\n" 36 var newDartConstraint = dartConstraint.difference(_preFlutterSupport);
23 "Expand it manually instead:\n" 37 if (newDartConstraint.isEmpty ||
24 "\n" 38 newDartConstraint ==
25 "environment:\n" 39 VersionConstraint.any.difference(_preFlutterSupport)) {
26 " sdk: \">=${constraint.min} <${constraint.max}\""); 40 newDartConstraint = new VersionConstraint.parse("<2.0.0")
41 .difference(_preFlutterSupport);
42 }
43
44 errors.add(
45 "Older versions of pub don't support Flutter SDK constraints.\n"
46 "Make sure your SDK constraint excludes those old versions:\n"
47 "\n"
48 "environment:\n"
49 " sdk: \"$newDartConstraint\"");
50 }
27 } 51 }
28 } 52 }
OLDNEW
« no previous file with comments | « no previous file | test/validator/sdk_constraint_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698