mirror of
https://github.com/flutter/packages.git
synced 2025-06-02 00:49:11 +08:00
[flutter_plugin_tools] Fix subpackage analysis (#5027)
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
## 0.8.1
|
||||
|
||||
- Fixes an `analyze` regression in 0.8.0 with packages that have non-`example`
|
||||
sub-packages.
|
||||
|
||||
## 0.8.0
|
||||
|
||||
- Ensures that `firebase-test-lab` runs include an `integration_test` runner.
|
||||
|
@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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.
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: flutter_plugin_tools
|
||||
description: Productivity utils for flutter/plugins and flutter/packages
|
||||
repository: https://github.com/flutter/plugins/tree/main/script/tool
|
||||
version: 0.8.0
|
||||
version: 0.8.1
|
||||
|
||||
dependencies:
|
||||
args: ^2.1.0
|
||||
|
@ -71,6 +71,31 @@ void main() {
|
||||
]));
|
||||
});
|
||||
|
||||
test('runs flutter pub get for non-example subpackages', () async {
|
||||
final Directory mainPackageDir = createFakePackage('a', packagesDir);
|
||||
final Directory otherPackages =
|
||||
mainPackageDir.childDirectory('other_packages');
|
||||
final Directory subpackage1 =
|
||||
createFakePackage('subpackage1', otherPackages);
|
||||
final Directory subpackage2 =
|
||||
createFakePackage('subpackage2', otherPackages);
|
||||
|
||||
await runCapturingPrint(runner, <String>['analyze']);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
ProcessCall('flutter', const <String>['packages', 'get'],
|
||||
mainPackageDir.path),
|
||||
ProcessCall(
|
||||
'flutter', const <String>['packages', 'get'], subpackage1.path),
|
||||
ProcessCall(
|
||||
'flutter', const <String>['packages', 'get'], subpackage2.path),
|
||||
ProcessCall('dart', const <String>['analyze', '--fatal-infos'],
|
||||
mainPackageDir.path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('don\'t elide a non-contained example package', () async {
|
||||
final Directory plugin1Dir = createFakePlugin('a', packagesDir);
|
||||
final Directory plugin2Dir = createFakePlugin('example', packagesDir);
|
||||
|
@ -323,5 +323,41 @@ void main() {
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('skips anything outside of the packages directory', () async {
|
||||
final Directory toolDir = packagesDir.parent.childDirectory('tool');
|
||||
const String newVersion = '1.1.0';
|
||||
final Directory package = createFakePackage(
|
||||
'flutter_plugin_tools', toolDir,
|
||||
version: newVersion);
|
||||
|
||||
// Simulate a minor version change so it would be a target.
|
||||
final File pubspecFile = RepositoryPackage(package).pubspecFile;
|
||||
final String changedFileOutput = <File>[
|
||||
pubspecFile,
|
||||
].map((File file) => file.path).join('\n');
|
||||
processRunner.mockProcessesForExecutable['git-diff'] = <io.Process>[
|
||||
MockProcess(stdout: changedFileOutput),
|
||||
];
|
||||
final String gitPubspecContents =
|
||||
pubspecFile.readAsStringSync().replaceAll(newVersion, '1.0.0');
|
||||
processRunner.mockProcessesForExecutable['git-show'] = <io.Process>[
|
||||
MockProcess(stdout: gitPubspecContents),
|
||||
];
|
||||
|
||||
final List<String> output = await runCapturingPrint(runner, <String>[
|
||||
'make-deps-path-based',
|
||||
'--target-dependencies-with-non-breaking-updates'
|
||||
]);
|
||||
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains(
|
||||
'Skipping /tool/flutter_plugin_tools/pubspec.yaml; not in packages directory.'),
|
||||
contains('No target dependencies'),
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user