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

[flutter_tools] add tool feature/scaffold for UWP (#77399)

parent a0ba6464
......@@ -111,6 +111,8 @@ class ApplicationPackageFactory {
return applicationBinary == null
? FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia)
: FuchsiaApp.fromPrebuiltApp(applicationBinary);
case TargetPlatform.windows_uwp_x64:
throw UnsupportedError('Cannot build for windows_uwp_x64');
}
assert(platform != null);
return null;
......
......@@ -521,6 +521,9 @@ class CachedArtifacts implements Artifacts {
case TargetPlatform.android:
assert(false, 'cannot use TargetPlatform.android to look up artifacts');
return null;
case TargetPlatform.windows_uwp_x64:
assert(false, 'cannot use TargetPlatform.windows_uwp_x64 to look up artifacts');
return null;
}
assert(false, 'Invalid platform $platform.');
return null;
......
......@@ -485,6 +485,7 @@ enum TargetPlatform {
linux_x64,
linux_arm64,
windows_x64,
windows_uwp_x64,
fuchsia_arm64,
fuchsia_x64,
tester,
......@@ -578,10 +579,12 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch}
return 'darwin-x64';
case TargetPlatform.linux_x64:
return 'linux-x64';
case TargetPlatform.linux_arm64:
case TargetPlatform.linux_arm64:
return 'linux-arm64';
case TargetPlatform.windows_x64:
return 'windows-x64';
case TargetPlatform.windows_uwp_x64:
return 'windows-uwp-x64';
case TargetPlatform.fuchsia_arm64:
return 'fuchsia-arm64';
case TargetPlatform.fuchsia_x64:
......
......@@ -418,6 +418,7 @@ class FlutterDeviceManager extends DeviceManager {
logger: logger,
fileSystem: fileSystem,
windowsWorkflow: windowsWorkflow,
featureFlags: featureFlags,
),
WebDevices(
featureFlags: featureFlags,
......
......@@ -54,6 +54,9 @@ abstract class FeatureFlags {
/// Whether the CFE experimental invalidation strategy is enabled.
bool get isExperimentalInvalidationStrategyEnabled => true;
/// Whether the windows UWP embedding is enabled.
bool get isWindowsUwpEnabled => false;
/// Whether a particular feature is enabled for the current channel.
///
/// Prefer using one of the specific getters above instead of this API.
......@@ -100,6 +103,9 @@ class FlutterFeatureFlags implements FeatureFlags {
@override
bool get isExperimentalInvalidationStrategyEnabled => isEnabled(experimentalInvalidationStrategy);
@override
bool get isWindowsUwpEnabled => isEnabled(windowsUwpEmbedding);
@override
bool isEnabled(Feature feature) {
final String currentChannel = _flutterVersion.channel;
......@@ -336,6 +342,16 @@ const Feature experimentalInvalidationStrategy = Feature(
),
);
/// The feature for enabling the Windows UWP embeding.
const Feature windowsUwpEmbedding = Feature(
name: 'Flutter for Windows UWP',
configSetting: 'enable-windows-uwp-desktop',
master: FeatureChannelSetting(
available: true,
enabledByDefault: false,
),
);
/// A [Feature] is a process for conditionally enabling tool features.
///
/// All settings are optional, and if not provided will generally default to
......
......@@ -1430,6 +1430,7 @@ DevelopmentArtifact _artifactFromTargetPlatform(TargetPlatform targetPlatform) {
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester:
case TargetPlatform.windows_uwp_x64:
// No artifacts currently supported.
return null;
}
......
......@@ -7,12 +7,14 @@
import 'package:meta/meta.dart';
import 'package:process/process.dart';
import '../application_package.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
import '../base/os.dart';
import '../build_info.dart';
import '../desktop_device.dart';
import '../device.dart';
import '../features.dart';
import '../project.dart';
import 'application_package.dart';
import 'build_windows.dart';
......@@ -68,6 +70,59 @@ class WindowsDevice extends DesktopDevice {
}
}
// A device that represents a desktop Windows UWP target.
class WindowsUWPDevice extends DesktopDevice {
WindowsUWPDevice({
@required ProcessManager processManager,
@required Logger logger,
@required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils,
}) : super(
'windows-uwp',
platformType: PlatformType.windows,
ephemeral: false,
processManager: processManager,
logger: logger,
fileSystem: fileSystem,
operatingSystemUtils: operatingSystemUtils,
);
@override
bool isSupported() => false;
@override
String get name => 'Windows (UWP)';
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.windows_uwp_x64;
@override
bool isSupportedForProject(FlutterProject flutterProject) {
// TODO(flutter): update with detection once FlutterProject knows
// about the UWP structure.
return false;
}
@override
Future<void> buildForDevice(
covariant WindowsApp package, {
String mainPath,
BuildInfo buildInfo,
}) async {
await buildWindows(
FlutterProject.current().windows,
buildInfo,
target: mainPath,
);
}
@override
String executablePathForDevice(ApplicationPackage package, BuildMode buildMode) {
// TODO(flutter): update once application package factory knows about UWP bundle.
throw UnsupportedError('Windows UWP device not implemented.');
}
}
class WindowsDevices extends PollingDeviceDiscovery {
WindowsDevices({
@required ProcessManager processManager,
......@@ -75,11 +130,13 @@ class WindowsDevices extends PollingDeviceDiscovery {
@required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils,
@required WindowsWorkflow windowsWorkflow,
@required FeatureFlags featureFlags,
}) : _fileSystem = fileSystem,
_logger = logger,
_processManager = processManager,
_operatingSystemUtils = operatingSystemUtils,
_windowsWorkflow = windowsWorkflow,
_featureFlags = featureFlags,
super('windows devices');
final FileSystem _fileSystem;
......@@ -87,6 +144,7 @@ class WindowsDevices extends PollingDeviceDiscovery {
final ProcessManager _processManager;
final OperatingSystemUtils _operatingSystemUtils;
final WindowsWorkflow _windowsWorkflow;
final FeatureFlags _featureFlags;
@override
bool get supportsPlatform => _windowsWorkflow.appliesToHostPlatform;
......@@ -106,6 +164,13 @@ class WindowsDevices extends PollingDeviceDiscovery {
processManager: _processManager,
operatingSystemUtils: _operatingSystemUtils,
),
if (_featureFlags.isWindowsUwpEnabled)
WindowsUWPDevice(
fileSystem: _fileSystem,
logger: _logger,
processManager: _processManager,
operatingSystemUtils: _operatingSystemUtils,
)
];
}
......
......@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/windows/application_package.dart';
import 'package:flutter_tools/src/windows/windows_device.dart';
......@@ -43,8 +44,9 @@ void main() {
expect(await WindowsDevices(
windowsWorkflow: WindowsWorkflow(
featureFlags: TestFeatureFlags(isWindowsEnabled: false),
platform: FakePlatform(operatingSystem: 'windows')
platform: FakePlatform(operatingSystem: 'windows'),
),
featureFlags: TestFeatureFlags(isWindowsEnabled: false),
operatingSystemUtils: FakeOperatingSystemUtils(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
......@@ -62,9 +64,25 @@ void main() {
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(),
featureFlags: TestFeatureFlags(isWindowsEnabled: true),
).devices, hasLength(1));
});
testWithoutContext('WindowsDevices lists a UWP Windows device if feature is enabled', () async {
final FeatureFlags featureFlags = TestFeatureFlags(isWindowsEnabled: true, isWindowsUwpEnabled: true);
expect(await WindowsDevices(
windowsWorkflow: WindowsWorkflow(
featureFlags: featureFlags,
platform: FakePlatform(operatingSystem: 'windows')
),
operatingSystemUtils: FakeOperatingSystemUtils(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(),
featureFlags: featureFlags,
).devices, hasLength(2));
});
testWithoutContext('WindowsDevices ignores the timeout provided to discoverDevices', () async {
final WindowsDevices windowsDevices = WindowsDevices(
windowsWorkflow: WindowsWorkflow(
......@@ -75,6 +93,7 @@ void main() {
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(),
featureFlags: TestFeatureFlags(isWindowsEnabled: true),
);
// Timeout ignored.
final List<Device> devices = await windowsDevices.discoverDevices(timeout: const Duration(seconds: 10));
......
......@@ -552,6 +552,7 @@ class TestFeatureFlags implements FeatureFlags {
this.isIOSEnabled = true,
this.isFuchsiaEnabled = false,
this.isExperimentalInvalidationStrategyEnabled = false,
this.isWindowsUwpEnabled = false,
});
@override
......@@ -581,6 +582,9 @@ class TestFeatureFlags implements FeatureFlags {
@override
final bool isExperimentalInvalidationStrategyEnabled;
@override
final bool isWindowsUwpEnabled;
@override
bool isEnabled(Feature feature) {
switch (feature) {
......@@ -602,6 +606,8 @@ class TestFeatureFlags implements FeatureFlags {
return isFuchsiaEnabled;
case experimentalInvalidationStrategy:
return isExperimentalInvalidationStrategyEnabled;
case windowsUwpEmbedding:
return isWindowsUwpEnabled;
}
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