Skip to content
Snippets Groups Projects
Commit c507e385 authored by rnystrom@google.com's avatar rnystrom@google.com Committed by Natalie Weizenbaum
Browse files

Don't allow packages to depend on themselves.

BUG=https://code.google.com/p/dart/issues/detail?id=12300
R=nweiz@google.com

Review URL: https://codereview.chromium.org//22825024

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@26543 260f80e4-7a28-3924-810f-c04153c831b5
parent fa1a9ca6
No related branches found
No related tags found
No related merge requests found
...@@ -134,10 +134,10 @@ Pubspec _parseMap(String filePath, Map map, SourceRegistry sources) { ...@@ -134,10 +134,10 @@ Pubspec _parseMap(String filePath, Map map, SourceRegistry sources) {
'The pubspec "version" field should be a semantic version number, ' 'The pubspec "version" field should be a semantic version number, '
'but was "$v".'); 'but was "$v".');
var dependencies = _parseDependencies(filePath, sources, var dependencies = _parseDependencies(name, filePath, sources,
map['dependencies']); map['dependencies']);
var devDependencies = _parseDependencies(filePath, sources, var devDependencies = _parseDependencies(name, filePath, sources,
map['dev_dependencies']); map['dev_dependencies']);
// Make sure the same package doesn't appear as both a regular and dev // Make sure the same package doesn't appear as both a regular and dev
...@@ -265,8 +265,8 @@ VersionConstraint _parseVersionConstraint(yaml, String getMessage(yaml)) { ...@@ -265,8 +265,8 @@ VersionConstraint _parseVersionConstraint(yaml, String getMessage(yaml)) {
} }
} }
List<PackageDep> _parseDependencies(String pubspecPath, SourceRegistry sources, List<PackageDep> _parseDependencies(String packageName, String pubspecPath,
yaml) { SourceRegistry sources, yaml) {
var dependencies = <PackageDep>[]; var dependencies = <PackageDep>[];
// Allow an empty dependencies key. // Allow an empty dependencies key.
...@@ -279,6 +279,10 @@ List<PackageDep> _parseDependencies(String pubspecPath, SourceRegistry sources, ...@@ -279,6 +279,10 @@ List<PackageDep> _parseDependencies(String pubspecPath, SourceRegistry sources,
} }
yaml.forEach((name, spec) { yaml.forEach((name, spec) {
if (name == packageName) {
throw new FormatException("Package '$name' cannot depend on itself.");
}
var description; var description;
var sourceName; var sourceName;
......
...@@ -22,14 +22,6 @@ class DependencyValidator extends Validator { ...@@ -22,14 +22,6 @@ class DependencyValidator extends Validator {
return _warnAboutSource(dependency); return _warnAboutSource(dependency);
} }
if (dependency.name == entrypoint.root.name) {
warnings.add('You don\'t need to explicitly depend on your own '
'package.\n'
'Pub enables "package:${entrypoint.root.name}" imports '
'implicitly.');
return new Future.value();
}
if (dependency.constraint.isAny) _warnAboutConstraint(dependency); if (dependency.constraint.isAny) _warnAboutConstraint(dependency);
return new Future.value(); return new Future.value();
......
...@@ -113,5 +113,30 @@ main() { ...@@ -113,5 +113,30 @@ main() {
pubCommand(command, pubCommand(command,
error: new RegExp("^Incompatible dependencies on 'baz':\n")); error: new RegExp("^Incompatible dependencies on 'baz':\n"));
}); });
integration('does not allow a dependency on itself', () {
d.dir(appPath, [
d.appPubspec({
"myapp": {"path": "."}
})
]).create();
pubCommand(command,
error: new RegExp("Package 'myapp' cannot depend on itself."));
});
integration('does not allow a dev dependency on itself', () {
d.dir(appPath, [
d.pubspec({
"name": "myapp",
"dev_dependencies": {
"myapp": {"path": "."}
}
})
]).create();
pubCommand(command,
error: new RegExp("Package 'myapp' cannot depend on itself."));
});
}); });
} }
...@@ -103,6 +103,24 @@ dev_dependencies: ...@@ -103,6 +103,24 @@ dev_dependencies:
'''); ''');
}); });
test("throws if it dependes on itself", () {
expectFormatError('''
name: myapp
dependencies:
myapp:
mock: ok
''');
});
test("throws if it has a dev dependency on itself", () {
expectFormatError('''
name: myapp
dev_dependencies:
myapp:
mock: ok
''');
});
test("throws if the description isn't valid", () { test("throws if the description isn't valid", () {
expectFormatError(''' expectFormatError('''
dependencies: dependencies:
......
...@@ -237,15 +237,5 @@ main() { ...@@ -237,15 +237,5 @@ main() {
}); });
}); });
}); });
integration('has a hosted dependency on itself', () {
d.dir(appPath, [
d.libPubspec("test_pkg", "1.0.0", deps: {
"test_pkg": ">=1.0.0"
})
]).create();
expectValidationWarning(dependency);
});
}); });
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment