The dependency script wasn't catching quite all our transitive dependencies (#13954)

This commit is contained in:
Ian Hickson
2018-01-08 21:39:33 -08:00
committed by GitHub
parent b50ccc49d5
commit 9114e2afd1
26 changed files with 213 additions and 6 deletions

View File

@@ -517,6 +517,7 @@ class PubspecYaml {
// the dependency if it wasn't one of our autogenerated transitive
// dependency lines.
if (!data.isTransitive) {
// Assert that we haven't seen it in this file already.
assert(!directDependencies.contains(data.name));
if (data.kind == DependencyKind.normal) {
// This is a regular dependency, so we need to update the
@@ -568,9 +569,12 @@ class PubspecYaml {
final Set<String> transitiveDependencies = new Set<String>(); // which dependencies we need to handle
// Merge the list of dependencies we've seen in this file and the dependencies we know this
// file mentions that are already pinned (and which didn't get special processing above).
final Set<String> done = new Set<String>.from(directDependencies)..addAll(specialDependencies);
final Set<String> implied = new Set<String>.from(directDependencies)..addAll(specialDependencies);
// Create a new set to hold the list of packages we've already processed, so
// that we don't redundantly process them multiple times.
final Set<String> done = new Set<String>();
for (String package in directDependencies.toList())
transitiveDependencies.addAll(versions.getTransitiveDependenciesFor(package, seen: done));
transitiveDependencies.addAll(versions.getTransitiveDependenciesFor(package, seen: done, exclude: implied));
// Sort that list lexically so that we don't get noisy diffs when upgrading.
final List<String> transitiveDependenciesAsList = transitiveDependencies.toList()..sort();
// Add a blank line to keep the output clean. It doesn't matter if this adds
@@ -951,8 +955,12 @@ class PubDependencyTree {
/// The transitive closure of all the dependencies for the given package,
/// excluding any listen in `seen`.
Iterable<String> getTransitiveDependenciesFor(String package, { Set<String> seen }) sync* {
seen ??= new Set<String>();
Iterable<String> getTransitiveDependenciesFor(String package, {
@required Set<String> seen,
@required Set<String> exclude,
}) sync* {
assert(seen != null);
assert(exclude != null);
if (!_dependencyTree.containsKey(package)) {
// We have no transitive dependencies extracted for flutter_sdk packages
// because they were omitted from pubspec.yaml used for 'pub upgrade' run.
@@ -960,9 +968,10 @@ class PubDependencyTree {
}
for (String dependency in _dependencyTree[package]) {
if (!seen.contains(dependency)) {
yield dependency;
if (!exclude.contains(dependency))
yield dependency;
seen.add(dependency);
yield* getTransitiveDependenciesFor(dependency, seen: seen);
yield* getTransitiveDependenciesFor(dependency, seen: seen, exclude: exclude);
}
}
}