Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 46b5891

Browse files
authored
[Impeller] Respect enable-impeller command line setting over info.plist setting (#40902)
[Impeller] Respect enable-impeller command line setting over info.plist setting
1 parent 4e848dc commit 46b5891

File tree

6 files changed

+72
-16
lines changed

6 files changed

+72
-16
lines changed

shell/common/switches_unittests.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,24 @@ TEST(SwitchesTest, EnableEmbedderAPI) {
9393
}
9494
}
9595

96+
TEST(SwitchesTest, NoEnableImpeller) {
97+
{
98+
// enable
99+
fml::CommandLine command_line =
100+
fml::CommandLineFromInitializerList({"command", "--enable-impeller"});
101+
EXPECT_TRUE(command_line.HasOption("enable-impeller"));
102+
Settings settings = SettingsFromCommandLine(command_line);
103+
EXPECT_EQ(settings.enable_impeller, true);
104+
}
105+
{
106+
// disable
107+
fml::CommandLine command_line = fml::CommandLineFromInitializerList(
108+
{"command", "--enable-impeller=false"});
109+
EXPECT_TRUE(command_line.HasOption("enable-impeller"));
110+
Settings settings = SettingsFromCommandLine(command_line);
111+
EXPECT_EQ(settings.enable_impeller, false);
112+
}
113+
}
114+
96115
} // namespace testing
97116
} // namespace flutter

shell/platform/darwin/common/command_line.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_COMMAND_LINE_H_
66
#define FLUTTER_SHELL_PLATFORM_DARWIN_COMMON_COMMAND_LINE_H_
77

8+
#import <Foundation/Foundation.h>
9+
810
#include "flutter/fml/command_line.h"
911

1012
#include "flutter/fml/macros.h"
1113

1214
namespace flutter {
1315

14-
fml::CommandLine CommandLineFromNSProcessInfo();
16+
fml::CommandLine CommandLineFromNSProcessInfo(
17+
NSProcessInfo* processInfoOrNil = nil);
1518

1619
} // namespace flutter
1720

shell/platform/darwin/common/command_line.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
namespace flutter {
1010

11-
fml::CommandLine CommandLineFromNSProcessInfo() {
11+
fml::CommandLine CommandLineFromNSProcessInfo(NSProcessInfo* processInfoOrNil) {
1212
std::vector<std::string> args_vector;
13+
auto processInfo = processInfoOrNil ? processInfoOrNil : [NSProcessInfo processInfo];
1314

14-
for (NSString* arg in [NSProcessInfo processInfo].arguments) {
15+
for (NSString* arg in processInfo.arguments) {
1516
args_vector.emplace_back(arg.UTF8String);
1617
}
1718

shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@
7676
return [NSBundle bundleWithIdentifier:bundleID];
7777
}
7878

79-
flutter::Settings FLTDefaultSettingsForBundle(NSBundle* bundle) {
80-
auto command_line = flutter::CommandLineFromNSProcessInfo();
79+
flutter::Settings FLTDefaultSettingsForBundle(NSBundle* bundle, NSProcessInfo* processInfoOrNil) {
80+
auto command_line = flutter::CommandLineFromNSProcessInfo(processInfoOrNil);
8181

8282
// Precedence:
83-
// 1. Settings from the specified NSBundle.
83+
// 1. Settings from the specified NSBundle (except for enable-impeller).
8484
// 2. Settings passed explicitly via command-line arguments.
8585
// 3. Settings from the NSBundle with the default bundle ID.
8686
// 4. Settings from the main NSBundle and default values.
@@ -206,15 +206,21 @@
206206
BOOL enableWideGamut = nsEnableWideGamut ? nsEnableWideGamut.boolValue : NO;
207207
settings.enable_wide_gamut = enableWideGamut;
208208

209-
// Whether to enable Impeller. First, look in the app bundle.
210-
NSNumber* enableImpeller = [bundle objectForInfoDictionaryKey:@"FLTEnableImpeller"];
211-
if (enableImpeller == nil) {
212-
// If it isn't in the app bundle, look in the main bundle.
213-
enableImpeller = [mainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"];
214-
}
215-
// Change the default only if the option is present.
216-
if (enableImpeller != nil) {
217-
settings.enable_impeller = enableImpeller.boolValue;
209+
// TODO(dnfield): We should reverse the order for all these settings so that command line options
210+
// are preferred to plist settings. https://github.com/flutter/flutter/issues/124049
211+
// Whether to enable Impeller. If the command line explicitly
212+
// specified an option for this, ignore what's in the plist.
213+
if (!command_line.HasOption("enable-impeller")) {
214+
// Next, look in the app bundle.
215+
NSNumber* enableImpeller = [bundle objectForInfoDictionaryKey:@"FLTEnableImpeller"];
216+
if (enableImpeller == nil) {
217+
// If it isn't in the app bundle, look in the main bundle.
218+
enableImpeller = [mainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"];
219+
}
220+
// Change the default only if the option is present.
221+
if (enableImpeller != nil) {
222+
settings.enable_impeller = enableImpeller.boolValue;
223+
}
218224
}
219225

220226
NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:@"FLTTraceSystrace"];

shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,32 @@ - (void)testEnableImpellerSettingIsCorrectlyParsed {
9393
[mockMainBundle stopMocking];
9494
}
9595

96+
- (void)testEnableImpellerSettingIsCorrectlyOverriddenByCommandLine {
97+
id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
98+
OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"]).andReturn(@"NO");
99+
id mockProcessInfo = OCMPartialMock([NSProcessInfo processInfo]);
100+
NSArray* arguments = @[ @"process_name", @"--enable-impeller" ];
101+
OCMStub([mockProcessInfo arguments]).andReturn(arguments);
102+
103+
auto settings = FLTDefaultSettingsForBundle(nil, mockProcessInfo);
104+
// Check settings.enable_impeller value is same as the value on command line.
105+
XCTAssertEqual(settings.enable_impeller, YES);
106+
[mockMainBundle stopMocking];
107+
}
108+
109+
- (void)testDisableImpellerSettingIsCorrectlyOverriddenByCommandLine {
110+
id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
111+
OCMStub([mockMainBundle objectForInfoDictionaryKey:@"FLTEnableImpeller"]).andReturn(@"YES");
112+
id mockProcessInfo = OCMPartialMock([NSProcessInfo processInfo]);
113+
NSArray* arguments = @[ @"process_name", @"--enable-impeller=false" ];
114+
OCMStub([mockProcessInfo arguments]).andReturn(arguments);
115+
116+
auto settings = FLTDefaultSettingsForBundle(nil, mockProcessInfo);
117+
// Check settings.enable_impeller value is same as the value on command line.
118+
XCTAssertEqual(settings.enable_impeller, NO);
119+
[mockMainBundle stopMocking];
120+
}
121+
96122
- (void)testDisableImpellerAppBundleSettingIsCorrectlyParsed {
97123
NSString* bundleId = [FlutterDartProject defaultBundleIdentifier];
98124
id mockAppBundle = OCMClassMock([NSBundle class]);

shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ NS_ASSUME_NONNULL_BEGIN
1414

1515
NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL);
1616

17-
flutter::Settings FLTDefaultSettingsForBundle(NSBundle* bundle = nil);
17+
flutter::Settings FLTDefaultSettingsForBundle(NSBundle* _Nullable bundle = nil,
18+
NSProcessInfo* _Nullable processInfoOrNil = nil);
1819

1920
@interface FlutterDartProject ()
2021

0 commit comments

Comments
 (0)