From 9c212d5d0dd21d58fbf181c7881aa98ff54d3011 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 15 Apr 2024 17:06:05 -0700 Subject: [PATCH] [iOS] allow enabling asserts from Plist. (flutter/engine#52069) Part of https://github.com/flutter/flutter/issues/145729 . I don't believe (or wasn't able to find ) if there is a way to specify dart-vm flags from an iOS application. Once its installed, the tool provided process args won't work. By allowing this to be specified in the Plist, developers can ensure the value persists for subsequent launches. --- .../ios/framework/Source/FlutterDartProject.mm | 5 +++++ .../ios/framework/Source/FlutterDartProjectTest.mm | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 716d26d903..cec9bd4a34 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -210,6 +210,11 @@ flutter::Settings FLTDefaultSettingsForBundle(NSBundle* bundle, NSProcessInfo* p settings.trace_systrace = enableTraceSystrace.boolValue; } + NSNumber* enableDartAsserts = [mainBundle objectForInfoDictionaryKey:@"FLTEnableDartAsserts"]; + if (enableDartAsserts != nil) { + settings.dart_flags.push_back("--enable-asserts"); + } + NSNumber* enableDartProfiling = [mainBundle objectForInfoDictionaryKey:@"FLTEnableDartProfiling"]; // Change the default only if the option is present. if (enableDartProfiling != nil) { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm index c68018bbde..19c7d4fc66 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm @@ -263,6 +263,20 @@ FLUTTER_ASSERT_ARC [mockMainBundle stopMocking]; } +- (void)testEnableDartAssertsCommandLineArgument { + id mockMainBundle = OCMPartialMock([NSBundle mainBundle]); + OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTEnableDartAsserts"]).andReturn(@"YES"); + id mockProcessInfo = OCMPartialMock([NSProcessInfo processInfo]); + NSArray* arguments = @[ @"process_name" ]; + OCMStub([mockProcessInfo arguments]).andReturn(arguments); + + auto settings = FLTDefaultSettingsForBundle(nil, mockProcessInfo); + + XCTAssertEqual(settings.dart_flags.size(), 1u); + XCTAssertEqual(settings.dart_flags[0], "--enable-asserts"); + [mockMainBundle stopMocking]; +} + - (void)testDisableImpellerSettingIsCorrectlyOverriddenByCommandLine { id mockMainBundle = OCMPartialMock([NSBundle mainBundle]); OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"]).andReturn(@"YES");