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

Side by Side Diff: utils/pub/entrypoint.dart

Issue 12171002: Tweak SDK constraint checking a bit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | utils/pub/git_source.dart » ('j') | utils/pub/git_source.dart » ('J')
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 library entrypoint; 5 library entrypoint;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'io.dart'; 8 import 'io.dart';
9 import 'lock_file.dart'; 9 import 'lock_file.dart';
10 import 'log.dart' as log; 10 import 'log.dart' as log;
11 import 'package.dart'; 11 import 'package.dart';
12 import 'pubspec.dart';
12 import 'sdk.dart' as sdk; 13 import 'sdk.dart' as sdk;
13 import 'system_cache.dart'; 14 import 'system_cache.dart';
14 import 'utils.dart'; 15 import 'utils.dart';
15 import 'version.dart'; 16 import 'version.dart';
16 import 'version_solver.dart'; 17 import 'version_solver.dart';
17 18
18 /// Pub operates over a directed graph of dependencies that starts at a root 19 /// Pub operates over a directed graph of dependencies that starts at a root
19 /// "entrypoint" package. This is typically the package where the current 20 /// "entrypoint" package. This is typically the package where the current
20 /// working directory is located. An entrypoint knows the [root] package it is 21 /// working directory is located. An entrypoint knows the [root] package it is
21 /// associated with and is responsible for managing the "packages" directory 22 /// associated with and is responsible for managing the "packages" directory
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return install(id); 137 return install(id);
137 })); 138 }));
138 }).then(_saveLockFile) 139 }).then(_saveLockFile)
139 .then(_installSelfReference) 140 .then(_installSelfReference)
140 .then(_linkSecondaryPackageDirs); 141 .then(_linkSecondaryPackageDirs);
141 } 142 }
142 143
143 /// Traverses the root's package dependency graph and loads each of the 144 /// Traverses the root's package dependency graph and loads each of the
144 /// reached packages. This should only be called after the lockfile has been 145 /// reached packages. This should only be called after the lockfile has been
145 /// successfully generated. 146 /// successfully generated.
146 Future<List<Package>> walkDependencies() { 147 Future<List<Pubspec>> walkDependencies() {
147 return loadLockFile().then((lockFile) { 148 return loadLockFile().then((lockFile) {
148 var group = new FutureGroup<Package>(); 149 var group = new FutureGroup<Pubspec>();
149 var visited = new Set<String>(); 150 var visited = new Set<String>();
150 151
151 // Include the root package in the results. 152 // Include the root package in the results.
152 group.add(new Future.immediate(root)); 153 group.add(new Future.immediate(root.pubspec));
153 154
154 visitPackage(Package package) { 155 visitPackage(Pubspec pubspec) {
155 for (var ref in package.dependencies) { 156 for (var ref in pubspec.dependencies) {
156 if (visited.contains(ref.name)) continue; 157 if (visited.contains(ref.name)) continue;
157 158
158 // Look up the concrete version. 159 // Look up the concrete version.
159 var id = lockFile.packages[ref.name]; 160 var id = lockFile.packages[ref.name];
160 161
161 visited.add(ref.name); 162 visited.add(ref.name);
162 var future = cache.describe(id); 163 var future = cache.describe(id);
163 group.add(future.then(visitPackage)); 164 group.add(future.then(visitPackage));
164 } 165 }
165 166
166 return package; 167 return pubspec;
167 } 168 }
168 169
169 visitPackage(root); 170 visitPackage(root.pubspec);
170 return group.future; 171 return group.future;
171 }); 172 });
172 } 173 }
173 174
174 /// Validates that the current Dart SDK version matches the SDK constraints 175 /// Validates that the current Dart SDK version matches the SDK constraints
175 /// of every package in the dependency graph. If a package's constraint does 176 /// of every package in the dependency graph. If a package's constraint does
176 /// not match, prints an error. 177 /// not match, prints an error.
177 Future validateSdkConstraints() { 178 Future validateSdkConstraints() {
178 return walkDependencies().then((packages) { 179 return walkDependencies().then((pubspecs) {
179 var errors = []; 180 var errors = [];
180 181
181 for (var package in packages) { 182 for (var pubspec in pubspecs) {
182 var sdkConstraint = package.pubspec.environment.sdkVersion; 183 var sdkConstraint = pubspec.environment.sdkVersion;
183 if (!sdkConstraint.allows(sdk.version)) { 184 if (!sdkConstraint.allows(sdk.version)) {
184 errors.add("- '${package.name}' requires ${sdkConstraint}"); 185 errors.add("- '${pubspec.name}' requires ${sdkConstraint}");
185 } 186 }
186 } 187 }
187 188
188 if (errors.length > 0) { 189 if (errors.length > 0) {
189 log.error("Some packages are not compatible with your SDK version " 190 log.error("Some packages are not compatible with your SDK version "
190 "${sdk.version}:\n" 191 "${sdk.version}:\n"
191 "${errors.join('\n')}\n\n" 192 "${errors.join('\n')}\n\n"
192 "You may be able to resolve this by upgrading to the latest Dart " 193 "You may be able to resolve this by upgrading to the latest Dart "
193 "SDK\n" 194 "SDK\n"
194 "or adding a version constraint to use an older version of a " 195 "or adding a version constraint to use an older version of a "
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 297
297 /// Creates a symlink to the `packages` directory in [dir] if none exists. 298 /// Creates a symlink to the `packages` directory in [dir] if none exists.
298 Future _linkSecondaryPackageDir(String dir) { 299 Future _linkSecondaryPackageDir(String dir) {
299 var to = join(dir, 'packages'); 300 var to = join(dir, 'packages');
300 return exists(to).then((exists) { 301 return exists(to).then((exists) {
301 if (exists) return; 302 if (exists) return;
302 return createSymlink(path, to); 303 return createSymlink(path, to);
303 }); 304 });
304 } 305 }
305 } 306 }
OLDNEW
« no previous file with comments | « no previous file | utils/pub/git_source.dart » ('j') | utils/pub/git_source.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698