[flutter_plugin_tools] Fix subpackage analysis (#5027)

This commit is contained in:
stuartmorgan
2022-03-11 15:15:26 -05:00
committed by GitHub
parent 159f6d87b7
commit 1bbfb60816
7 changed files with 103 additions and 18 deletions

View File

@ -102,16 +102,25 @@ class AnalyzeCommand extends PackageLoopingCommand {
@override
Future<PackageResult> runForPackage(RepositoryPackage package) async {
// For non-example packages, fetch dependencies. 'flutter packages get'
// automatically runs 'pub get' in examples as part of handling the parent
// directory, which is guaranteed to come first in the package enumeration.
if (package.directory.basename != 'example' ||
!RepositoryPackage(package.directory.parent).pubspecFile.existsSync()) {
final int exitCode = await processRunner.runAndStream(
flutterCommand, <String>['packages', 'get'],
workingDir: package.directory);
if (exitCode != 0) {
return PackageResult.fail(<String>['Unable to get dependencies']);
// Analysis runs over the package and all subpackages, so all of them need
// `flutter packages get` run before analyzing. `example` packages can be
// skipped since 'flutter packages get' automatically runs `pub get` in
// examples as part of handling the parent directory.
final List<RepositoryPackage> packagesToGet = <RepositoryPackage>[
package,
...await getSubpackages(package).toList(),
];
for (final RepositoryPackage packageToGet in packagesToGet) {
if (packageToGet.directory.basename != 'example' ||
!RepositoryPackage(packageToGet.directory.parent)
.pubspecFile
.existsSync()) {
final int exitCode = await processRunner.runAndStream(
flutterCommand, <String>['packages', 'get'],
workingDir: packageToGet.directory);
if (exitCode != 0) {
return PackageResult.fail(<String>['Unable to get dependencies']);
}
}
}

View File

@ -417,16 +417,22 @@ abstract class PluginCommand extends Command<void> {
await for (final PackageEnumerationEntry plugin
in getTargetPackages(filterExcluded: filterExcluded)) {
yield plugin;
yield* plugin.package.directory
.list(recursive: true, followLinks: false)
.where(_isDartPackage)
.map((FileSystemEntity directory) => PackageEnumerationEntry(
// _isDartPackage guarantees that this cast is valid.
RepositoryPackage(directory as Directory),
excluded: plugin.excluded));
yield* getSubpackages(plugin.package).map((RepositoryPackage package) =>
PackageEnumerationEntry(package, excluded: plugin.excluded));
}
}
/// Returns all Dart package folders (e.g., examples) under the given package.
Stream<RepositoryPackage> getSubpackages(RepositoryPackage package,
{bool filterExcluded = true}) async* {
yield* package.directory
.list(recursive: true, followLinks: false)
.where(_isDartPackage)
.map((FileSystemEntity directory) =>
// _isDartPackage guarantees that this cast is valid.
RepositoryPackage(directory as Directory));
}
/// Returns the files contained, recursively, within the packages
/// involved in this command execution.
Stream<File> getFiles() {

View File

@ -207,6 +207,10 @@ dependency_overrides:
allComponents.contains('example')) {
continue;
}
if (!allComponents.contains(packagesDir.basename)) {
print(' Skipping $changedPath; not in packages directory.');
continue;
}
final RepositoryPackage package =
RepositoryPackage(packagesDir.fileSystem.file(changedPath).parent);
// Ignored deleted packages, as they won't be published.