[flutter_conductor] Lift rev parse in conductor (#92594)

* lift git-rev-parse in conductor start
* remove localFlutterRoot from globals.dart
* make localFlutterRoot getter private
* fix analysis
This commit is contained in:
Christopher Fujino
2021-10-28 08:29:16 -07:00
committed by GitHub
parent 9bd0fef560
commit 45f438071a
6 changed files with 41 additions and 71 deletions

View File

@@ -3,9 +3,6 @@
// found in the LICENSE file.
import 'package:args/args.dart';
import 'package:file/file.dart';
import 'package:file/local.dart';
import 'package:platform/platform.dart';
import 'proto/conductor_state.pb.dart' as pb;
@@ -41,29 +38,6 @@ class ConductorException implements Exception {
String toString() => 'Exception: $message';
}
Directory? _flutterRoot;
Directory get localFlutterRoot {
if (_flutterRoot != null) {
return _flutterRoot!;
}
String filePath;
const FileSystem fileSystem = LocalFileSystem();
const Platform platform = LocalPlatform();
filePath = platform.script.toFilePath();
final String checkoutsDirname = fileSystem.path.normalize(
fileSystem.path.join(
fileSystem.path.dirname(filePath),
'..', // flutter/dev/conductor/core
'..', // flutter/dev/conductor
'..', // flutter/dev
'..', // flutter
),
);
_flutterRoot = fileSystem.directory(checkoutsDirname);
return _flutterRoot!;
}
bool assertsEnabled() {
// Verify asserts enabled
bool assertsEnabled = false;

View File

@@ -109,7 +109,8 @@ message ConductorState {
// The current [ReleasePhase] that has yet to be completed.
ReleasePhase currentPhase = 9;
// Commit hash of the Conductor tool.
// A string used to validate that the current conductor is the same version
// that created the [ConductorState] object.
string conductorVersion = 10;
// One of x, y, z, m, or n.

View File

@@ -34,7 +34,7 @@ const String kStateOption = 'state-file';
class StartCommand extends Command<void> {
StartCommand({
required this.checkouts,
required this.flutterRoot,
required this.conductorVersion,
}) : platform = checkouts.platform,
processManager = checkouts.processManager,
fileSystem = checkouts.fileSystem,
@@ -105,10 +105,7 @@ class StartCommand extends Command<void> {
final Checkouts checkouts;
/// The root directory of the Flutter repository that houses the Conductor.
///
/// This directory is used to check the git revision of the Conductor.
final Directory flutterRoot;
final String conductorVersion;
final FileSystem fileSystem;
final Platform platform;
final ProcessManager processManager;
@@ -191,7 +188,7 @@ class StartCommand extends Command<void> {
engineCherrypickRevisions: engineCherrypickRevisions,
engineMirror: engineMirror,
engineUpstream: engineUpstream,
flutterRoot: flutterRoot,
conductorVersion: conductorVersion,
frameworkCherrypickRevisions: frameworkCherrypickRevisions,
frameworkMirror: frameworkMirror,
frameworkUpstream: frameworkUpstream,
@@ -219,7 +216,7 @@ class StartContext {
required this.frameworkCherrypickRevisions,
required this.frameworkMirror,
required this.frameworkUpstream,
required this.flutterRoot,
required this.conductorVersion,
required this.incrementLetter,
required this.processManager,
required this.releaseChannel,
@@ -236,7 +233,7 @@ class StartContext {
final List<String> frameworkCherrypickRevisions;
final String frameworkMirror;
final String frameworkUpstream;
final Directory flutterRoot;
final String conductorVersion;
final String incrementLetter;
final Git git;
final ProcessManager processManager;
@@ -244,26 +241,6 @@ class StartContext {
final File stateFile;
final Stdio stdio;
/// Git revision for the currently running Conductor.
Future<String> get conductorVersion async {
if (_conductorVersion != null) {
return Future<String>.value(_conductorVersion);
}
_conductorVersion = (await git.getOutput(
<String>['rev-parse', 'HEAD'],
'look up the current revision.',
workingDirectory: flutterRoot.path,
)).trim();
if (_conductorVersion == null || _conductorVersion!.isEmpty) {
throw ConductorException(
'Failed to determine the git revision of the Flutter SDK\n'
'Working directory: ${flutterRoot.path}'
);
}
return _conductorVersion!;
}
String? _conductorVersion;
Future<void> run() async {
if (stateFile.existsSync()) {
throw ConductorException(
@@ -420,7 +397,7 @@ class StartContext {
state.currentPhase = ReleasePhase.APPLY_ENGINE_CHERRYPICKS;
state.conductorVersion = await conductorVersion;
state.conductorVersion = conductorVersion;
stdio.printTrace('Writing state to file ${stateFile.path}...');