Unverified Commit 18167785 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] wire up alternative invalidation strategy to features (#71439)

parent b1d65e31
...@@ -49,6 +49,9 @@ abstract class FeatureFlags { ...@@ -49,6 +49,9 @@ abstract class FeatureFlags {
/// Whether fast single widget reloads are enabled. /// Whether fast single widget reloads are enabled.
bool get isSingleWidgetReloadEnabled => false; bool get isSingleWidgetReloadEnabled => false;
/// Whether the CFE experimental invalidation strategy is enabled.
bool get isExperimentalInvalidationStrategyEnabled => false;
/// Whether a particular feature is enabled for the current channel. /// Whether a particular feature is enabled for the current channel.
/// ///
/// Prefer using one of the specific getters above instead of this API. /// Prefer using one of the specific getters above instead of this API.
...@@ -92,6 +95,9 @@ class FlutterFeatureFlags implements FeatureFlags { ...@@ -92,6 +95,9 @@ class FlutterFeatureFlags implements FeatureFlags {
@override @override
bool get isSingleWidgetReloadEnabled => isEnabled(singleWidgetReload); bool get isSingleWidgetReloadEnabled => isEnabled(singleWidgetReload);
@override
bool get isExperimentalInvalidationStrategyEnabled => isEnabled(experimentalInvalidationStrategy);
@override @override
bool isEnabled(Feature feature) { bool isEnabled(Feature feature) {
final String currentChannel = _flutterVersion.channel; final String currentChannel = _flutterVersion.channel;
...@@ -125,6 +131,7 @@ const List<Feature> allFeatures = <Feature>[ ...@@ -125,6 +131,7 @@ const List<Feature> allFeatures = <Feature>[
flutterAndroidFeature, flutterAndroidFeature,
flutterIOSFeature, flutterIOSFeature,
flutterFuchsiaFeature, flutterFuchsiaFeature,
experimentalInvalidationStrategy,
]; ];
/// The [Feature] for flutter web. /// The [Feature] for flutter web.
...@@ -274,6 +281,29 @@ const Feature singleWidgetReload = Feature( ...@@ -274,6 +281,29 @@ const Feature singleWidgetReload = Feature(
), ),
); );
/// The CFE experimental invalidation strategy.
const Feature experimentalInvalidationStrategy = Feature(
name: 'Hot reload optimization that reduces incremental artifact size',
configSetting: 'experimental-invalidation-strategy',
environmentOverride: 'FLUTTER_CFE_EXPERIMENTAL_INVALIDATION',
master: FeatureChannelSetting(
available: true,
enabledByDefault: true,
),
dev: FeatureChannelSetting(
available: true,
enabledByDefault: false,
),
beta: FeatureChannelSetting(
available: true,
enabledByDefault: false,
),
stable: FeatureChannelSetting(
available: true,
enabledByDefault: false,
),
);
/// A [Feature] is a process for conditionally enabling tool features. /// A [Feature] is a process for conditionally enabling tool features.
/// ///
/// All settings are optional, and if not provided will generally default to /// All settings are optional, and if not provided will generally default to
......
...@@ -139,12 +139,13 @@ class FlutterDevice { ...@@ -139,12 +139,13 @@ class FlutterDevice {
} else { } else {
// The flutter-widget-cache feature only applies to run mode. // The flutter-widget-cache feature only applies to run mode.
List<String> extraFrontEndOptions = buildInfo.extraFrontEndOptions; List<String> extraFrontEndOptions = buildInfo.extraFrontEndOptions;
if (featureFlags.isSingleWidgetReloadEnabled) { extraFrontEndOptions = <String>[
extraFrontEndOptions = <String>[ if (featureFlags.isSingleWidgetReloadEnabled)
'--flutter-widget-cache', '--flutter-widget-cache',
...?extraFrontEndOptions, if (featureFlags.isExperimentalInvalidationStrategyEnabled)
]; '--enable-experiment=alternative-invalidation-strategy',
} ...?extraFrontEndOptions,
];
generator = ResidentCompiler( generator = ResidentCompiler(
globals.artifacts.getArtifactPath( globals.artifacts.getArtifactPath(
Artifact.flutterPatchedSdkPath, Artifact.flutterPatchedSdkPath,
......
...@@ -2615,6 +2615,33 @@ void main() { ...@@ -2615,6 +2615,33 @@ void main() {
FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true) FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true)
}); });
testUsingContext('FlutterDevice passes alternative-invalidation-strategy flag when feature is enabled', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final MockDevice mockDevice = MockDevice();
when(mockDevice.targetPlatform).thenAnswer((Invocation invocation) async {
return TargetPlatform.android_arm;
});
final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create(
mockDevice,
buildInfo: const BuildInfo(
BuildMode.debug,
'',
treeShakeIcons: false,
extraFrontEndOptions: <String>[],
),
target: null, platform: null,
)).generator as DefaultResidentCompiler;
expect(residentCompiler.extraFrontEndOptions,
contains('--enable-experiment=alternative-invalidation-strategy'));
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isExperimentalInvalidationStrategyEnabled: true)
});
testUsingContext('connect sets up log reader', () => testbed.run(() async { testUsingContext('connect sets up log reader', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final MockDevice mockDevice = MockDevice(); final MockDevice mockDevice = MockDevice();
......
...@@ -730,7 +730,8 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -730,7 +730,8 @@ class TestFeatureFlags implements FeatureFlags {
this.isAndroidEnabled = true, this.isAndroidEnabled = true,
this.isIOSEnabled = true, this.isIOSEnabled = true,
this.isFuchsiaEnabled = false, this.isFuchsiaEnabled = false,
}); this.isExperimentalInvalidationStrategyEnabled = false,
});
@override @override
final bool isLinuxEnabled; final bool isLinuxEnabled;
...@@ -756,6 +757,9 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -756,6 +757,9 @@ class TestFeatureFlags implements FeatureFlags {
@override @override
final bool isFuchsiaEnabled; final bool isFuchsiaEnabled;
@override
final bool isExperimentalInvalidationStrategyEnabled;
@override @override
bool isEnabled(Feature feature) { bool isEnabled(Feature feature) {
switch (feature) { switch (feature) {
...@@ -775,6 +779,8 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -775,6 +779,8 @@ class TestFeatureFlags implements FeatureFlags {
return isIOSEnabled; return isIOSEnabled;
case flutterFuchsiaFeature: case flutterFuchsiaFeature:
return isFuchsiaEnabled; return isFuchsiaEnabled;
case experimentalInvalidationStrategy:
return isExperimentalInvalidationStrategyEnabled;
} }
return false; return false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment