Unverified Commit 0b882698 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove branch migration and standardize constructor style for...

[flutter_tools] remove branch migration and standardize constructor style for version interface (#70058)
parent d11859fe
......@@ -115,10 +115,7 @@ class ChannelCommand extends FlutterCommand {
Future<void> _switchChannel(String branchName) async {
globals.printStatus("Switching to flutter channel '$branchName'...");
if (kObsoleteBranches.containsKey(branchName)) {
final String alternative = kObsoleteBranches[branchName];
globals.printStatus("This channel is obsolete. Consider switching to the '$alternative' channel instead.");
} else if (!kOfficialChannels.contains(branchName)) {
if (!kOfficialChannels.contains(branchName)) {
globals.printStatus('This is not an official channel. For a list of available channels, try "flutter channel".');
}
await _checkout(branchName);
......@@ -126,15 +123,6 @@ class ChannelCommand extends FlutterCommand {
globals.printStatus("To ensure that you're on the latest build from this channel, run 'flutter upgrade'");
}
static Future<void> upgradeChannel() async {
final String channel = globals.flutterVersion.channel;
if (kObsoleteBranches.containsKey(channel)) {
final String alternative = kObsoleteBranches[channel];
globals.printStatus("Transitioning from '$channel' to '$alternative'...");
return _checkout(alternative);
}
}
static Future<void> _checkout(String branchName) async {
// Get latest refs from upstream.
int result = await globals.processUtils.stream(
......
......@@ -10,7 +10,6 @@ import '../base/io.dart';
import '../base/logger.dart';
import '../base/process.dart';
import '../base/terminal.dart';
import '../base/time.dart';
import '../cache.dart';
import '../globals.dart' as globals;
import '../persistent_tool_state.dart';
......@@ -87,7 +86,7 @@ class DowngradeCommand extends FlutterCommand {
String workingDirectory = Cache.flutterRoot;
if (argResults.wasParsed('working-directory')) {
workingDirectory = stringArg('working-directory');
_flutterVersion = FlutterVersion(const SystemClock(), workingDirectory);
_flutterVersion = FlutterVersion(workingDirectory: workingDirectory);
}
final String currentChannel = _flutterVersion.channel;
......
......@@ -14,7 +14,6 @@ import '../dart/pub.dart';
import '../globals.dart' as globals;
import '../runner/flutter_command.dart';
import '../version.dart';
import 'channel.dart';
class UpgradeCommand extends FlutterCommand {
UpgradeCommand([UpgradeCommandRunner commandRunner])
......@@ -67,7 +66,7 @@ class UpgradeCommand extends FlutterCommand {
gitTagVersion: GitTagVersion.determine(globals.processUtils),
flutterVersion: stringArg('working-directory') == null
? globals.flutterVersion
: FlutterVersion(const SystemClock(), _commandRunner.workingDirectory),
: FlutterVersion(clock: const SystemClock(), workingDirectory: _commandRunner.workingDirectory),
verifyOnly: boolArg('verify-only'),
);
}
......@@ -154,7 +153,6 @@ class UpgradeCommandRunner {
);
}
recordState(flutterVersion);
await upgradeChannel(flutterVersion);
await attemptReset(upstreamRevision);
if (!testFlow) {
await flutterUpgradeContinue();
......@@ -258,15 +256,6 @@ class UpgradeCommandRunner {
return revision;
}
/// Attempts to upgrade the channel.
///
/// If the user is on a deprecated channel, attempts to migrate them off of
/// it.
Future<void> upgradeChannel(FlutterVersion flutterVersion) async {
globals.printStatus('Upgrading Flutter from $workingDirectory...');
await ChannelCommand.upgradeChannel();
}
/// Attempts a hard reset to the given revision.
///
/// This is a reset instead of fast forward because if we are on a release
......
......@@ -186,7 +186,7 @@ Future<T> runInContext<T>(
androidWorkflow: androidWorkflow,
),
FeatureFlags: () => const FlutterFeatureFlags(),
FlutterVersion: () => FlutterVersion(const SystemClock()),
FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
FuchsiaArtifacts: () => FuchsiaArtifacts.find(),
FuchsiaDeviceTools: () => FuchsiaDeviceTools(),
FuchsiaSdk: () => FuchsiaSdk(),
......
......@@ -423,8 +423,7 @@ class _DefaultUsage implements Usage {
isFirstRun ||
// Display the welcome message if we are not on master, and if the
// persistent tool state instructs that we should.
(!globals.flutterVersion.isMaster &&
(globals.persistentToolState.redisplayWelcomeMessage ?? true))) {
(globals.persistentToolState.redisplayWelcomeMessage ?? true)) {
_printWelcome();
_printedWelcome = true;
globals.persistentToolState.redisplayWelcomeMessage = false;
......
......@@ -232,13 +232,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
globals.flutterUsage.suppressAnalytics = true;
}
try {
await globals.flutterVersion.ensureVersionFile();
} on FileSystemException catch (e) {
globals.printError('Failed to write the version file to the artifact cache: "$e".');
globals.printError('Please ensure you have permissions in the artifact cache directory.');
throwToolExit('Failed to write the version file');
}
globals.flutterVersion.ensureVersionFile();
final bool machineFlag = topLevelResults['machine'] as bool;
if (topLevelResults.command?.name != 'upgrade' && topLevelResults['version-check'] as bool && !machineFlag) {
await globals.flutterVersion.checkFlutterVersionFreshness();
......
......@@ -16,17 +16,6 @@ import 'globals.dart' as globals;
/// The flutter GitHub repository.
String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
/// This maps old branch names to the names of branches that replaced them.
///
/// For example, in early 2018 we changed from having an "alpha" branch to
/// having a "dev" branch, so anyone using "alpha" now gets transitioned to
/// "dev".
const Map<String, String> kObsoleteBranches = <String, String>{
'alpha': 'dev',
'hackathon': 'dev',
'codelab': 'dev',
};
/// The names of each channel/branch in order of increasing stability.
enum Channel {
master,
......@@ -67,7 +56,11 @@ class FlutterVersion {
///
/// Call [fetchTagsAndUpdate] to update the version based on the latest tags
/// available upstream.
FlutterVersion([this._clock = const SystemClock(), this._workingDirectory]) {
FlutterVersion({
SystemClock clock = const SystemClock(),
String workingDirectory,
}) : _clock = clock,
_workingDirectory = workingDirectory {
_frameworkRevision = _runGit(
gitLog(<String>['-n', '1', '--pretty=format:%H']).join(' '),
globals.processUtils,
......@@ -77,6 +70,9 @@ class FlutterVersion {
_frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision);
}
final SystemClock _clock;
final String _workingDirectory;
/// Fetches tags from the upstream Flutter repository and re-calculates the
/// version.
///
......@@ -88,21 +84,12 @@ class FlutterVersion {
_frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision);
}
final SystemClock _clock;
final String _workingDirectory;
String _repositoryUrl;
String get repositoryUrl {
final String _ = channel;
return _repositoryUrl;
}
/// Whether we are currently on the master branch.
bool get isMaster {
final String branchName = getBranchName();
return !<String>['dev', 'beta', 'stable'].contains(branchName);
}
String _channel;
/// The channel is the upstream branch.
/// `master`, `dev`, `beta`, `stable`; or old ones, like `alpha`, `hackathon`, ...
......@@ -161,9 +148,8 @@ class FlutterVersion {
String get engineRevision => globals.cache.engineRevision;
String get engineRevisionShort => _shortGitRevision(engineRevision);
Future<void> ensureVersionFile() {
void ensureVersionFile() {
globals.fs.file(globals.fs.path.join(Cache.flutterRoot, 'version')).writeAsStringSync(_frameworkVersion);
return Future<void>.value();
}
@override
......@@ -298,8 +284,7 @@ class FlutterVersion {
}();
if (redactUnknownBranches || _branch.isEmpty) {
// Only return the branch names we know about; arbitrary branch names might contain PII.
if (!kOfficialChannels.contains(_branch) &&
!kObsoleteBranches.containsKey(_branch)) {
if (!kOfficialChannels.contains(_branch)) {
return '[user-branch]';
}
}
......
......@@ -40,7 +40,7 @@ void main() {
fakeCommandRunner = FakeUpgradeCommandRunner();
realCommandRunner = UpgradeCommandRunner();
processManager = FakeProcessManager.list(<FakeCommand>[]);
fakeCommandRunner.willHaveUncomittedChanges = false;
fakeCommandRunner.willHaveUncommittedChanges = false;
fakePlatform = FakePlatform()..environment = Map<String, String>.unmodifiable(<String, String>{
'ENV1': 'irrelevant',
'ENV2': 'irrelevant',
......@@ -63,7 +63,7 @@ void main() {
});
testUsingContext('throws tool exit with uncommitted changes', () async {
fakeCommandRunner.willHaveUncomittedChanges = true;
fakeCommandRunner.willHaveUncommittedChanges = true;
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
force: false,
continueFlow: false,
......@@ -290,7 +290,7 @@ void main() {
});
testUsingContext('does not throw tool exit with uncommitted changes and force', () async {
fakeCommandRunner.willHaveUncomittedChanges = true;
fakeCommandRunner.willHaveUncommittedChanges = true;
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
force: true,
......@@ -348,7 +348,7 @@ void main() {
]);
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_upgrade_test.');
flutterToolState = tempDir.childFile('.flutter_tool_state');
mockFlutterVersion = MockFlutterVersion(isStable: true);
mockFlutterVersion = MockFlutterVersion();
});
tearDown(() {
......@@ -385,7 +385,7 @@ void main() {
}
class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
bool willHaveUncomittedChanges = false;
bool willHaveUncommittedChanges = false;
bool alreadyUpToDate = false;
......@@ -395,10 +395,7 @@ class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
Future<String> fetchRemoteRevision() async => remoteRevision;
@override
Future<bool> hasUncommittedChanges() async => willHaveUncomittedChanges;
@override
Future<void> upgradeChannel(FlutterVersion flutterVersion) async {}
Future<bool> hasUncommittedChanges() async => willHaveUncommittedChanges;
@override
Future<void> attemptReset(String newRevision) async {}
......
......@@ -70,7 +70,7 @@ void main() {
expect(count, 0);
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(const SystemClock()),
FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
Usage: () => Usage(
configDirOverride: tempDir.path,
logFile: tempDir.childFile('analytics.log').path,
......@@ -94,7 +94,7 @@ void main() {
expect(count, 0);
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(const SystemClock()),
FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
Usage: () => Usage(
configDirOverride: tempDir.path,
logFile: tempDir.childFile('analytics.log').path,
......@@ -112,7 +112,7 @@ void main() {
expect(globals.fs.file('test').readAsStringSync(), contains('$featuresKey: enable-web'));
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(const SystemClock()),
FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
Config: () => mockFlutterConfig,
Platform: () => FakePlatform(environment: <String, String>{
'FLUTTER_ANALYTICS_LOG_FILE': 'test',
......@@ -138,7 +138,7 @@ void main() {
contains('$featuresKey: enable-web,enable-linux-desktop,enable-macos-desktop'),
);
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(const SystemClock()),
FlutterVersion: () => FlutterVersion(clock: const SystemClock()),
Config: () => mockFlutterConfig,
Platform: () => FakePlatform(environment: <String, String>{
'FLUTTER_ANALYTICS_LOG_FILE': 'test',
......
......@@ -96,18 +96,6 @@ void main() {
Platform: () => platform,
}, initializeFlutterRoot: false);
testUsingContext('throw tool exit if the version file cannot be written', () async {
final MockFlutterVersion version = globals.flutterVersion as MockFlutterVersion;
when(version.ensureVersionFile()).thenThrow(const FileSystemException());
expect(() async => await runner.run(<String>['dummy']), throwsToolExit());
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => platform,
}, initializeFlutterRoot: false);
testUsingContext('Doesnt crash on invalid .packages file', () async {
fs.file('pubspec.yaml').createSync();
fs.file('.packages')
......
......@@ -119,7 +119,7 @@ void main() {
_expectVersionMessage('');
expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => processManager,
Cache: () => mockCache,
});
......@@ -143,7 +143,7 @@ void main() {
await version.checkFlutterVersionFreshness();
_expectVersionMessage('');
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -165,7 +165,7 @@ void main() {
await version.checkFlutterVersionFreshness();
_expectVersionMessage(FlutterVersion.newVersionAvailableMessage());
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -191,7 +191,7 @@ void main() {
await version.checkFlutterVersionFreshness();
_expectVersionMessage('');
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -222,7 +222,7 @@ void main() {
await version.checkFlutterVersionFreshness();
_expectVersionMessage('');
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -246,7 +246,7 @@ void main() {
await version.checkFlutterVersionFreshness();
_expectVersionMessage(FlutterVersion.newVersionAvailableMessage());
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -266,7 +266,7 @@ void main() {
await version.checkFlutterVersionFreshness();
_expectVersionMessage('');
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -286,7 +286,7 @@ void main() {
await version.checkFlutterVersionFreshness();
_expectVersionMessage(FlutterVersion.versionOutOfDateMessage(_testClock.now().difference(getChannelOutOfDateVersion())));
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -320,7 +320,7 @@ void main() {
workingDirectory: anyNamed('workingDirectory'),
));
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
});
});
......@@ -336,7 +336,7 @@ void main() {
fakeData(mockProcessManager, mockCache, channel: channel);
_expectDefault(await VersionCheckStamp.load());
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -345,7 +345,7 @@ void main() {
fakeData(mockProcessManager, mockCache, stampJson: '<', channel: channel);
_expectDefault(await VersionCheckStamp.load());
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -359,7 +359,7 @@ void main() {
);
_expectDefault(await VersionCheckStamp.load());
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -383,7 +383,7 @@ void main() {
expect(stamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
expect(stamp.lastTimeWarningWasPrinted, _testClock.now());
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -410,7 +410,7 @@ void main() {
expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
expect(storedStamp.lastTimeWarningWasPrinted, _testClock.now());
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......@@ -441,7 +441,7 @@ void main() {
expect(storedStamp.lastTimeVersionWasChecked, _testClock.ago(const Duration(days: 2)));
expect(storedStamp.lastTimeWarningWasPrinted, _testClock.now());
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(_testClock),
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
Cache: () => mockCache,
});
......
......@@ -419,14 +419,7 @@ class FakeXcodeProjectInterpreter implements XcodeProjectInterpreter {
List<String> xcrunCommand() => <String>['xcrun'];
}
class MockFlutterVersion extends Mock implements FlutterVersion {
MockFlutterVersion({bool isStable = false}) : _isStable = isStable;
final bool _isStable;
@override
bool get isMaster => !_isStable;
}
class MockFlutterVersion extends Mock implements FlutterVersion {}
class MockClock extends Mock implements SystemClock {}
......
......@@ -709,9 +709,6 @@ class FakeFlutterVersion implements FlutterVersion {
return 'v0.0.0';
}
@override
bool get isMaster => true;
@override
String get repositoryUrl => null;
......
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