Unverified Commit 45f43807 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[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
parent 9bd0fef5
...@@ -26,7 +26,7 @@ Future<void> main(List<String> args) async { ...@@ -26,7 +26,7 @@ Future<void> main(List<String> args) async {
); );
final Checkouts checkouts = Checkouts( final Checkouts checkouts = Checkouts(
fileSystem: fileSystem, fileSystem: fileSystem,
parentDirectory: localFlutterRoot.parent, parentDirectory: _localFlutterRoot.parent,
platform: platform, platform: platform,
processManager: processManager, processManager: processManager,
stdio: stdio, stdio: stdio,
...@@ -39,6 +39,12 @@ Future<void> main(List<String> args) async { ...@@ -39,6 +39,12 @@ Future<void> main(List<String> args) async {
usageLineLength: 80, usageLineLength: 80,
); );
final String conductorVersion = (await const Git(processManager).getOutput(
<String>['rev-parse'],
'Get the revision of the current Flutter SDK',
workingDirectory: _localFlutterRoot.path,
)).trim();
<Command<void>>[ <Command<void>>[
RollDevCommand( RollDevCommand(
checkouts: checkouts, checkouts: checkouts,
...@@ -48,21 +54,21 @@ Future<void> main(List<String> args) async { ...@@ -48,21 +54,21 @@ Future<void> main(List<String> args) async {
), ),
CodesignCommand( CodesignCommand(
checkouts: checkouts, checkouts: checkouts,
flutterRoot: localFlutterRoot, flutterRoot: _localFlutterRoot,
), ),
StatusCommand( StatusCommand(
checkouts: checkouts, checkouts: checkouts,
), ),
StartCommand( StartCommand(
checkouts: checkouts, checkouts: checkouts,
flutterRoot: localFlutterRoot, conductorVersion: conductorVersion,
), ),
CleanCommand( CleanCommand(
checkouts: checkouts, checkouts: checkouts,
), ),
CandidatesCommand( CandidatesCommand(
checkouts: checkouts, checkouts: checkouts,
flutterRoot: localFlutterRoot, flutterRoot: _localFlutterRoot,
), ),
NextCommand( NextCommand(
checkouts: checkouts, checkouts: checkouts,
...@@ -81,3 +87,21 @@ Future<void> main(List<String> args) async { ...@@ -81,3 +87,21 @@ Future<void> main(List<String> args) async {
io.exit(1); io.exit(1);
} }
} }
Directory get _localFlutterRoot {
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/bin
'..', // flutter/dev/conductor/core
'..', // flutter/dev/conductor
'..', // flutter/dev
'..', // flutter
),
);
return fileSystem.directory(checkoutsDirname);
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
export 'src/candidates.dart'; export 'src/candidates.dart';
export 'src/clean.dart'; export 'src/clean.dart';
export 'src/codesign.dart'; export 'src/codesign.dart';
export 'src/git.dart';
export 'src/globals.dart'; export 'src/globals.dart';
export 'src/next.dart' hide kStateOption, kYesFlag; export 'src/next.dart' hide kStateOption, kYesFlag;
export 'src/repository.dart'; export 'src/repository.dart';
......
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:args/args.dart'; 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; import 'proto/conductor_state.pb.dart' as pb;
...@@ -41,29 +38,6 @@ class ConductorException implements Exception { ...@@ -41,29 +38,6 @@ class ConductorException implements Exception {
String toString() => 'Exception: $message'; 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() { bool assertsEnabled() {
// Verify asserts enabled // Verify asserts enabled
bool assertsEnabled = false; bool assertsEnabled = false;
......
...@@ -109,7 +109,8 @@ message ConductorState { ...@@ -109,7 +109,8 @@ message ConductorState {
// The current [ReleasePhase] that has yet to be completed. // The current [ReleasePhase] that has yet to be completed.
ReleasePhase currentPhase = 9; 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; string conductorVersion = 10;
// One of x, y, z, m, or n. // One of x, y, z, m, or n.
......
...@@ -34,7 +34,7 @@ const String kStateOption = 'state-file'; ...@@ -34,7 +34,7 @@ const String kStateOption = 'state-file';
class StartCommand extends Command<void> { class StartCommand extends Command<void> {
StartCommand({ StartCommand({
required this.checkouts, required this.checkouts,
required this.flutterRoot, required this.conductorVersion,
}) : platform = checkouts.platform, }) : platform = checkouts.platform,
processManager = checkouts.processManager, processManager = checkouts.processManager,
fileSystem = checkouts.fileSystem, fileSystem = checkouts.fileSystem,
...@@ -105,10 +105,7 @@ class StartCommand extends Command<void> { ...@@ -105,10 +105,7 @@ class StartCommand extends Command<void> {
final Checkouts checkouts; final Checkouts checkouts;
/// The root directory of the Flutter repository that houses the Conductor. final String conductorVersion;
///
/// This directory is used to check the git revision of the Conductor.
final Directory flutterRoot;
final FileSystem fileSystem; final FileSystem fileSystem;
final Platform platform; final Platform platform;
final ProcessManager processManager; final ProcessManager processManager;
...@@ -191,7 +188,7 @@ class StartCommand extends Command<void> { ...@@ -191,7 +188,7 @@ class StartCommand extends Command<void> {
engineCherrypickRevisions: engineCherrypickRevisions, engineCherrypickRevisions: engineCherrypickRevisions,
engineMirror: engineMirror, engineMirror: engineMirror,
engineUpstream: engineUpstream, engineUpstream: engineUpstream,
flutterRoot: flutterRoot, conductorVersion: conductorVersion,
frameworkCherrypickRevisions: frameworkCherrypickRevisions, frameworkCherrypickRevisions: frameworkCherrypickRevisions,
frameworkMirror: frameworkMirror, frameworkMirror: frameworkMirror,
frameworkUpstream: frameworkUpstream, frameworkUpstream: frameworkUpstream,
...@@ -219,7 +216,7 @@ class StartContext { ...@@ -219,7 +216,7 @@ class StartContext {
required this.frameworkCherrypickRevisions, required this.frameworkCherrypickRevisions,
required this.frameworkMirror, required this.frameworkMirror,
required this.frameworkUpstream, required this.frameworkUpstream,
required this.flutterRoot, required this.conductorVersion,
required this.incrementLetter, required this.incrementLetter,
required this.processManager, required this.processManager,
required this.releaseChannel, required this.releaseChannel,
...@@ -236,7 +233,7 @@ class StartContext { ...@@ -236,7 +233,7 @@ class StartContext {
final List<String> frameworkCherrypickRevisions; final List<String> frameworkCherrypickRevisions;
final String frameworkMirror; final String frameworkMirror;
final String frameworkUpstream; final String frameworkUpstream;
final Directory flutterRoot; final String conductorVersion;
final String incrementLetter; final String incrementLetter;
final Git git; final Git git;
final ProcessManager processManager; final ProcessManager processManager;
...@@ -244,26 +241,6 @@ class StartContext { ...@@ -244,26 +241,6 @@ class StartContext {
final File stateFile; final File stateFile;
final Stdio stdio; 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 { Future<void> run() async {
if (stateFile.existsSync()) { if (stateFile.existsSync()) {
throw ConductorException( throw ConductorException(
...@@ -420,7 +397,7 @@ class StartContext { ...@@ -420,7 +397,7 @@ class StartContext {
state.currentPhase = ReleasePhase.APPLY_ENGINE_CHERRYPICKS; state.currentPhase = ReleasePhase.APPLY_ENGINE_CHERRYPICKS;
state.conductorVersion = await conductorVersion; state.conductorVersion = conductorVersion;
stdio.printTrace('Writing state to file ${stateFile.path}...'); stdio.printTrace('Writing state to file ${stateFile.path}...');
......
...@@ -25,6 +25,7 @@ void main() { ...@@ -25,6 +25,7 @@ void main() {
const String candidateBranch = 'flutter-1.2-candidate.3'; const String candidateBranch = 'flutter-1.2-candidate.3';
const String releaseChannel = 'stable'; const String releaseChannel = 'stable';
const String revision = 'abcd1234'; const String revision = 'abcd1234';
const String conductorVersion = 'deadbeef';
late Checkouts checkouts; late Checkouts checkouts;
late MemoryFileSystem fileSystem; late MemoryFileSystem fileSystem;
late FakePlatform platform; late FakePlatform platform;
...@@ -66,7 +67,7 @@ void main() { ...@@ -66,7 +67,7 @@ void main() {
); );
final StartCommand command = StartCommand( final StartCommand command = StartCommand(
checkouts: checkouts, checkouts: checkouts,
flutterRoot: fileSystem.directory(flutterRoot), conductorVersion: conductorVersion,
); );
return CommandRunner<void>('codesign-test', '')..addCommand(command); return CommandRunner<void>('codesign-test', '')..addCommand(command);
} }
...@@ -252,10 +253,6 @@ void main() { ...@@ -252,10 +253,6 @@ void main() {
commands: <FakeCommand>[ commands: <FakeCommand>[
...engineCommands, ...engineCommands,
...frameworkCommands, ...frameworkCommands,
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: revision,
),
], ],
); );
...@@ -301,7 +298,7 @@ void main() { ...@@ -301,7 +298,7 @@ void main() {
expect(state.framework.startingGitHead, revision3); expect(state.framework.startingGitHead, revision3);
expect(state.framework.upstream.url, 'git@github.com:flutter/flutter.git'); expect(state.framework.upstream.url, 'git@github.com:flutter/flutter.git');
expect(state.currentPhase, ReleasePhase.APPLY_ENGINE_CHERRYPICKS); expect(state.currentPhase, ReleasePhase.APPLY_ENGINE_CHERRYPICKS);
expect(state.conductorVersion, revision); expect(state.conductorVersion, conductorVersion);
expect(state.incrementLevel, incrementLevel); expect(state.incrementLevel, incrementLevel);
}); });
...@@ -436,10 +433,6 @@ void main() { ...@@ -436,10 +433,6 @@ void main() {
commands: <FakeCommand>[ commands: <FakeCommand>[
...engineCommands, ...engineCommands,
...frameworkCommands, ...frameworkCommands,
const FakeCommand(
command: <String>['git', 'rev-parse', 'HEAD'],
stdout: revision,
),
], ],
); );
...@@ -483,7 +476,7 @@ void main() { ...@@ -483,7 +476,7 @@ void main() {
expect(state.framework.candidateBranch, candidateBranch); expect(state.framework.candidateBranch, candidateBranch);
expect(state.framework.startingGitHead, revision3); expect(state.framework.startingGitHead, revision3);
expect(state.currentPhase, ReleasePhase.APPLY_ENGINE_CHERRYPICKS); expect(state.currentPhase, ReleasePhase.APPLY_ENGINE_CHERRYPICKS);
expect(state.conductorVersion, revision); expect(state.conductorVersion, conductorVersion);
expect(state.incrementLevel, incrementLevel); expect(state.incrementLevel, incrementLevel);
}); });
}, onPlatform: <String, dynamic>{ }, onPlatform: <String, dynamic>{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment