Handle git dependencies, roll packages to get transitive deps of flutter_gallery (#61064)

This commit is contained in:
Dan Field
2020-07-07 22:21:19 -07:00
committed by GitHub
parent 5969eb60ec
commit d45ad057b4
2 changed files with 62 additions and 20 deletions

View File

@@ -483,6 +483,9 @@ enum DependencyKind {
// A dependency that was "normal", but for which we later found a "path" or
// "sdk" dependency in the dependency_overrides section.
overridden,
// A depdendency that uses git.
git,
}
/// This is the string we output next to each of our autogenerated transitive
@@ -546,7 +549,8 @@ class PubspecYaml {
// the dependency. So we track what is the "current" (or "last") dependency
// that we are dealing with using this variable.
PubspecDependency lastDependency;
for (final String line in lines) {
for (int index = 0; index < lines.length; index += 1) {
String line = lines[index];
if (lastDependency == null) {
// First we look to see if we're transitioning to a new top-level section.
// The PubspecHeader.parse static method can recognize those headers.
@@ -644,23 +648,23 @@ class PubspecYaml {
//
// Try to parse the line by giving it to the last PubspecDependency
// object we created. If parseLock fails to recognize the line, it will
// throw. If it does recognize the line but decides it's one we don't
// care about (specifically, "git:" dependencies), it'll return false.
// throw. If it does recognize the line and needs the following lines in
// its lockLine, it'll return false.
// Otherwise it returns true.
//
// If it returns true, then it will have updated itself internally to
// store the information from this line.
if (!lastDependency.parseLock(line, filename, lockIsOverride: section == Section.dependencyOverrides)) {
// Ok we're dealing with some "git:" dependency. Let's pretend we
// never saw it. In practice this is only used for the flutter gallery
// assets dependency which we don't care about especially since it has
// no subdependencies and it's pinned by git hash.
//
// Remove the PubspecDependency entry we had for it and replace it
// with a PubspecLine entry, and add such an entry for this line.
result.removeLast();
result.add(PubspecLine(lastDependency.line));
result.add(PubspecLine(line));
// Ok we're dealing with some "git:" dependency. Consume lines until
// we are out of the git dependency, and stuff them into the lock
// line.
lastDependency._lockLine = line;
lastDependency._lockIsOverride = section == Section.dependencyOverrides;
do {
index += 1;
line = lines[index];
lastDependency._lockLine += '\n$line';
} while (line.startsWith(' '));
}
// We're done with this special dependency, so reset back to null so
// we'll go in the top section next time instead.
@@ -1121,7 +1125,7 @@ class PubspecDependency extends PubspecLine {
/// If parse decided we were a two-line dependency, this is called to parse the second line.
/// We throw if we couldn't parse this line.
/// We return true if we parsed it and stored the line in lockLine.
/// We return false if we parsed it but want to forget the whole thing.
/// We return false if we parsed it and it's a git dependency that needs the next few lines.
bool parseLock(String line, String pubspecPath, { @required bool lockIsOverride }) {
assert(lockIsOverride != null);
assert(kind == DependencyKind.unknown);
@@ -1136,7 +1140,8 @@ class PubspecDependency extends PubspecLine {
_lockTarget = line.substring(_sdkPrefix.length, line.length);
_kind = DependencyKind.sdk;
} else if (line.startsWith(_gitPrefix)) {
// We're a git: dependency. Return false so we'll be forgotten.
// We're a git: dependency. We'll have to get the next few lines.
_kind = DependencyKind.git;
return false;
} else {
throw 'Could not parse additional details for dependency $name; line was: "$line"';
@@ -1191,6 +1196,15 @@ class PubspecDependency extends PubspecLine {
dependencies.writeln(' sdk: $lockTarget');
}
break;
case DependencyKind.git:
if (_lockIsOverride) {
dependencies.writeln(' $name: any');
overrides.writeln(' $name:');
overrides.writeln(lockLine);
} else {
dependencies.writeln(' $name:');
dependencies.writeln(lockLine);
}
}
}
}