mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> ### Overview This splits the Swift Package Manager feature in two: 1. **SwiftPM feature**: This builds plugins using SwiftPM (if the app supports it), and, uses the new app & plugin templates that support SwiftPM 2. **SwiftPM app migration feature**: this updates an existing Flutter iOS or macOS app to support Swift Package Manager. This feature requires the SwiftPM feature - if SwiftPM is off, the app migration is also off. For now, both features are off by default. We plan to turn on the first feature in the next stable release. The app migration feature will be stay off by default until we have higher confidence in the migration. See this mini design doc: https://github.com/flutter/flutter/issues/151567#issuecomment-2455941279 Here's the PR that updates the SwiftPM docs: https://github.com/flutter/website/pull/11495 Part of https://github.com/flutter/flutter/issues/151567 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
470 lines
17 KiB
Dart
470 lines
17 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter_tools/src/base/config.dart';
|
|
import 'package:flutter_tools/src/base/platform.dart';
|
|
import 'package:flutter_tools/src/features.dart';
|
|
import 'package:flutter_tools/src/flutter_features.dart';
|
|
|
|
import '../src/common.dart';
|
|
import '../src/fakes.dart';
|
|
|
|
void main() {
|
|
group('Features', () {
|
|
late Config testConfig;
|
|
late FakePlatform platform;
|
|
late FlutterFeatureFlags featureFlags;
|
|
|
|
setUp(() {
|
|
testConfig = Config.test();
|
|
platform = FakePlatform(environment: <String, String>{});
|
|
|
|
for (final Feature feature in allConfigurableFeatures) {
|
|
testConfig.setValue(feature.configSetting!, false);
|
|
}
|
|
|
|
featureFlags = FlutterFeatureFlags(
|
|
flutterVersion: FakeFlutterVersion(),
|
|
config: testConfig,
|
|
platform: platform,
|
|
);
|
|
});
|
|
|
|
FeatureFlags createFlags(String channel) {
|
|
return FlutterFeatureFlags(
|
|
flutterVersion: FakeFlutterVersion(branch: channel),
|
|
config: testConfig,
|
|
platform: platform,
|
|
);
|
|
}
|
|
|
|
testWithoutContext('setting has safe defaults', () {
|
|
const FeatureChannelSetting featureSetting = FeatureChannelSetting();
|
|
|
|
expect(featureSetting.available, false);
|
|
expect(featureSetting.enabledByDefault, false);
|
|
});
|
|
|
|
testWithoutContext('has safe defaults', () {
|
|
const Feature feature = Feature(name: 'example');
|
|
|
|
expect(feature.name, 'example');
|
|
expect(feature.environmentOverride, null);
|
|
expect(feature.configSetting, null);
|
|
});
|
|
|
|
testWithoutContext('retrieves the correct setting for each branch', () {
|
|
const FeatureChannelSetting masterSetting = FeatureChannelSetting(available: true);
|
|
const FeatureChannelSetting betaSetting = FeatureChannelSetting(available: true);
|
|
const FeatureChannelSetting stableSetting = FeatureChannelSetting(available: true);
|
|
const Feature feature = Feature(
|
|
name: 'example',
|
|
master: masterSetting,
|
|
beta: betaSetting,
|
|
stable: stableSetting,
|
|
);
|
|
|
|
expect(feature.getSettingForChannel('master'), masterSetting);
|
|
expect(feature.getSettingForChannel('beta'), betaSetting);
|
|
expect(feature.getSettingForChannel('stable'), stableSetting);
|
|
expect(feature.getSettingForChannel('unknown'), masterSetting);
|
|
});
|
|
|
|
testWithoutContext('env variables are only enabled with "true" string', () {
|
|
platform.environment = <String, String>{'FLUTTER_WEB': 'hello'};
|
|
|
|
expect(featureFlags.isWebEnabled, false);
|
|
|
|
platform.environment = <String, String>{'FLUTTER_WEB': 'true'};
|
|
|
|
expect(featureFlags.isWebEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter web help string', () {
|
|
expect(flutterWebFeature.generateHelpMessage(), 'Enable or disable Flutter for web.');
|
|
});
|
|
|
|
testWithoutContext('Flutter macOS desktop help string', () {
|
|
expect(
|
|
flutterMacOSDesktopFeature.generateHelpMessage(),
|
|
'Enable or disable support for desktop on macOS.',
|
|
);
|
|
});
|
|
|
|
testWithoutContext('Flutter Linux desktop help string', () {
|
|
expect(
|
|
flutterLinuxDesktopFeature.generateHelpMessage(),
|
|
'Enable or disable support for desktop on Linux.',
|
|
);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop help string', () {
|
|
expect(
|
|
flutterWindowsDesktopFeature.generateHelpMessage(),
|
|
'Enable or disable support for desktop on Windows.',
|
|
);
|
|
});
|
|
|
|
testWithoutContext('help string on multiple channels', () {
|
|
const Feature testWithoutContextFeature = Feature(
|
|
name: 'example',
|
|
master: FeatureChannelSetting(available: true),
|
|
beta: FeatureChannelSetting(available: true),
|
|
stable: FeatureChannelSetting(available: true),
|
|
configSetting: 'foo',
|
|
);
|
|
|
|
expect(testWithoutContextFeature.generateHelpMessage(), 'Enable or disable example.');
|
|
});
|
|
|
|
/// Flutter Web
|
|
|
|
testWithoutContext('Flutter web off by default on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
|
|
expect(featureFlags.isWebEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter web enabled with config on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
testConfig.setValue('enable-web', true);
|
|
|
|
expect(featureFlags.isWebEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter web enabled with environment variable on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
platform.environment = <String, String>{'FLUTTER_WEB': 'true'};
|
|
|
|
expect(featureFlags.isWebEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter web off by default on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
|
|
expect(featureFlags.isWebEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter web enabled with config on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
testConfig.setValue('enable-web', true);
|
|
|
|
expect(featureFlags.isWebEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter web not enabled with environment variable on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
platform.environment = <String, String>{'FLUTTER_WEB': 'true'};
|
|
|
|
expect(featureFlags.isWebEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter web on by default on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
testConfig.removeValue('enable-web');
|
|
|
|
expect(featureFlags.isWebEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter web enabled with config on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
testConfig.setValue('enable-web', true);
|
|
|
|
expect(featureFlags.isWebEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter web not enabled with environment variable on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
platform.environment = <String, String>{'FLUTTER_WEB': 'enabled'};
|
|
|
|
expect(featureFlags.isWebEnabled, false);
|
|
});
|
|
|
|
/// Flutter macOS desktop.
|
|
|
|
testWithoutContext('Flutter macos desktop off by default on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
|
|
expect(featureFlags.isMacOSEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter macos desktop enabled with config on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
testConfig.setValue('enable-macos-desktop', true);
|
|
|
|
expect(featureFlags.isMacOSEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter macos desktop enabled with environment variable on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
platform.environment = <String, String>{'FLUTTER_MACOS': 'true'};
|
|
|
|
expect(featureFlags.isMacOSEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter macos desktop off by default on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
|
|
expect(featureFlags.isMacOSEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter macos desktop enabled with config on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
testConfig.setValue('enable-macos-desktop', true);
|
|
|
|
expect(featureFlags.isMacOSEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter macos desktop enabled with environment variable on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
platform.environment = <String, String>{'FLUTTER_MACOS': 'true'};
|
|
|
|
expect(featureFlags.isMacOSEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter macos desktop off by default on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
|
|
expect(featureFlags.isMacOSEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter macos desktop enabled with config on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
testConfig.setValue('enable-macos-desktop', true);
|
|
|
|
expect(featureFlags.isMacOSEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter macos desktop enabled with environment variable on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
platform.environment = <String, String>{'FLUTTER_MACOS': 'true'};
|
|
|
|
expect(featureFlags.isMacOSEnabled, true);
|
|
});
|
|
|
|
/// Flutter Linux Desktop
|
|
testWithoutContext('Flutter linux desktop off by default on master', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
|
|
expect(featureFlags.isLinuxEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter linux desktop enabled with config on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
testConfig.setValue('enable-linux-desktop', true);
|
|
|
|
expect(featureFlags.isLinuxEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter linux desktop enabled with environment variable on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
platform.environment = <String, String>{'FLUTTER_LINUX': 'true'};
|
|
|
|
expect(featureFlags.isLinuxEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter linux desktop off by default on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
|
|
expect(featureFlags.isLinuxEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter linux desktop enabled with config on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
testConfig.setValue('enable-linux-desktop', true);
|
|
|
|
expect(featureFlags.isLinuxEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter linux desktop enabled with environment variable on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
platform.environment = <String, String>{'FLUTTER_LINUX': 'true'};
|
|
|
|
expect(featureFlags.isLinuxEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter linux desktop off by default on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
|
|
expect(featureFlags.isLinuxEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter linux desktop enabled with config on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
testConfig.setValue('enable-linux-desktop', true);
|
|
|
|
expect(featureFlags.isLinuxEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter linux desktop enabled with environment variable on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
platform.environment = <String, String>{'FLUTTER_LINUX': 'true'};
|
|
|
|
expect(featureFlags.isLinuxEnabled, true);
|
|
});
|
|
|
|
/// Flutter Windows desktop.
|
|
testWithoutContext('Flutter Windows desktop off by default on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
|
|
expect(featureFlags.isWindowsEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop enabled with config on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
testConfig.setValue('enable-windows-desktop', true);
|
|
|
|
expect(featureFlags.isWindowsEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop enabled with environment variable on master', () {
|
|
final FeatureFlags featureFlags = createFlags('master');
|
|
platform.environment = <String, String>{'FLUTTER_WINDOWS': 'true'};
|
|
|
|
expect(featureFlags.isWindowsEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop off by default on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
|
|
expect(featureFlags.isWindowsEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop enabled with config on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
testConfig.setValue('enable-windows-desktop', true);
|
|
|
|
expect(featureFlags.isWindowsEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop enabled with environment variable on beta', () {
|
|
final FeatureFlags featureFlags = createFlags('beta');
|
|
platform.environment = <String, String>{'FLUTTER_WINDOWS': 'true'};
|
|
|
|
expect(featureFlags.isWindowsEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop off by default on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
|
|
expect(featureFlags.isWindowsEnabled, false);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop enabled with config on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
testConfig.setValue('enable-windows-desktop', true);
|
|
|
|
expect(featureFlags.isWindowsEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Flutter Windows desktop enabled with environment variable on stable', () {
|
|
final FeatureFlags featureFlags = createFlags('stable');
|
|
platform.environment = <String, String>{'FLUTTER_WINDOWS': 'true'};
|
|
|
|
expect(featureFlags.isWindowsEnabled, true);
|
|
});
|
|
|
|
for (final Feature feature in <Feature>[
|
|
flutterWindowsDesktopFeature,
|
|
flutterMacOSDesktopFeature,
|
|
flutterLinuxDesktopFeature,
|
|
]) {
|
|
test('${feature.name} available and enabled by default on master', () {
|
|
expect(feature.master.enabledByDefault, true);
|
|
expect(feature.master.available, true);
|
|
});
|
|
test('${feature.name} available and enabled by default on beta', () {
|
|
expect(feature.beta.enabledByDefault, true);
|
|
expect(feature.beta.available, true);
|
|
});
|
|
test('${feature.name} available and enabled by default on stable', () {
|
|
expect(feature.stable.enabledByDefault, true);
|
|
expect(feature.stable.available, true);
|
|
});
|
|
}
|
|
|
|
// Custom devices on all channels
|
|
for (final String channel in <String>['master', 'beta', 'stable']) {
|
|
testWithoutContext('Custom devices are enabled with flag on $channel', () {
|
|
final FeatureFlags featureFlags = createFlags(channel);
|
|
testConfig.setValue('enable-custom-devices', true);
|
|
expect(featureFlags.areCustomDevicesEnabled, true);
|
|
});
|
|
|
|
testWithoutContext('Custom devices are enabled with environment variable on $channel', () {
|
|
final FeatureFlags featureFlags = createFlags(channel);
|
|
platform.environment = <String, String>{'FLUTTER_CUSTOM_DEVICES': 'true'};
|
|
expect(featureFlags.areCustomDevicesEnabled, true);
|
|
});
|
|
}
|
|
|
|
test('${nativeAssets.name} availability and default enabled', () {
|
|
expect(nativeAssets.master.enabledByDefault, false);
|
|
expect(nativeAssets.master.available, true);
|
|
expect(nativeAssets.beta.enabledByDefault, false);
|
|
expect(nativeAssets.beta.available, false);
|
|
expect(nativeAssets.stable.enabledByDefault, false);
|
|
expect(nativeAssets.stable.available, false);
|
|
});
|
|
|
|
group('Swift Package Manager feature', () {
|
|
testWithoutContext('availability and default enabled', () {
|
|
expect(swiftPackageManager.master.enabledByDefault, false);
|
|
expect(swiftPackageManager.master.available, true);
|
|
expect(swiftPackageManager.beta.enabledByDefault, false);
|
|
expect(swiftPackageManager.beta.available, true);
|
|
expect(swiftPackageManager.stable.enabledByDefault, false);
|
|
expect(swiftPackageManager.stable.available, true);
|
|
});
|
|
|
|
testWithoutContext('can be enabled', () {
|
|
platform.environment = <String, String>{'FLUTTER_SWIFT_PACKAGE_MANAGER': 'true'};
|
|
|
|
expect(featureFlags.isSwiftPackageManagerEnabled, isTrue);
|
|
});
|
|
});
|
|
|
|
group('Swift Package Manager app migration feature', () {
|
|
testWithoutContext('availability and default enabled', () {
|
|
expect(swiftPackageManagerMigration.master.enabledByDefault, false);
|
|
expect(swiftPackageManagerMigration.master.available, true);
|
|
expect(swiftPackageManagerMigration.beta.enabledByDefault, false);
|
|
expect(swiftPackageManagerMigration.beta.available, true);
|
|
expect(swiftPackageManagerMigration.stable.enabledByDefault, false);
|
|
expect(swiftPackageManagerMigration.stable.available, true);
|
|
});
|
|
|
|
testWithoutContext('requires Swift Package Manager feature', () {
|
|
platform.environment = <String, String>{
|
|
'FLUTTER_SWIFT_PACKAGE_MANAGER': 'false',
|
|
'FLUTTER_SWIFT_PACKAGE_MANAGER_MIGRATION': 'true',
|
|
};
|
|
|
|
expect(featureFlags.isSwiftPackageManagerEnabled, isFalse);
|
|
expect(featureFlags.isSwiftPackageManagerMigrationEnabled, isFalse);
|
|
});
|
|
|
|
testWithoutContext('is separate from the Swift Package Manager feature', () {
|
|
platform.environment = <String, String>{
|
|
'FLUTTER_SWIFT_PACKAGE_MANAGER': 'true',
|
|
'FLUTTER_SWIFT_PACKAGE_MANAGER_MIGRATION': 'false',
|
|
};
|
|
|
|
expect(featureFlags.isSwiftPackageManagerEnabled, isTrue);
|
|
expect(featureFlags.isSwiftPackageManagerMigrationEnabled, isFalse);
|
|
});
|
|
|
|
testWithoutContext('can be enabled', () {
|
|
platform.environment = <String, String>{
|
|
'FLUTTER_SWIFT_PACKAGE_MANAGER': 'true',
|
|
'FLUTTER_SWIFT_PACKAGE_MANAGER_MIGRATION': 'true',
|
|
};
|
|
|
|
expect(featureFlags.isSwiftPackageManagerEnabled, isTrue);
|
|
expect(featureFlags.isSwiftPackageManagerEnabled, isTrue);
|
|
});
|
|
});
|
|
});
|
|
}
|