mirror of
https://github.com/flutter/packages.git
synced 2025-06-16 01:58:39 +08:00
[flutter_plugin_tools] Restructure version-check (#4111)
Combines the two different aspects of version-checking into a single looping structure based on plugins, using the new base command, rather than one operating on plugins as controlled by the usual flags and the other operating on a git list of changed files. Also simplifies the determination of the new version by simply checking the file, rather than querying git for the HEAD state of the file. Tests setup is simplified since we no longer need to set up nearly as much fake `git` output. Minor changes to base commands: - Move indentation up to PackageLoopingCommand so that it is consistent across commands - Add a new post-loop command for any cleanup, which is needed by version-check - Change the way the GitDir instance is managed by the base PluginCommand, so that it's always cached even when not overridden, to reduce duplicate work and code. Part of https://github.com/flutter/flutter/issues/83413
This commit is contained in:
@ -20,8 +20,8 @@ abstract class PluginCommand extends Command<void> {
|
||||
PluginCommand(
|
||||
this.packagesDir, {
|
||||
this.processRunner = const ProcessRunner(),
|
||||
this.gitDir,
|
||||
}) {
|
||||
GitDir? gitDir,
|
||||
}) : _gitDir = gitDir {
|
||||
argParser.addMultiOption(
|
||||
_pluginsArg,
|
||||
splitCommas: true,
|
||||
@ -76,10 +76,11 @@ abstract class PluginCommand extends Command<void> {
|
||||
/// This can be overridden for testing.
|
||||
final ProcessRunner processRunner;
|
||||
|
||||
/// The git directory to use. By default it uses the parent directory.
|
||||
/// The git directory to use. If unset, [gitDir] populates it from the
|
||||
/// packages directory's enclosing repository.
|
||||
///
|
||||
/// This can be mocked for testing.
|
||||
final GitDir? gitDir;
|
||||
GitDir? _gitDir;
|
||||
|
||||
int? _shardIndex;
|
||||
int? _shardCount;
|
||||
@ -100,6 +101,26 @@ abstract class PluginCommand extends Command<void> {
|
||||
return _shardCount!;
|
||||
}
|
||||
|
||||
/// Returns the [GitDir] containing [packagesDir].
|
||||
Future<GitDir> get gitDir async {
|
||||
GitDir? gitDir = _gitDir;
|
||||
if (gitDir != null) {
|
||||
return gitDir;
|
||||
}
|
||||
|
||||
// Ensure there are no symlinks in the path, as it can break
|
||||
// GitDir's allowSubdirectory:true.
|
||||
final String packagesPath = packagesDir.resolveSymbolicLinksSync();
|
||||
if (!await GitDir.isGitDir(packagesPath)) {
|
||||
printError('$packagesPath is not a valid Git repository.');
|
||||
throw ToolExit(2);
|
||||
}
|
||||
gitDir =
|
||||
await GitDir.fromExisting(packagesDir.path, allowSubdirectory: true);
|
||||
_gitDir = gitDir;
|
||||
return gitDir;
|
||||
}
|
||||
|
||||
/// Convenience accessor for boolean arguments.
|
||||
bool getBoolArg(String key) {
|
||||
return (argResults![key] as bool?) ?? false;
|
||||
@ -291,22 +312,10 @@ abstract class PluginCommand extends Command<void> {
|
||||
///
|
||||
/// Throws tool exit if [gitDir] nor root directory is a git directory.
|
||||
Future<GitVersionFinder> retrieveVersionFinder() async {
|
||||
final String rootDir = packagesDir.parent.absolute.path;
|
||||
final String baseSha = getStringArg(_kBaseSha);
|
||||
|
||||
GitDir? baseGitDir = gitDir;
|
||||
if (baseGitDir == null) {
|
||||
if (!await GitDir.isGitDir(rootDir)) {
|
||||
printError(
|
||||
'$rootDir is not a valid Git repository.',
|
||||
);
|
||||
throw ToolExit(2);
|
||||
}
|
||||
baseGitDir = await GitDir.fromExisting(rootDir);
|
||||
}
|
||||
|
||||
final GitVersionFinder gitVersionFinder =
|
||||
GitVersionFinder(baseGitDir, baseSha);
|
||||
GitVersionFinder(await gitDir, baseSha);
|
||||
return gitVersionFinder;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user