diff --git a/packages/flutter_tools/lib/src/commands/channel.dart b/packages/flutter_tools/lib/src/commands/channel.dart index 7ab0d5f4b2..02b1487cbb 100644 --- a/packages/flutter_tools/lib/src/commands/channel.dart +++ b/packages/flutter_tools/lib/src/commands/channel.dart @@ -115,10 +115,7 @@ class ChannelCommand extends FlutterCommand { Future _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 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 _checkout(String branchName) async { // Get latest refs from upstream. int result = await globals.processUtils.stream( diff --git a/packages/flutter_tools/lib/src/commands/downgrade.dart b/packages/flutter_tools/lib/src/commands/downgrade.dart index 543dafda4e..ddf98c2597 100644 --- a/packages/flutter_tools/lib/src/commands/downgrade.dart +++ b/packages/flutter_tools/lib/src/commands/downgrade.dart @@ -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; diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index e941d7c454..5771d9b6a5 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -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 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 diff --git a/packages/flutter_tools/lib/src/context_runner.dart b/packages/flutter_tools/lib/src/context_runner.dart index 2abcdeea75..fc65f44fe1 100644 --- a/packages/flutter_tools/lib/src/context_runner.dart +++ b/packages/flutter_tools/lib/src/context_runner.dart @@ -186,7 +186,7 @@ Future runInContext( androidWorkflow: androidWorkflow, ), FeatureFlags: () => const FlutterFeatureFlags(), - FlutterVersion: () => FlutterVersion(const SystemClock()), + FlutterVersion: () => FlutterVersion(clock: const SystemClock()), FuchsiaArtifacts: () => FuchsiaArtifacts.find(), FuchsiaDeviceTools: () => FuchsiaDeviceTools(), FuchsiaSdk: () => FuchsiaSdk(), diff --git a/packages/flutter_tools/lib/src/reporting/usage.dart b/packages/flutter_tools/lib/src/reporting/usage.dart index cdff5ae512..1ced397b73 100644 --- a/packages/flutter_tools/lib/src/reporting/usage.dart +++ b/packages/flutter_tools/lib/src/reporting/usage.dart @@ -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; diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart index b3301f825d..6f7670414a 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart @@ -232,13 +232,7 @@ class FlutterCommandRunner extends CommandRunner { 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(); diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index 3ec6bcd899..6d679d3e7f 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart @@ -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 kObsoleteBranches = { - '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(['-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 !['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 ensureVersionFile() { + void ensureVersionFile() { globals.fs.file(globals.fs.path.join(Cache.flutterRoot, 'version')).writeAsStringSync(_frameworkVersion); - return Future.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]'; } } diff --git a/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart b/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart index 6910c31d95..3fbdb4425e 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart @@ -40,7 +40,7 @@ void main() { fakeCommandRunner = FakeUpgradeCommandRunner(); realCommandRunner = UpgradeCommandRunner(); processManager = FakeProcessManager.list([]); - fakeCommandRunner.willHaveUncomittedChanges = false; + fakeCommandRunner.willHaveUncommittedChanges = false; fakePlatform = FakePlatform()..environment = Map.unmodifiable({ '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 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 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 fetchRemoteRevision() async => remoteRevision; @override - Future hasUncommittedChanges() async => willHaveUncomittedChanges; - - @override - Future upgradeChannel(FlutterVersion flutterVersion) async {} + Future hasUncommittedChanges() async => willHaveUncommittedChanges; @override Future attemptReset(String newRevision) async {} diff --git a/packages/flutter_tools/test/general.shard/analytics_test.dart b/packages/flutter_tools/test/general.shard/analytics_test.dart index 377f04ca55..5551845dcf 100644 --- a/packages/flutter_tools/test/general.shard/analytics_test.dart +++ b/packages/flutter_tools/test/general.shard/analytics_test.dart @@ -70,7 +70,7 @@ void main() { expect(count, 0); }, overrides: { - 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: { - 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: { - FlutterVersion: () => FlutterVersion(const SystemClock()), + FlutterVersion: () => FlutterVersion(clock: const SystemClock()), Config: () => mockFlutterConfig, Platform: () => FakePlatform(environment: { 'FLUTTER_ANALYTICS_LOG_FILE': 'test', @@ -138,7 +138,7 @@ void main() { contains('$featuresKey: enable-web,enable-linux-desktop,enable-macos-desktop'), ); }, overrides: { - FlutterVersion: () => FlutterVersion(const SystemClock()), + FlutterVersion: () => FlutterVersion(clock: const SystemClock()), Config: () => mockFlutterConfig, Platform: () => FakePlatform(environment: { 'FLUTTER_ANALYTICS_LOG_FILE': 'test', diff --git a/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart b/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart index b18722376b..b2bda05907 100644 --- a/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/runner/flutter_command_runner_test.dart @@ -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(['dummy']), throwsToolExit()); - - }, overrides: { - 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') diff --git a/packages/flutter_tools/test/general.shard/version_test.dart b/packages/flutter_tools/test/general.shard/version_test.dart index 5b922bca5c..3e69c5be74 100644 --- a/packages/flutter_tools/test/general.shard/version_test.dart +++ b/packages/flutter_tools/test/general.shard/version_test.dart @@ -119,7 +119,7 @@ void main() { _expectVersionMessage(''); expect(processManager.hasRemainingExpectations, isFalse); }, overrides: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => processManager, Cache: () => mockCache, }); @@ -143,7 +143,7 @@ void main() { await version.checkFlutterVersionFreshness(); _expectVersionMessage(''); }, overrides: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => mockProcessManager, Cache: () => mockCache, }); @@ -165,7 +165,7 @@ void main() { await version.checkFlutterVersionFreshness(); _expectVersionMessage(FlutterVersion.newVersionAvailableMessage()); }, overrides: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => mockProcessManager, Cache: () => mockCache, }); @@ -191,7 +191,7 @@ void main() { await version.checkFlutterVersionFreshness(); _expectVersionMessage(''); }, overrides: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => mockProcessManager, Cache: () => mockCache, }); @@ -222,7 +222,7 @@ void main() { await version.checkFlutterVersionFreshness(); _expectVersionMessage(''); }, overrides: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => mockProcessManager, Cache: () => mockCache, }); @@ -246,7 +246,7 @@ void main() { await version.checkFlutterVersionFreshness(); _expectVersionMessage(FlutterVersion.newVersionAvailableMessage()); }, overrides: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => mockProcessManager, Cache: () => mockCache, }); @@ -266,7 +266,7 @@ void main() { await version.checkFlutterVersionFreshness(); _expectVersionMessage(''); }, overrides: { - 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: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => mockProcessManager, Cache: () => mockCache, }); @@ -320,7 +320,7 @@ void main() { workingDirectory: anyNamed('workingDirectory'), )); }, overrides: { - 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: { - 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: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => mockProcessManager, Cache: () => mockCache, }); @@ -359,7 +359,7 @@ void main() { ); _expectDefault(await VersionCheckStamp.load()); }, overrides: { - 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: { - 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: { - 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: { - FlutterVersion: () => FlutterVersion(_testClock), + FlutterVersion: () => FlutterVersion(clock: _testClock), ProcessManager: () => mockProcessManager, Cache: () => mockCache, }); diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index 0813ecc48d..b1616fea2d 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -419,14 +419,7 @@ class FakeXcodeProjectInterpreter implements XcodeProjectInterpreter { List xcrunCommand() => ['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 {} diff --git a/packages/flutter_tools/test/src/testbed.dart b/packages/flutter_tools/test/src/testbed.dart index f0f8a4cf55..44c2b87e78 100644 --- a/packages/flutter_tools/test/src/testbed.dart +++ b/packages/flutter_tools/test/src/testbed.dart @@ -709,9 +709,6 @@ class FakeFlutterVersion implements FlutterVersion { return 'v0.0.0'; } - @override - bool get isMaster => true; - @override String get repositoryUrl => null;