From 1b07c3d798caabd1b38aef203420809cfad3e92d Mon Sep 17 00:00:00 2001 From: hellohuanlin <41930132+hellohuanlin@users.noreply.github.com> Date: Mon, 17 Jul 2023 15:21:07 -0700 Subject: [PATCH] [tools/ios_build_ipa] fallback to CFBundleName if CFBundleDisplayName is absent (#130752) The display name will fallback to CFBundleName if CFBundleDisplayName is absent. *List which issues are fixed by this PR. You must list at least one issue.* Fixes https://github.com/flutter/flutter/issues/120553 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].* --- .../lib/src/commands/build_ios.dart | 3 +- .../lib/src/ios/plist_parser.dart | 1 + .../hermetic/build_ipa_test.dart | 58 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/commands/build_ios.dart b/packages/flutter_tools/lib/src/commands/build_ios.dart index 27a483aa08c..211bf2f16c7 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios.dart @@ -378,7 +378,8 @@ class BuildIOSArchiveCommand extends _BuildIOSSubCommand { xcodeProjectSettingsMap['Version Number'] = globals.plistParser.getValueFromFile(plistPath, PlistParser.kCFBundleShortVersionStringKey); xcodeProjectSettingsMap['Build Number'] = globals.plistParser.getValueFromFile(plistPath, PlistParser.kCFBundleVersionKey); - xcodeProjectSettingsMap['Display Name'] = globals.plistParser.getValueFromFile(plistPath, PlistParser.kCFBundleDisplayNameKey); + xcodeProjectSettingsMap['Display Name'] = globals.plistParser.getValueFromFile(plistPath, PlistParser.kCFBundleDisplayNameKey) + ?? globals.plistParser.getValueFromFile(plistPath, PlistParser.kCFBundleNameKey); xcodeProjectSettingsMap['Deployment Target'] = globals.plistParser.getValueFromFile(plistPath, PlistParser.kMinimumOSVersionKey); xcodeProjectSettingsMap['Bundle Identifier'] = globals.plistParser.getValueFromFile(plistPath, PlistParser.kCFBundleIdentifierKey); diff --git a/packages/flutter_tools/lib/src/ios/plist_parser.dart b/packages/flutter_tools/lib/src/ios/plist_parser.dart index f6e1a9fe7cc..de40cedff8e 100644 --- a/packages/flutter_tools/lib/src/ios/plist_parser.dart +++ b/packages/flutter_tools/lib/src/ios/plist_parser.dart @@ -30,6 +30,7 @@ class PlistParser { static const String kCFBundleExecutableKey = 'CFBundleExecutable'; static const String kCFBundleVersionKey = 'CFBundleVersion'; static const String kCFBundleDisplayNameKey = 'CFBundleDisplayName'; + static const String kCFBundleNameKey = 'CFBundleName'; static const String kMinimumOSVersionKey = 'MinimumOSVersion'; static const String kNSPrincipalClassKey = 'NSPrincipalClass'; diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart index 622be93c1fd..11f65819e1c 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart @@ -954,6 +954,8 @@ void main() { plistUtils.fileContents[plistPath] = { 'CFBundleIdentifier': 'io.flutter.someProject', 'CFBundleDisplayName': 'Awesome Gallery', + // Will not use CFBundleName since CFBundleDisplayName is present. + 'CFBundleName': 'Awesome Gallery 2', 'MinimumOSVersion': '11.0', 'CFBundleVersion': '666', 'CFBundleShortVersionString': '12.34.56', @@ -992,6 +994,62 @@ void main() { PlistParser: () => plistUtils, }); + testUsingContext( + 'Validate basic Xcode settings with CFBundleDisplayName fallback to CFBundleName', () async { + const String plistPath = 'build/ios/archive/Runner.xcarchive/Products/Applications/Runner.app/Info.plist'; + fakeProcessManager.addCommands([ + xattrCommand, + setUpFakeXcodeBuildHandler(onRun: () { + fileSystem.file(plistPath).createSync(recursive: true); + }), + exportArchiveCommand(exportOptionsPlist: _exportOptionsPlist), + ]); + + createMinimalMockProjectFiles(); + + plistUtils.fileContents[plistPath] = { + 'CFBundleIdentifier': 'io.flutter.someProject', + // Will use CFBundleName since CFBundleDisplayName is absent. + 'CFBundleName': 'Awesome Gallery', + 'MinimumOSVersion': '11.0', + 'CFBundleVersion': '666', + 'CFBundleShortVersionString': '12.34.56', + }; + + final BuildCommand command = BuildCommand( + androidSdk: FakeAndroidSdk(), + buildSystem: TestBuildSystem.all(BuildResult(success: true)), + fileSystem: MemoryFileSystem.test(), + logger: BufferLogger.test(), + osUtils: FakeOperatingSystemUtils(), + ); + await createTestCommandRunner(command).run( + ['build', 'ipa', '--no-pub']); + + expect( + testLogger.statusText, + contains( + '[✓] App Settings Validation\n' + ' • Version Number: 12.34.56\n' + ' • Build Number: 666\n' + ' • Display Name: Awesome Gallery\n' + ' • Deployment Target: 11.0\n' + ' • Bundle Identifier: io.flutter.someProject\n' + ) + ); + expect( + testLogger.statusText, + contains('To update the settings, please refer to https://docs.flutter.dev/deployment/ios') + ); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => fakeProcessManager, + Platform: () => macosPlatform, + XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(), + PlistParser: () => plistUtils, + }); + + testUsingContext( 'Validate basic Xcode settings with default bundle identifier prefix', () async { const String plistPath = 'build/ios/archive/Runner.xcarchive/Products/Applications/Runner.app/Info.plist';