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

Side by Side Diff: lib/src/validator/dependency.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 unified diff | Download patch
« no previous file with comments | « lib/src/solver/version_solver.dart ('k') | lib/src/validator/sdk_constraint.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) 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 6
7 import 'package:pub_semver/pub_semver.dart'; 7 import 'package:pub_semver/pub_semver.dart';
8 8
9 import '../entrypoint.dart'; 9 import '../entrypoint.dart';
10 import '../log.dart' as log; 10 import '../log.dart' as log;
(...skipping 11 matching lines...) Expand all
22 /// The range of all pub versions that do support `^` version constraints. 22 /// The range of all pub versions that do support `^` version constraints.
23 /// 23 ///
24 /// This is intersected with the user's SDK constraint to provide a suggested 24 /// This is intersected with the user's SDK constraint to provide a suggested
25 /// constraint. 25 /// constraint.
26 final _postCaretPubVersions = new VersionConstraint.parse("^1.8.0"); 26 final _postCaretPubVersions = new VersionConstraint.parse("^1.8.0");
27 27
28 /// A validator that validates a package's dependencies. 28 /// A validator that validates a package's dependencies.
29 class DependencyValidator extends Validator { 29 class DependencyValidator extends Validator {
30 /// Whether the SDK constraint guarantees that `^` version constraints are 30 /// Whether the SDK constraint guarantees that `^` version constraints are
31 /// safe. 31 /// safe.
32 bool get _caretAllowed => entrypoint.root.pubspec.environment.sdkVersion 32 bool get _caretAllowed => entrypoint.root.pubspec.dartSdkConstraint
33 .intersect(_preCaretPubVersions).isEmpty; 33 .intersect(_preCaretPubVersions).isEmpty;
34 34
35 DependencyValidator(Entrypoint entrypoint) 35 DependencyValidator(Entrypoint entrypoint)
36 : super(entrypoint); 36 : super(entrypoint);
37 37
38 Future validate() async { 38 Future validate() async {
39 var caretDeps = []; 39 var caretDeps = [];
40 40
41 for (var dependency in entrypoint.root.pubspec.dependencies) { 41 for (var dependency in entrypoint.root.pubspec.dependencies) {
42 if (dependency.source is! HostedSource) { 42 if (dependency.source is! HostedSource) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 'dependencies:\n' 167 'dependencies:\n'
168 ' ${dep.name}: $constraint\n' 168 ' ${dep.name}: $constraint\n'
169 '\n' 169 '\n'
170 'Without an upper bound, you\'re promising to support ' 170 'Without an upper bound, you\'re promising to support '
171 '${log.bold("all")} future versions of ${dep.name}.'); 171 '${log.bold("all")} future versions of ${dep.name}.');
172 } 172 }
173 173
174 /// Emits an error for any version constraints that use `^` without an 174 /// Emits an error for any version constraints that use `^` without an
175 /// appropriate SDK constraint. 175 /// appropriate SDK constraint.
176 void _errorAboutCaretConstraints(List<PackageDep> caretDeps) { 176 void _errorAboutCaretConstraints(List<PackageDep> caretDeps) {
177 var newSdkConstraint = entrypoint.root.pubspec.environment.sdkVersion 177 var newSdkConstraint = entrypoint.root.pubspec.dartSdkConstraint
178 .intersect(_postCaretPubVersions); 178 .intersect(_postCaretPubVersions);
179 179
180 if (newSdkConstraint.isEmpty) newSdkConstraint = _postCaretPubVersions; 180 if (newSdkConstraint.isEmpty) newSdkConstraint = _postCaretPubVersions;
181 181
182 var buffer = new StringBuffer( 182 var buffer = new StringBuffer(
183 "Older versions of pub don't support ^ version constraints.\n" 183 "Older versions of pub don't support ^ version constraints.\n"
184 "Make sure your SDK constraint excludes those old versions:\n" 184 "Make sure your SDK constraint excludes those old versions:\n"
185 "\n" 185 "\n"
186 "environment:\n" 186 "environment:\n"
187 " sdk: \"$newSdkConstraint\"\n" 187 " sdk: \"$newSdkConstraint\"\n"
(...skipping 17 matching lines...) Expand all
205 errors.add(buffer.toString().trim()); 205 errors.add(buffer.toString().trim());
206 } 206 }
207 207
208 /// Returns the suggested version constraint for a dependency that was tested 208 /// Returns the suggested version constraint for a dependency that was tested
209 /// against [version]. 209 /// against [version].
210 String _constraintForVersion(Version version) { 210 String _constraintForVersion(Version version) {
211 if (_caretAllowed) return "^$version"; 211 if (_caretAllowed) return "^$version";
212 return '">=$version <${version.nextBreaking}"'; 212 return '">=$version <${version.nextBreaking}"';
213 } 213 }
214 } 214 }
OLDNEW
« no previous file with comments | « lib/src/solver/version_solver.dart ('k') | lib/src/validator/sdk_constraint.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698