From 22247cd55cfffb0d066d8e0184aeb040634c6a70 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 2 Oct 2024 09:13:25 -0700 Subject: [PATCH] Add deprecation warning for "flutter create --ios-language" (#155867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Objective-C `flutter create --ios-language objc` template will be removed in https://github.com/flutter/flutter/issues/148586. Add a deprecation warning when this flag is passed. Add an additional warning when Objective-C is specified requesting the user's use-case. Do not show the warning when creating the module, as Swift is not supported for it yet https://github.com/flutter/flutter/issues/23955 ![Screenshot 2024-09-27 at 8 54 16 PM](https://github.com/user-attachments/assets/112be47f-a5bd-4f57-9a9d-c96c7bbc8ac3) Part of https://github.com/flutter/flutter/issues/148586 --- .../lib/src/commands/create.dart | 7 +++++ .../lib/src/commands/create_base.dart | 5 ++-- .../commands.shard/permeable/create_test.dart | 30 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 992c6914b7..761202e629 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -258,6 +258,13 @@ class CreateCommand extends CreateBase { 'template: the language will always be C or C++.', exitCode: 2, ); + } else if (argResults!.wasParsed('ios-language')) { + globals.printWarning( + 'The "ios-language" option is deprecated and will be removed in a future Flutter release.'); + if (stringArg('ios-language') == 'objc') { + globals.printWarning( + 'Please comment in https://github.com/flutter/flutter/issues/148586 describing your use-case for using Objective-C instead of Swift.'); + } } final String organization = await getOrganization(); diff --git a/packages/flutter_tools/lib/src/commands/create_base.dart b/packages/flutter_tools/lib/src/commands/create_base.dart index 7ae2d59967..76ff09a32b 100644 --- a/packages/flutter_tools/lib/src/commands/create_base.dart +++ b/packages/flutter_tools/lib/src/commands/create_base.dart @@ -100,14 +100,15 @@ abstract class CreateBase extends FlutterCommand { abbr: 'i', defaultsTo: 'swift', allowed: ['objc', 'swift'], - help: 'The language to use for iOS-specific code, either Objective-C (legacy) or Swift (recommended).' + help: '(deprecated) The language to use for iOS-specific code, either Swift (recommended) or Objective-C (legacy).', + hide: !verboseHelp, ); argParser.addOption( 'android-language', abbr: 'a', defaultsTo: 'kotlin', allowed: ['java', 'kotlin'], - help: 'The language to use for Android-specific code, either Java (legacy) or Kotlin (recommended).', + help: 'The language to use for Android-specific code, either Kotlin (recommended) or Java (legacy).', ); argParser.addFlag( 'skip-name-checks', diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart index 7c0ee8963e..bb2e1419bf 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart @@ -1686,6 +1686,36 @@ void main() { expect(displayName, 'My Project'); }); + testUsingContext('should not show --ios-language deprecation warning issue for Swift', () async { + Cache.flutterRoot = '../..'; + + final CreateCommand command = CreateCommand(); + final CommandRunner runner = createTestCommandRunner(command); + + await runner.run(['create', '--no-pub', '--ios-language=swift', projectDir.path]); + expect(logger.warningText, contains('The "ios-language" option is deprecated and will be removed in a future Flutter release.')); + expect(logger.warningText, isNot(contains('https://github.com/flutter/flutter/issues/148586'))); + + }, overrides: { + FeatureFlags: () => TestFeatureFlags(), + Logger: () => logger, + }); + + testUsingContext('should show --ios-language deprecation warning issue for Objective-C', () async { + Cache.flutterRoot = '../..'; + + final CreateCommand command = CreateCommand(); + final CommandRunner runner = createTestCommandRunner(command); + + await runner.run(['create', '--no-pub', '--ios-language=objc', projectDir.path]); + expect(logger.warningText, contains('The "ios-language" option is deprecated and will be removed in a future Flutter release.')); + expect(logger.warningText, contains('https://github.com/flutter/flutter/issues/148586')); + + }, overrides: { + FeatureFlags: () => TestFeatureFlags(), + Logger: () => logger, + }); + testUsingContext('has correct content and formatting with macOS app template', () async { Cache.flutterRoot = '../..';