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

Unified Diff: utils/pub/pubspec.dart

Issue 12038038: Add support for specifying SDK version constraints in pubspecs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up a bit. Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/pub/sdk_source.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/pubspec.dart
diff --git a/utils/pub/pubspec.dart b/utils/pub/pubspec.dart
index 078b7e05dc83c3c9271cf4ac09d6796f3344179f..aaabdd1b9b2feebd65df581c55d538927f296ede 100644
--- a/utils/pub/pubspec.dart
+++ b/utils/pub/pubspec.dart
@@ -22,11 +22,14 @@ class Pubspec {
/// The packages this package depends on.
final List<PackageRef> dependencies;
+ /// The environment-related metadata.
+ final PubspecEnvironment environment;
+
/// All pubspec fields. This includes the fields from which other properties
/// are derived.
final Map<String, Object> fields;
- Pubspec(this.name, this.version, this.dependencies,
+ Pubspec(this.name, this.version, this.dependencies, this.environment,
[Map<String, Object> fields])
: this.fields = fields == null ? {} : fields;
@@ -34,9 +37,10 @@ class Pubspec {
: name = null,
version = Version.none,
dependencies = <PackageRef>[],
+ environment = new PubspecEnvironment(),
fields = {};
- /// Whether or not the pubspec has no contents.
+ /// Whether or not the pubspec has no contents.
bool get isEmpty =>
name == null && version == Version.none && dependencies.isEmpty;
@@ -70,6 +74,26 @@ class Pubspec {
var dependencies = _parseDependencies(sources,
parsedPubspec['dependencies']);
+ var environmentYaml = parsedPubspec['environment'];
+ var sdkConstraint = VersionConstraint.any;
+ if (environmentYaml != null) {
+ if (environmentYaml is! Map) {
+ throw new FormatException(
+ 'The pubspec "environment" field should be a map, but was '
+ '"$environmentYaml".');
+ }
+
+ var sdkYaml = environmentYaml['sdk'];
+ if (sdkYaml is! String) {
+ throw new FormatException(
+ 'The "sdk" field of "environment" should be a string, but was '
+ '"$sdkYaml".');
+ }
+
+ sdkConstraint = new VersionConstraint.parse(sdkYaml);
+ }
+ var environment = new PubspecEnvironment(sdkConstraint);
+
// Even though the pub app itself doesn't use these fields, we validate
// them here so that users find errors early before they try to upload to
// the server:
@@ -123,7 +147,7 @@ class Pubspec {
}
}
- return new Pubspec(name, version, dependencies, parsedPubspec);
+ return new Pubspec(name, version, dependencies, environment, parsedPubspec);
}
}
@@ -181,3 +205,14 @@ List<PackageRef> _parseDependencies(SourceRegistry sources, yaml) {
return dependencies;
}
+
+/// The environment-related metadata in the pubspec. Corresponds to the data
+/// under the "environment:" key in the pubspec.
+class PubspecEnvironment {
+ /// The version constraint specifying which SDK versions this package works
+ /// with.
+ final VersionConstraint sdkVersion;
+
+ PubspecEnvironment([VersionConstraint sdk])
+ : sdkVersion = sdk != null ? sdk : VersionConstraint.any;
+}
« no previous file with comments | « no previous file | utils/pub/sdk_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698