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 { ...@@ -111,6 +111,8 @@ class ApplicationPackageFactory {
return applicationBinary == null return applicationBinary == null
? FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia) ? FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia)
: FuchsiaApp.fromPrebuiltApp(applicationBinary); : FuchsiaApp.fromPrebuiltApp(applicationBinary);
case TargetPlatform.windows_uwp_x64:
throw UnsupportedError('Cannot build for windows_uwp_x64');
} }
assert(platform != null); assert(platform != null);
return null; return null;
......
...@@ -521,6 +521,9 @@ class CachedArtifacts implements Artifacts { ...@@ -521,6 +521,9 @@ class CachedArtifacts implements Artifacts {
case TargetPlatform.android: case TargetPlatform.android:
assert(false, 'cannot use TargetPlatform.android to look up artifacts'); assert(false, 'cannot use TargetPlatform.android to look up artifacts');
return null; 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.'); assert(false, 'Invalid platform $platform.');
return null; return null;
......
...@@ -485,6 +485,7 @@ enum TargetPlatform { ...@@ -485,6 +485,7 @@ enum TargetPlatform {
linux_x64, linux_x64,
linux_arm64, linux_arm64,
windows_x64, windows_x64,
windows_uwp_x64,
fuchsia_arm64, fuchsia_arm64,
fuchsia_x64, fuchsia_x64,
tester, tester,
...@@ -582,6 +583,8 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch} ...@@ -582,6 +583,8 @@ String getNameForTargetPlatform(TargetPlatform platform, {DarwinArch darwinArch}
return 'linux-arm64'; return 'linux-arm64';
case TargetPlatform.windows_x64: case TargetPlatform.windows_x64:
return 'windows-x64'; return 'windows-x64';
case TargetPlatform.windows_uwp_x64:
return 'windows-uwp-x64';
case TargetPlatform.fuchsia_arm64: case TargetPlatform.fuchsia_arm64:
return 'fuchsia-arm64'; return 'fuchsia-arm64';
case TargetPlatform.fuchsia_x64: case TargetPlatform.fuchsia_x64:
......
...@@ -418,6 +418,7 @@ class FlutterDeviceManager extends DeviceManager { ...@@ -418,6 +418,7 @@ class FlutterDeviceManager extends DeviceManager {
logger: logger, logger: logger,
fileSystem: fileSystem, fileSystem: fileSystem,
windowsWorkflow: windowsWorkflow, windowsWorkflow: windowsWorkflow,
featureFlags: featureFlags,
), ),
WebDevices( WebDevices(
featureFlags: featureFlags, featureFlags: featureFlags,
......
...@@ -54,6 +54,9 @@ abstract class FeatureFlags { ...@@ -54,6 +54,9 @@ abstract class FeatureFlags {
/// Whether the CFE experimental invalidation strategy is enabled. /// Whether the CFE experimental invalidation strategy is enabled.
bool get isExperimentalInvalidationStrategyEnabled => true; 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. /// 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.
...@@ -100,6 +103,9 @@ class FlutterFeatureFlags implements FeatureFlags { ...@@ -100,6 +103,9 @@ class FlutterFeatureFlags implements FeatureFlags {
@override @override
bool get isExperimentalInvalidationStrategyEnabled => isEnabled(experimentalInvalidationStrategy); bool get isExperimentalInvalidationStrategyEnabled => isEnabled(experimentalInvalidationStrategy);
@override
bool get isWindowsUwpEnabled => isEnabled(windowsUwpEmbedding);
@override @override
bool isEnabled(Feature feature) { bool isEnabled(Feature feature) {
final String currentChannel = _flutterVersion.channel; final String currentChannel = _flutterVersion.channel;
...@@ -336,6 +342,16 @@ const Feature experimentalInvalidationStrategy = Feature( ...@@ -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. /// 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
......
...@@ -1430,6 +1430,7 @@ DevelopmentArtifact _artifactFromTargetPlatform(TargetPlatform targetPlatform) { ...@@ -1430,6 +1430,7 @@ DevelopmentArtifact _artifactFromTargetPlatform(TargetPlatform targetPlatform) {
case TargetPlatform.fuchsia_arm64: case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64: case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester: case TargetPlatform.tester:
case TargetPlatform.windows_uwp_x64:
// No artifacts currently supported. // No artifacts currently supported.
return null; return null;
} }
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../application_package.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../desktop_device.dart'; import '../desktop_device.dart';
import '../device.dart'; import '../device.dart';
import '../features.dart';
import '../project.dart'; import '../project.dart';
import 'application_package.dart'; import 'application_package.dart';
import 'build_windows.dart'; import 'build_windows.dart';
...@@ -68,6 +70,59 @@ class WindowsDevice extends DesktopDevice { ...@@ -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 { class WindowsDevices extends PollingDeviceDiscovery {
WindowsDevices({ WindowsDevices({
@required ProcessManager processManager, @required ProcessManager processManager,
...@@ -75,11 +130,13 @@ class WindowsDevices extends PollingDeviceDiscovery { ...@@ -75,11 +130,13 @@ class WindowsDevices extends PollingDeviceDiscovery {
@required FileSystem fileSystem, @required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils, @required OperatingSystemUtils operatingSystemUtils,
@required WindowsWorkflow windowsWorkflow, @required WindowsWorkflow windowsWorkflow,
@required FeatureFlags featureFlags,
}) : _fileSystem = fileSystem, }) : _fileSystem = fileSystem,
_logger = logger, _logger = logger,
_processManager = processManager, _processManager = processManager,
_operatingSystemUtils = operatingSystemUtils, _operatingSystemUtils = operatingSystemUtils,
_windowsWorkflow = windowsWorkflow, _windowsWorkflow = windowsWorkflow,
_featureFlags = featureFlags,
super('windows devices'); super('windows devices');
final FileSystem _fileSystem; final FileSystem _fileSystem;
...@@ -87,6 +144,7 @@ class WindowsDevices extends PollingDeviceDiscovery { ...@@ -87,6 +144,7 @@ class WindowsDevices extends PollingDeviceDiscovery {
final ProcessManager _processManager; final ProcessManager _processManager;
final OperatingSystemUtils _operatingSystemUtils; final OperatingSystemUtils _operatingSystemUtils;
final WindowsWorkflow _windowsWorkflow; final WindowsWorkflow _windowsWorkflow;
final FeatureFlags _featureFlags;
@override @override
bool get supportsPlatform => _windowsWorkflow.appliesToHostPlatform; bool get supportsPlatform => _windowsWorkflow.appliesToHostPlatform;
...@@ -106,6 +164,13 @@ class WindowsDevices extends PollingDeviceDiscovery { ...@@ -106,6 +164,13 @@ class WindowsDevices extends PollingDeviceDiscovery {
processManager: _processManager, processManager: _processManager,
operatingSystemUtils: _operatingSystemUtils, 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'; ...@@ -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/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/device.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/project.dart';
import 'package:flutter_tools/src/windows/application_package.dart'; import 'package:flutter_tools/src/windows/application_package.dart';
import 'package:flutter_tools/src/windows/windows_device.dart'; import 'package:flutter_tools/src/windows/windows_device.dart';
...@@ -43,8 +44,9 @@ void main() { ...@@ -43,8 +44,9 @@ void main() {
expect(await WindowsDevices( expect(await WindowsDevices(
windowsWorkflow: WindowsWorkflow( windowsWorkflow: WindowsWorkflow(
featureFlags: TestFeatureFlags(isWindowsEnabled: false), featureFlags: TestFeatureFlags(isWindowsEnabled: false),
platform: FakePlatform(operatingSystem: 'windows') platform: FakePlatform(operatingSystem: 'windows'),
), ),
featureFlags: TestFeatureFlags(isWindowsEnabled: false),
operatingSystemUtils: FakeOperatingSystemUtils(), operatingSystemUtils: FakeOperatingSystemUtils(),
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
...@@ -62,9 +64,25 @@ void main() { ...@@ -62,9 +64,25 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
featureFlags: TestFeatureFlags(isWindowsEnabled: true),
).devices, hasLength(1)); ).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 { testWithoutContext('WindowsDevices ignores the timeout provided to discoverDevices', () async {
final WindowsDevices windowsDevices = WindowsDevices( final WindowsDevices windowsDevices = WindowsDevices(
windowsWorkflow: WindowsWorkflow( windowsWorkflow: WindowsWorkflow(
...@@ -75,6 +93,7 @@ void main() { ...@@ -75,6 +93,7 @@ void main() {
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
featureFlags: TestFeatureFlags(isWindowsEnabled: true),
); );
// Timeout ignored. // Timeout ignored.
final List<Device> devices = await windowsDevices.discoverDevices(timeout: const Duration(seconds: 10)); final List<Device> devices = await windowsDevices.discoverDevices(timeout: const Duration(seconds: 10));
......
...@@ -552,6 +552,7 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -552,6 +552,7 @@ class TestFeatureFlags implements FeatureFlags {
this.isIOSEnabled = true, this.isIOSEnabled = true,
this.isFuchsiaEnabled = false, this.isFuchsiaEnabled = false,
this.isExperimentalInvalidationStrategyEnabled = false, this.isExperimentalInvalidationStrategyEnabled = false,
this.isWindowsUwpEnabled = false,
}); });
@override @override
...@@ -581,6 +582,9 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -581,6 +582,9 @@ class TestFeatureFlags implements FeatureFlags {
@override @override
final bool isExperimentalInvalidationStrategyEnabled; final bool isExperimentalInvalidationStrategyEnabled;
@override
final bool isWindowsUwpEnabled;
@override @override
bool isEnabled(Feature feature) { bool isEnabled(Feature feature) {
switch (feature) { switch (feature) {
...@@ -602,6 +606,8 @@ class TestFeatureFlags implements FeatureFlags { ...@@ -602,6 +606,8 @@ class TestFeatureFlags implements FeatureFlags {
return isFuchsiaEnabled; return isFuchsiaEnabled;
case experimentalInvalidationStrategy: case experimentalInvalidationStrategy:
return isExperimentalInvalidationStrategyEnabled; return isExperimentalInvalidationStrategyEnabled;
case windowsUwpEmbedding:
return isWindowsUwpEnabled;
} }
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