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

Side by Side Diff: lib/src/pubspec.dart

Issue 1556043006: Don't choke on dev transformers from path deps. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Created 4 years, 11 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/transformer/gets_and_upgrades_a_package_with_a_dev_transformer_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) 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 pub.pubspec; 5 library pub.pubspec;
6 6
7 import 'package:path/path.dart' as path; 7 import 'package:path/path.dart' as path;
8 import 'package:pub_semver/pub_semver.dart'; 8 import 'package:pub_semver/pub_semver.dart';
9 import 'package:source_span/source_span.dart'; 9 import 'package:source_span/source_span.dart';
10 import 'package:yaml/yaml.dart'; 10 import 'package:yaml/yaml.dart';
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 183 }
184 } 184 }
185 185
186 var config = _wrapSpanFormatException('transformer config', () { 186 var config = _wrapSpanFormatException('transformer config', () {
187 return new TransformerConfig.parse( 187 return new TransformerConfig.parse(
188 libraryNode.value, libraryNode.span, 188 libraryNode.value, libraryNode.span,
189 configurationNode); 189 configurationNode);
190 }); 190 });
191 191
192 var package = config.id.package; 192 var package = config.id.package;
193 if (package != name && 193 if (package != name && !config.id.isBuiltInTransformer &&
194 !config.id.isBuiltInTransformer && 194 !_hasDependency(package)) {
195 !dependencies.any((ref) => ref.name == package) &&
196 !devDependencies.any((ref) => ref.name == package) &&
197 !dependencyOverrides.any((ref) => ref.name == package)) {
198 _error('"$package" is not a dependency.', 195 _error('"$package" is not a dependency.',
199 libraryNode.span); 196 libraryNode.span);
200 } 197 }
201 198
202 return config; 199 return config;
203 }).toSet(); 200 }).toSet();
204 }).toList(); 201 }).toList();
205 202
206 return _transformers; 203 return _transformers;
207 } 204 }
208 List<Set<TransformerConfig>> _transformers; 205 List<Set<TransformerConfig>> _transformers;
209 206
207 /// Returns whether this pubspec has any kind of dependency on [package].
208 ///
209 /// This explicitly avoids calling [_parseDependencies] because parsing dev
210 /// dependencies can fail for a hosted package's pubspec (e.g. if that package
211 /// has a relative path dev dependency).
212 bool _hasDependency(String package) {
213 return [
214 'dependencies', 'dev_dependencies', 'dependency_overrides'
215 ].any((field) {
216 var map = fields[field];
217 if (map == null) return false;
218
219 if (map is! Map) {
220 _error('"$field" field must be a map.', fields.nodes[field].span);
221 }
222
223 return map.containsKey(package);
224 });
225 }
226
210 /// The environment-related metadata. 227 /// The environment-related metadata.
211 PubspecEnvironment get environment { 228 PubspecEnvironment get environment {
212 if (_environment != null) return _environment; 229 if (_environment != null) return _environment;
213 230
214 var yaml = fields['environment']; 231 var yaml = fields['environment'];
215 if (yaml == null) { 232 if (yaml == null) {
216 _environment = new PubspecEnvironment(VersionConstraint.any); 233 _environment = new PubspecEnvironment(VersionConstraint.any);
217 return _environment; 234 return _environment;
218 } 235 }
219 236
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 specNode.nodes.keys.single.span); 506 specNode.nodes.keys.single.span);
490 } 507 }
491 508
492 descriptionNode = specNode.nodes[sourceName]; 509 descriptionNode = specNode.nodes[sourceName];
493 } else { 510 } else {
494 _error('A dependency specification must be a string or a mapping.', 511 _error('A dependency specification must be a string or a mapping.',
495 specNode.span); 512 specNode.span);
496 } 513 }
497 514
498 // Let the source validate the description. 515 // Let the source validate the description.
499 var ref = _wrapFormatException('description', descriptionNode.span, () {
500 var pubspecPath; 516 var pubspecPath;
Bob Nystrom 2016/01/04 23:46:44 Fix the indentation.
nweiz 2016/01/05 01:57:13 Oops, this whole change shouldn't have made it in.
501 if (_location != null && _isFileUri(_location)) { 517 if (_location != null && _isFileUri(_location)) {
502 pubspecPath = path.fromUri(_location); 518 pubspecPath = path.fromUri(_location);
503 } 519 }
504 520
505 return _sources[sourceName].parseRef(name, descriptionNode.value, 521 var ref = _sources[sourceName].parseRef(name, descriptionNode.value,
506 containingPath: pubspecPath); 522 containingPath: pubspecPath);
507 });
508 523
509 dependencies.add(ref.withConstraint(versionConstraint)); 524 dependencies.add(ref.withConstraint(versionConstraint));
510 }); 525 });
511 526
512 return dependencies; 527 return dependencies;
513 } 528 }
514 529
515 /// Parses [node] to a [VersionConstraint]. 530 /// Parses [node] to a [VersionConstraint].
516 VersionConstraint _parseVersionConstraint(YamlNode node) { 531 VersionConstraint _parseVersionConstraint(YamlNode node) {
517 if (node.value == null) return VersionConstraint.any; 532 if (node.value == null) return VersionConstraint.any;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 implements ApplicationException { 608 implements ApplicationException {
594 PubspecException(String message, SourceSpan span) 609 PubspecException(String message, SourceSpan span)
595 : super(message, span); 610 : super(message, span);
596 } 611 }
597 612
598 /// Returns whether [uri] is a file URI. 613 /// Returns whether [uri] is a file URI.
599 /// 614 ///
600 /// This is slightly more complicated than just checking if the scheme is 615 /// This is slightly more complicated than just checking if the scheme is
601 /// 'file', since relative URIs also refer to the filesystem on the VM. 616 /// 'file', since relative URIs also refer to the filesystem on the VM.
602 bool _isFileUri(Uri uri) => uri.scheme == 'file' || uri.scheme == ''; 617 bool _isFileUri(Uri uri) => uri.scheme == 'file' || uri.scheme == '';
OLDNEW
« no previous file with comments | « no previous file | test/transformer/gets_and_upgrades_a_package_with_a_dev_transformer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698