From 1cfe6487a6526b4c154c77a17e580e393f734445 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Tue, 5 Nov 2024 13:51:18 -0800 Subject: [PATCH] iOS: Use standard Obj-C cflags for ios_test_flutter (flutter/engine#56384) Previously, we had not enabled standard iOS cflags for `ios_test_flutter`, though ARC had been manually added to the cflags. This meant that the following flags were not enabled: * -Werror=overriding-method-mismatch * -Werror=undeclared-selector Both of these existed in the code within this target: * undeclared-selector: `insertionPointColor` was a non-public selector on UITextInput prior to iOS 17. * overriding-method-mismatch: `FakeFlutterUndoManagerDelegate`, which implements the `FlutterUndoManagerDelegate` protocol, declared `initWithUndoManager:activeInputView:` with a different type for `activeInputView`. This was a hack to jam in a test mock object that didn't match the required type for the property. Conveniently we have a class (`FlutterTextInputView`) that implements the required type and protocol (`UIView`). Issue: https://github.com/flutter/flutter/issues/137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../shell/platform/darwin/ios/BUILD.gn | 14 ++++++----- .../Source/FlutterTextInputPluginTest.mm | 6 +++-- .../Source/FlutterUndoManagerPluginTest.mm | 25 +++++-------------- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index 76db728261..48be279cd9 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -198,18 +198,20 @@ platform_frameworks_path = shared_library("ios_test_flutter") { testonly = true visibility = [ "*" ] + + # Xcode 15 beta has a bug where iOS 17 API usage is not guarded. + # This bug results engine build failure since the engine treats warnings as errors. + # The `-Wno-unguarded-availability-new` can be removed when the Xcode bug is fixed. + # See details in https://github.com/flutter/flutter/issues/128958. + cflags_objc = flutter_cflags_objc_arc + cflags_objcc = + flutter_cflags_objcc_arc + [ "-Wno-unguarded-availability-new" ] cflags = [ "-fvisibility=default", "-F$platform_frameworks_path", - "-fobjc-arc", "-mios-simulator-version-min=$ios_testing_deployment_target", ] - # XCode 15 beta has a bug where iOS 17 API usage is not guarded. - # This bug results engine build failure since the engine treats warnings as errors. - # The `-Wno-unguarded-availability-new` can be removed when the XCode bug is fixed. - # See details in https://github.com/flutter/flutter/issues/128958. - cflags_objcc = [ "-Wno-unguarded-availability-new" ] ldflags = [ "-F$platform_frameworks_path", "-Wl,-install_name,@rpath/Frameworks/libios_test_flutter.dylib", diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm index cd75d64dc9..d8c16103b4 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.mm @@ -834,8 +834,10 @@ FLUTTER_ASSERT_ARC - (void)testFlutterTextInputViewOnlyRespondsToInsertionPointColorBelowIOS17 { FlutterTextInputView* inputView = [[FlutterTextInputView alloc] initWithOwner:textInputPlugin]; - BOOL respondsToInsertionPointColor = - [inputView respondsToSelector:@selector(insertionPointColor)]; + // [UITextInputTraits insertionPointColor] is non-public API, so @selector(insertionPointColor) + // would generate a compile-time warning. + SEL insertionPointColor = NSSelectorFromString(@"insertionPointColor"); + BOOL respondsToInsertionPointColor = [inputView respondsToSelector:insertionPointColor]; if (@available(iOS 17, *)) { XCTAssertFalse(respondsToInsertionPointColor); } else { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm index d5d445ca62..261b421b17 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPluginTest.mm @@ -8,37 +8,24 @@ #import #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" +#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h" FLUTTER_ASSERT_ARC -/// OCMock does not allow mocking both class and protocol. Use this to mock the methods used on -/// `UIView*` in the plugin. -@interface TextInputViewTest : NSObject - -@property(nonatomic, weak) id inputDelegate; -@property(nonatomic, readonly) UITextInputAssistantItem* inputAssistantItem; - -@end - -@implementation TextInputViewTest -@end - @interface FakeFlutterUndoManagerDelegate : NSObject @property(readonly) NSUInteger undoCount; @property(readonly) NSUInteger redoCount; @property(nonatomic, nullable) NSUndoManager* undoManager; +@property(nonatomic, nullable) UIView* activeTextInputView; - (instancetype)initWithUndoManager:(NSUndoManager*)undoManager - activeTextInputView:(TextInputViewTest*)activeTextInputView; + activeTextInputView:(UIView*)activeTextInputView; @end @implementation FakeFlutterUndoManagerDelegate -@synthesize undoManager = _undoManager; -@synthesize activeTextInputView = _activeTextInputView; - - (instancetype)initWithUndoManager:(NSUndoManager*)undoManager activeTextInputView:(UIView*)activeTextInputView { self = [super init]; @@ -62,7 +49,7 @@ FLUTTER_ASSERT_ARC @interface FlutterUndoManagerPluginTest : XCTestCase @property(nonatomic) FakeFlutterUndoManagerDelegate* undoManagerDelegate; @property(nonatomic) FlutterUndoManagerPlugin* undoManagerPlugin; -@property(nonatomic) TextInputViewTest* activeTextInputView; +@property(nonatomic) UIView* activeTextInputView; @property(nonatomic) NSUndoManager* undoManager; @end @@ -72,7 +59,7 @@ FLUTTER_ASSERT_ARC [super setUp]; self.undoManager = OCMClassMock([NSUndoManager class]); - self.activeTextInputView = OCMClassMock([TextInputViewTest class]); + self.activeTextInputView = OCMClassMock([FlutterTextInputView class]); self.undoManagerDelegate = [[FakeFlutterUndoManagerDelegate alloc] initWithUndoManager:self.undoManager @@ -170,7 +157,7 @@ FLUTTER_ASSERT_ARC // Use a real undo manager. NSUndoManager* undoManager = [[NSUndoManager alloc] init]; @autoreleasepool { - id activeTextInputView = OCMClassMock([TextInputViewTest class]); + id activeTextInputView = OCMClassMock([FlutterTextInputView class]); FakeFlutterUndoManagerDelegate* undoManagerDelegate = [[FakeFlutterUndoManagerDelegate alloc] initWithUndoManager:undoManager