Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 40572a7

Browse files
[flutter_plugin_tools] Add a new 'make-deps-path-based' command (#4575)
Adds a new command that adds `dependency_overrides` to any packages in the repository that depend on a list of target packages, including an option to target packages that will publish a non-breaking change in a given diff. Adds a new CI step that uses the above in conjunction with a new `--run-on-dirty-packages` to adjust the dependencies of anything in the repository that uses a to-be-published package and then re-run analysis on just those packages. This will allow us to catch in presubmit any changes that are not breaking from a semver standpoint, but will break us due to our strict analysis in CI. Fixes flutter/flutter#89862
1 parent c32b27b commit 40572a7

16 files changed

+758
-25
lines changed

.cirrus.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,25 @@ task:
109109
matrix:
110110
CHANNEL: "master"
111111
CHANNEL: "stable"
112-
tool_script:
112+
analyze_tool_script:
113113
- cd script/tool
114114
- dart analyze --fatal-infos
115-
script:
115+
analyze_script:
116116
# DO NOT change the custom-analysis argument here without changing the Dart repo.
117117
# See the comment in script/configs/custom_analysis.yaml for details.
118118
- ./script/tool_runner.sh analyze --custom-analysis=script/configs/custom_analysis.yaml
119+
pathified_analyze_script:
120+
# Re-run analysis with path-based dependencies to ensure that publishing
121+
# the changes won't break analysis of other packages in the respository
122+
# that depend on it.
123+
- ./script/tool_runner.sh make-deps-path-based --target-dependencies-with-non-breaking-updates
124+
# This uses --run-on-dirty-packages rather than --packages-for-branch
125+
# since only the packages changed by 'make-deps-path-based' need to be
126+
# checked.
127+
- dart $PLUGIN_TOOL analyze --run-on-dirty-packages --log-timing --custom-analysis=script/configs/custom_analysis.yaml
128+
# Restore the tree to a clean state, to avoid accidental issues if
129+
# other script steps are added to this task.
130+
- git checkout .
119131
### Android tasks ###
120132
- name: android-build_all_plugins
121133
env:

script/tool/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
## NEXT
22

33
- Ensures that `firebase-test-lab` runs include an `integration_test` runner.
4+
- Adds a `make-deps-path-based` command to convert inter-repo package
5+
dependencies to path-based dependencies.
6+
- Adds a (hidden) `--run-on-dirty-packages` flag for use with
7+
`make-deps-path-based` in CI.
48

59
## 0.7.3
610

script/tool/lib/src/common/git_version_finder.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ class GitVersionFinder {
3131
}
3232

3333
/// Get a list of all the changed files.
34-
Future<List<String>> getChangedFiles() async {
34+
Future<List<String>> getChangedFiles(
35+
{bool includeUncommitted = false}) async {
3536
final String baseSha = await getBaseSha();
3637
final io.ProcessResult changedFilesCommand = await baseGitDir
37-
.runCommand(<String>['diff', '--name-only', baseSha, 'HEAD']);
38+
.runCommand(<String>[
39+
'diff',
40+
'--name-only',
41+
baseSha,
42+
if (!includeUncommitted) 'HEAD'
43+
]);
3844
final String changedFilesStdout = changedFilesCommand.stdout.toString();
3945
if (changedFilesStdout.isEmpty) {
4046
return <String>[];

script/tool/lib/src/common/plugin_command.dart

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,15 @@ abstract class PluginCommand extends Command<void> {
7575
help: 'Run the command on changed packages/plugins.\n'
7676
'If no packages have changed, or if there have been changes that may\n'
7777
'affect all packages, the command runs on all packages.\n'
78-
'The packages excluded with $_excludeArg is also excluded even if changed.\n'
78+
'Packages excluded with $_excludeArg are excluded even if changed.\n'
7979
'See $_baseShaArg if a custom base is needed to determine the diff.\n\n'
8080
'Cannot be combined with $_packagesArg.\n');
81+
argParser.addFlag(_runOnDirtyPackagesArg,
82+
help:
83+
'Run the command on packages with changes that have not been committed.\n'
84+
'Packages excluded with $_excludeArg are excluded even if changed.\n'
85+
'Cannot be combined with $_packagesArg.\n',
86+
hide: true);
8187
argParser.addFlag(_packagesForBranchArg,
8288
help:
8389
'This runs on all packages (equivalent to no package selection flag)\n'
@@ -103,6 +109,7 @@ abstract class PluginCommand extends Command<void> {
103109
static const String _packagesForBranchArg = 'packages-for-branch';
104110
static const String _pluginsArg = 'plugins';
105111
static const String _runOnChangedPackagesArg = 'run-on-changed-packages';
112+
static const String _runOnDirtyPackagesArg = 'run-on-dirty-packages';
106113
static const String _shardCountArg = 'shardCount';
107114
static const String _shardIndexArg = 'shardIndex';
108115

@@ -289,6 +296,7 @@ abstract class PluginCommand extends Command<void> {
289296
final Set<String> packageSelectionFlags = <String>{
290297
_packagesArg,
291298
_runOnChangedPackagesArg,
299+
_runOnDirtyPackagesArg,
292300
_packagesForBranchArg,
293301
};
294302
if (packageSelectionFlags
@@ -300,7 +308,7 @@ abstract class PluginCommand extends Command<void> {
300308
throw ToolExit(exitInvalidArguments);
301309
}
302310

303-
Set<String> plugins = Set<String>.from(getStringListArg(_packagesArg));
311+
Set<String> packages = Set<String>.from(getStringListArg(_packagesArg));
304312

305313
final bool runOnChangedPackages;
306314
if (getBoolArg(_runOnChangedPackagesArg)) {
@@ -331,7 +339,21 @@ abstract class PluginCommand extends Command<void> {
331339
final List<String> changedFiles =
332340
await gitVersionFinder.getChangedFiles();
333341
if (!_changesRequireFullTest(changedFiles)) {
334-
plugins = _getChangedPackages(changedFiles);
342+
packages = _getChangedPackages(changedFiles);
343+
}
344+
} else if (getBoolArg(_runOnDirtyPackagesArg)) {
345+
final GitVersionFinder gitVersionFinder =
346+
GitVersionFinder(await gitDir, 'HEAD');
347+
print('Running for all packages that have uncommitted changes\n');
348+
// _changesRequireFullTest is deliberately not used here, as this flag is
349+
// intended for use in CI to re-test packages changed by
350+
// 'make-deps-path-based'.
351+
packages = _getChangedPackages(
352+
await gitVersionFinder.getChangedFiles(includeUncommitted: true));
353+
// For the same reason, empty is not treated as "all packages" as it is
354+
// for other flags.
355+
if (packages.isEmpty) {
356+
return;
335357
}
336358
}
337359

@@ -347,7 +369,7 @@ abstract class PluginCommand extends Command<void> {
347369
in dir.list(followLinks: false)) {
348370
// A top-level Dart package is a plugin package.
349371
if (_isDartPackage(entity)) {
350-
if (plugins.isEmpty || plugins.contains(p.basename(entity.path))) {
372+
if (packages.isEmpty || packages.contains(p.basename(entity.path))) {
351373
yield PackageEnumerationEntry(
352374
RepositoryPackage(entity as Directory),
353375
excluded: excludedPluginNames.contains(entity.basename));
@@ -364,9 +386,9 @@ abstract class PluginCommand extends Command<void> {
364386
path.relative(subdir.path, from: dir.path);
365387
final String packageName = path.basename(subdir.path);
366388
final String basenamePath = path.basename(entity.path);
367-
if (plugins.isEmpty ||
368-
plugins.contains(relativePath) ||
369-
plugins.contains(basenamePath)) {
389+
if (packages.isEmpty ||
390+
packages.contains(relativePath) ||
391+
packages.contains(basenamePath)) {
370392
yield PackageEnumerationEntry(
371393
RepositoryPackage(subdir as Directory),
372394
excluded: excludedPluginNames.contains(basenamePath) ||

script/tool/lib/src/common/repository_package.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:file/file.dart';
66
import 'package:path/path.dart' as p;
7+
import 'package:pubspec_parse/pubspec_parse.dart';
78

89
import 'core.dart';
910

@@ -47,6 +48,14 @@ class RepositoryPackage {
4748
/// The package's top-level pubspec.yaml.
4849
File get pubspecFile => directory.childFile('pubspec.yaml');
4950

51+
late final Pubspec _parsedPubspec =
52+
Pubspec.parse(pubspecFile.readAsStringSync());
53+
54+
/// Returns the parsed [pubspecFile].
55+
///
56+
/// Caches for future use.
57+
Pubspec parsePubspec() => _parsedPubspec;
58+
5059
/// True if this appears to be a federated plugin package, according to
5160
/// repository conventions.
5261
bool get isFederated =>

script/tool/lib/src/create_all_plugins_app_command.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ class CreateAllPluginsAppCommand extends PluginCommand {
178178
final RepositoryPackage package = entry.package;
179179
final Directory pluginDirectory = package.directory;
180180
final String pluginName = pluginDirectory.basename;
181-
final File pubspecFile = package.pubspecFile;
182-
final Pubspec pubspec = Pubspec.parse(pubspecFile.readAsStringSync());
181+
final Pubspec pubspec = package.parsePubspec();
183182

184183
if (pubspec.publishTo != 'none') {
185184
pathDependencies[pluginName] = PathDependency(pluginDirectory.path);

script/tool/lib/src/main.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'license_check_command.dart';
2020
import 'lint_android_command.dart';
2121
import 'lint_podspecs_command.dart';
2222
import 'list_command.dart';
23+
import 'make_deps_path_based_command.dart';
2324
import 'native_test_command.dart';
2425
import 'publish_check_command.dart';
2526
import 'publish_plugin_command.dart';
@@ -58,6 +59,7 @@ void main(List<String> args) {
5859
..addCommand(LintPodspecsCommand(packagesDir))
5960
..addCommand(ListCommand(packagesDir))
6061
..addCommand(NativeTestCommand(packagesDir))
62+
..addCommand(MakeDepsPathBasedCommand(packagesDir))
6163
..addCommand(PublishCheckCommand(packagesDir))
6264
..addCommand(PublishPluginCommand(packagesDir))
6365
..addCommand(PubspecCheckCommand(packagesDir))

0 commit comments

Comments
 (0)