Unverified Commit 3bec9c2a authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] allow winuwp build to setup generated Cmake (#79676)

parent b070ed3c
...@@ -741,6 +741,11 @@ String getWindowsBuildDirectory() { ...@@ -741,6 +741,11 @@ String getWindowsBuildDirectory() {
return globals.fs.path.join(getBuildDirectory(), 'windows'); return globals.fs.path.join(getBuildDirectory(), 'windows');
} }
/// Returns the Windows UWP build output directory.
String getWindowsBuildUwpDirectory() {
return globals.fs.path.join(getBuildDirectory(), 'winuwp');
}
/// Returns the Fuchsia build output directory. /// Returns the Fuchsia build output directory.
String getFuchsiaBuildDirectory() { String getFuchsiaBuildDirectory() {
return globals.fs.path.join(getBuildDirectory(), 'fuchsia'); return globals.fs.path.join(getBuildDirectory(), 'fuchsia');
......
...@@ -108,7 +108,9 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory { ...@@ -108,7 +108,9 @@ class FlutterApplicationPackageFactory extends ApplicationPackageFactory {
? FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia) ? FuchsiaApp.fromFuchsiaProject(FlutterProject.current().fuchsia)
: FuchsiaApp.fromPrebuiltApp(applicationBinary); : FuchsiaApp.fromPrebuiltApp(applicationBinary);
case TargetPlatform.windows_uwp_x64: case TargetPlatform.windows_uwp_x64:
throw UnsupportedError('Cannot build for windows_uwp_x64'); return applicationBinary == null
? WindowsApp.fromWindowsProject(FlutterProject.current().windowsUwp)
: WindowsApp.fromPrebuiltApp(applicationBinary);
} }
assert(platform != null); assert(platform != null);
return null; return null;
......
...@@ -132,6 +132,31 @@ Future<void> buildWindowsUwp(WindowsUwpProject windowsProject, BuildInfo buildIn ...@@ -132,6 +132,31 @@ Future<void> buildWindowsUwp(WindowsUwpProject windowsProject, BuildInfo buildIn
'The Windows UWP project template and build process has changed. In order to build ' 'The Windows UWP project template and build process has changed. In order to build '
'you must delete the winuwp directory and re-create the project.', 'you must delete the winuwp directory and re-create the project.',
); );
}
// Ensure that necessary ephemeral files are generated and up to date.
_writeGeneratedFlutterConfig(windowsProject, buildInfo, target);
createPluginSymlinks(windowsProject.parent);
final VisualStudio visualStudio = visualStudioOverride ?? VisualStudio(
fileSystem: globals.fs,
platform: globals.platform,
logger: globals.logger,
processManager: globals.processManager,
);
final String cmakePath = visualStudio.cmakePath;
if (cmakePath == null) {
throwToolExit('Unable to find suitable Visual Studio toolchain. '
'Please run `flutter doctor` for more details.');
}
final Directory buildDirectory = globals.fs.directory(getWindowsBuildUwpDirectory());
final Status status = globals.logger.startProgress(
'Building Windows application...',
);
try {
await _runCmakeGeneration(cmakePath, buildDirectory, windowsProject.cmakeFile.parent);
} finally {
status.cancel();
} }
throwToolExit('Windows UWP builds are not implemented.'); throwToolExit('Windows UWP builds are not implemented.');
} }
......
...@@ -78,7 +78,7 @@ class WindowsUWPDevice extends DesktopDevice { ...@@ -78,7 +78,7 @@ class WindowsUWPDevice extends DesktopDevice {
@required FileSystem fileSystem, @required FileSystem fileSystem,
@required OperatingSystemUtils operatingSystemUtils, @required OperatingSystemUtils operatingSystemUtils,
}) : super( }) : super(
'windows-uwp', 'winuwp',
platformType: PlatformType.windows, platformType: PlatformType.windows,
ephemeral: false, ephemeral: false,
processManager: processManager, processManager: processManager,
...@@ -88,7 +88,7 @@ class WindowsUWPDevice extends DesktopDevice { ...@@ -88,7 +88,7 @@ class WindowsUWPDevice extends DesktopDevice {
); );
@override @override
bool isSupported() => false; bool isSupported() => true;
@override @override
String get name => 'Windows (UWP)'; String get name => 'Windows (UWP)';
...@@ -100,7 +100,7 @@ class WindowsUWPDevice extends DesktopDevice { ...@@ -100,7 +100,7 @@ class WindowsUWPDevice extends DesktopDevice {
bool isSupportedForProject(FlutterProject flutterProject) { bool isSupportedForProject(FlutterProject flutterProject) {
// TODO(flutter): update with detection once FlutterProject knows // TODO(flutter): update with detection once FlutterProject knows
// about the UWP structure. // about the UWP structure.
return false; return true;
} }
@override @override
...@@ -109,8 +109,8 @@ class WindowsUWPDevice extends DesktopDevice { ...@@ -109,8 +109,8 @@ class WindowsUWPDevice extends DesktopDevice {
String mainPath, String mainPath,
BuildInfo buildInfo, BuildInfo buildInfo,
}) async { }) async {
await buildWindows( await buildWindowsUwp(
FlutterProject.current().windows, FlutterProject.current().windowsUwp,
buildInfo, buildInfo,
target: mainPath, target: mainPath,
); );
......
...@@ -84,14 +84,17 @@ void main() { ...@@ -84,14 +84,17 @@ void main() {
// Returns the command matching the build_windows call to generate CMake // Returns the command matching the build_windows call to generate CMake
// files. // files.
FakeCommand cmakeGenerationCommand({void Function() onRun}) { FakeCommand cmakeGenerationCommand({void Function() onRun, bool winuwp = false}) {
return FakeCommand( return FakeCommand(
command: <String>[ command: <String>[
cmakePath, cmakePath,
'-S', '-S',
fileSystem.path.dirname(buildFilePath), fileSystem.path.dirname(winuwp ? buildUwpFilePath : buildFilePath),
'-B', '-B',
r'build\windows', if (winuwp)
r'build\winuwp'
else
r'build\windows',
'-G', '-G',
'Visual Studio 16 2019', 'Visual Studio 16 2019',
], ],
...@@ -466,7 +469,7 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier ...@@ -466,7 +469,7 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier
FeatureFlags: () => TestFeatureFlags(isWindowsUwpEnabled: true), FeatureFlags: () => TestFeatureFlags(isWindowsUwpEnabled: true),
}); });
testUsingContext('Windows build fails when the project version is out of date', () async { testUsingContext('Windows UWP build fails when the project version is out of date', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(cmakePath); final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(cmakePath);
final BuildWindowsUwpCommand command = BuildWindowsUwpCommand() final BuildWindowsUwpCommand command = BuildWindowsUwpCommand()
..visualStudioOverride = fakeVisualStudio; ..visualStudioOverride = fakeVisualStudio;
...@@ -482,6 +485,22 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier ...@@ -482,6 +485,22 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isWindowsUwpEnabled: true), FeatureFlags: () => TestFeatureFlags(isWindowsUwpEnabled: true),
}); });
testUsingContext('Windows UWP build fails after writing Cmake file', () async {
final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(cmakePath);
final BuildWindowsUwpCommand command = BuildWindowsUwpCommand()
..visualStudioOverride = fakeVisualStudio;
setUpMockUwpFilesForBuild(0);
expect(createTestCommandRunner(command).run(
const <String>['winuwp', '--no-pub']
), throwsToolExit(message: 'Windows UWP builds are not implemented'));
}, overrides: <Type, Generator>{
Platform: () => windowsPlatform,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[cmakeGenerationCommand(winuwp: true)]),
FeatureFlags: () => TestFeatureFlags(isWindowsUwpEnabled: true),
});
} }
class FakeVisualStudio extends Fake implements VisualStudio { class FakeVisualStudio extends Fake implements VisualStudio {
......
...@@ -40,6 +40,24 @@ void main() { ...@@ -40,6 +40,24 @@ void main() {
expect(windowsDevice.supportsRuntimeMode(BuildMode.jitRelease), false); expect(windowsDevice.supportsRuntimeMode(BuildMode.jitRelease), false);
}); });
testWithoutContext('WindowsUwpDevice defaults', () async {
final WindowsUWPDevice windowsDevice = setUpWindowsUwpDevice();
final PrebuiltWindowsApp windowsApp = PrebuiltWindowsApp(executable: 'foo');
expect(await windowsDevice.targetPlatform, TargetPlatform.windows_uwp_x64);
expect(windowsDevice.name, 'Windows (UWP)');
expect(await windowsDevice.installApp(windowsApp), true);
expect(await windowsDevice.uninstallApp(windowsApp), true);
expect(await windowsDevice.isLatestBuildInstalled(windowsApp), true);
expect(await windowsDevice.isAppInstalled(windowsApp), true);
expect(windowsDevice.category, Category.desktop);
expect(windowsDevice.supportsRuntimeMode(BuildMode.debug), true);
expect(windowsDevice.supportsRuntimeMode(BuildMode.profile), true);
expect(windowsDevice.supportsRuntimeMode(BuildMode.release), true);
expect(windowsDevice.supportsRuntimeMode(BuildMode.jitRelease), false);
});
testWithoutContext('WindowsDevices does not list devices if the workflow is unsupported', () async { testWithoutContext('WindowsDevices does not list devices if the workflow is unsupported', () async {
expect(await WindowsDevices( expect(await WindowsDevices(
windowsWorkflow: WindowsWorkflow( windowsWorkflow: WindowsWorkflow(
...@@ -164,6 +182,19 @@ WindowsDevice setUpWindowsDevice({ ...@@ -164,6 +182,19 @@ WindowsDevice setUpWindowsDevice({
); );
} }
WindowsUWPDevice setUpWindowsUwpDevice({
FileSystem fileSystem,
Logger logger,
ProcessManager processManager,
}) {
return WindowsUWPDevice(
fileSystem: fileSystem ?? MemoryFileSystem.test(),
logger: logger ?? BufferLogger.test(),
processManager: processManager ?? FakeProcessManager.any(),
operatingSystemUtils: FakeOperatingSystemUtils(),
);
}
class FakeWindowsApp extends Fake implements WindowsApp { class FakeWindowsApp extends Fake implements WindowsApp {
@override @override
String executable(BuildMode buildMode) => '${buildMode.name}/executable'; String executable(BuildMode buildMode) => '${buildMode.name}/executable';
......
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