diff --git a/packages/flutter_tools/lib/src/windows/build_windows.dart b/packages/flutter_tools/lib/src/windows/build_windows.dart index eb35576ea5..38312e70aa 100644 --- a/packages/flutter_tools/lib/src/windows/build_windows.dart +++ b/packages/flutter_tools/lib/src/windows/build_windows.dart @@ -164,12 +164,72 @@ Future buildWindowsUwp(WindowsUwpProject windowsProject, BuildInfo buildIn 'Building Windows application...', ); try { + // The Cmake re-entrant build does not work for UWP, so the flutter build is + // run in advance. + await _runFlutterBuild(buildDirectory, buildInfo, target); await _runCmakeGeneration(cmakePath, buildDirectory, windowsProject.cmakeFile.parent); await _runBuild(cmakePath, buildDirectory, buildModeName, install: false); } finally { status.cancel(); } - throwToolExit('Windows UWP builds are not implemented.'); +} + +const Map _targets = { + BuildMode.debug: 'debug_bundle_windows_assets_uwp', + BuildMode.profile: 'profile_bundle_windows_assets_uwp', + BuildMode.release: 'release_bundle_windows_assets_uwp', +}; + +Future _runFlutterBuild(Directory buildDirectory, BuildInfo buildInfo, String targetFile) async { + await buildDirectory.create(recursive: true); + int result; + String flutterEngine; + String localEngine; + if (globals.artifacts is LocalEngineArtifacts) { + final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts; + final String engineOutPath = localEngineArtifacts.engineOutPath; + flutterEngine = globals.fs.path.dirname(globals.fs.path.dirname(engineOutPath)); + localEngine = globals.fs.path.basename(engineOutPath); + } + try { + result = await globals.processUtils.stream( + [ + globals.fs.path.join(Cache.flutterRoot, 'bin', 'flutter'), + if (globals.logger.isVerbose) + '--verbose', + if (flutterEngine != null) '--local-engine-src-path=$flutterEngine', + if (localEngine != null) '--local-engine=$localEngine', + 'assemble', + '--no-version-check', + '--output=build', + '-dTargetPlatform=windows-uwp-x64', + '-dTrackWidgetCreation=${buildInfo.trackWidgetCreation}', + '-dBuildMode=${getNameForBuildMode(buildInfo.mode)}', + '-dTargetFile=$targetFile', + '-dTreeShakeIcons="${buildInfo.treeShakeIcons}"', + '-dDartObfuscation=${buildInfo.dartObfuscation}', + if (buildInfo.bundleSkSLPath != null) + '-iBundleSkSLPath=${buildInfo.bundleSkSLPath}', + if (buildInfo.codeSizeDirectory != null) + '-dCodeSizeDirectory=${buildInfo.codeSizeDirectory}', + if (buildInfo.splitDebugInfoPath != null) + '-dSplitDebugInfo=${buildInfo.splitDebugInfoPath}', + if (buildInfo.dartDefines != null && buildInfo.dartDefines.isNotEmpty) + '--DartDefines=${encodeDartDefines(buildInfo.dartDefines)}', + if (buildInfo.extraGenSnapshotOptions != null && buildInfo.extraGenSnapshotOptions.isNotEmpty) + '--ExtraGenSnapshotOptions=${buildInfo.extraGenSnapshotOptions}', + if (buildInfo.extraFrontEndOptions != null && buildInfo.extraFrontEndOptions.isNotEmpty) + '--ExtraFrontEndOptions=${buildInfo.extraFrontEndOptions}', + _targets[buildInfo.mode], + ], + trace: true, + ); + } on ArgumentError { + throwToolExit("cmake not found. Run 'flutter doctor' for more information."); + } + if (result != 0) { + throwToolExit('Unable to generate build files'); + } } Future _runCmakeGeneration(String cmakePath, Directory buildDir, Directory sourceDir) async { diff --git a/packages/flutter_tools/lib/src/windows/install_manifest.dart b/packages/flutter_tools/lib/src/windows/install_manifest.dart index b657bc447a..0ea500bedd 100644 --- a/packages/flutter_tools/lib/src/windows/install_manifest.dart +++ b/packages/flutter_tools/lib/src/windows/install_manifest.dart @@ -51,5 +51,5 @@ Future createManifest({ outputs.add(project.ephemeralDirectory.childFile('icudtl.dat')); project.ephemeralDirectory.childFile('install_manifest') ..createSync(recursive: true) - ..writeAsStringSync(outputs.map((File file) => file.absolute.path).join('\n')); + ..writeAsStringSync(outputs.map((File file) => file.absolute.uri.path.substring(1)).join('\n')); } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart index 8fefbd41fb..a34a246ca0 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart @@ -53,6 +53,7 @@ void main() { setUpAll(() { Cache.disableLocking(); + Cache.flutterRoot = ''; }); setUp(() { @@ -530,7 +531,7 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier setUpMockProjectFilesForBuild(); // This message should include 'To enable, run "flutter config --enable-windows-uwp-desktop"." - // once the `windowsUwpEmbedding` feature is available on all platforms. + // once the `windowsUwpEmbedding` feature is available on all channels. expect(createTestCommandRunner(command).run( const ['winuwp', '--no-pub'] ), throwsToolExit(message: RegExp(r'"build winuwp" is not currently supported\.$'))); @@ -541,19 +542,34 @@ C:\foo\windows\runner\main.cpp(17,1): error C2065: 'Baz': undeclared identifier FeatureFlags: () => TestFeatureFlags(isWindowsUwpEnabled: false), }); - testUsingContext('Windows UWP build fails after writing Cmake file', () async { + testUsingContext('Windows UWP build completes successfully', () async { final FakeVisualStudio fakeVisualStudio = FakeVisualStudio(cmakePath); final BuildWindowsUwpCommand command = BuildWindowsUwpCommand() ..visualStudioOverride = fakeVisualStudio; setUpMockUwpFilesForBuild(0); - expect(createTestCommandRunner(command).run( + await createTestCommandRunner(command).run( const ['winuwp', '--no-pub'] - ), throwsToolExit(message: 'Windows UWP builds are not implemented')); + ); }, overrides: { Platform: () => windowsPlatform, FileSystem: () => fileSystem, ProcessManager: () => FakeProcessManager.list([ + const FakeCommand( + command: [ + r'C:\flutter\bin\flutter', + 'assemble', + '--no-version-check', + '--output=build', + '-dTargetPlatform=windows-uwp-x64', + '-dTrackWidgetCreation=true', + '-dBuildMode=release', + r'-dTargetFile=lib\main.dart', + '-dTreeShakeIcons="true"', + '-dDartObfuscation=false', + 'release_bundle_windows_assets_uwp' + ], + ), cmakeGenerationCommand(winuwp: true), buildCommand('Release', stdout: 'STDOUT STUFF', winuwp: true), ]), diff --git a/packages/flutter_tools/test/general.shard/windows/install_manifest_test.dart b/packages/flutter_tools/test/general.shard/windows/install_manifest_test.dart index b083becc89..c5fb4d9a4d 100644 --- a/packages/flutter_tools/test/general.shard/windows/install_manifest_test.dart +++ b/packages/flutter_tools/test/general.shard/windows/install_manifest_test.dart @@ -22,7 +22,7 @@ void main() { FileSystem fileSystem; setUp(() { - fileSystem = MemoryFileSystem.test(); + fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows); }); testUsingContext('Generates install manifest for a debug build', () async { @@ -44,11 +44,11 @@ void main() { final File manifest = flutterProject.windowsUwp.ephemeralDirectory.childFile('install_manifest'); expect(manifest, exists); expect(manifest.readAsLinesSync(), unorderedEquals([ - '/build/winuwp/flutter_assets/kernel_blob.bin', - '/build/winuwp/flutter_assets/AssetManifest.json', - '/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll', - '/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll.pdb', - '/winuwp/flutter/ephemeral/icudtl.dat', + 'C:/build/winuwp/flutter_assets/kernel_blob.bin', + 'C:/build/winuwp/flutter_assets/AssetManifest.json', + 'C:/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll', + 'C:/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll.pdb', + 'C:/winuwp/flutter/ephemeral/icudtl.dat', ])); }, overrides: { FileSystem: () => fileSystem, @@ -74,11 +74,11 @@ void main() { final File manifest = flutterProject.windowsUwp.ephemeralDirectory.childFile('install_manifest'); expect(manifest, exists); expect(manifest.readAsLinesSync(), unorderedEquals([ - '/build/winuwp/app.so', - '/build/winuwp/flutter_assets/AssetManifest.json', - '/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll', - '/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll.pdb', - '/winuwp/flutter/ephemeral/icudtl.dat' + 'C:/build/winuwp/app.so', + 'C:/build/winuwp/flutter_assets/AssetManifest.json', + 'C:/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll', + 'C:/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll.pdb', + 'C:/winuwp/flutter/ephemeral/icudtl.dat' ])); }, overrides: { FileSystem: () => fileSystem, @@ -128,14 +128,14 @@ flutter: final File manifest = flutterProject.windowsUwp.ephemeralDirectory.childFile('install_manifest'); expect(manifest, exists); expect(manifest.readAsLinesSync(), unorderedEquals([ - '/build/winuwp/app.so', - '/build/winuwp/flutter_assets/assets/foo.png', - '/build/winuwp/flutter_assets/AssetManifest.json', - '/build/winuwp/flutter_assets/FontManifest.json', - '/build/winuwp/flutter_assets/NOTICES', - '/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll', - '/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll.pdb', - '/winuwp/flutter/ephemeral/icudtl.dat' + 'C:/build/winuwp/app.so', + 'C:/build/winuwp/flutter_assets/assets/foo.png', + 'C:/build/winuwp/flutter_assets/AssetManifest.json', + 'C:/build/winuwp/flutter_assets/FontManifest.json', + 'C:/build/winuwp/flutter_assets/NOTICES', + 'C:/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll', + 'C:/winuwp/flutter/ephemeral/flutter_windows_winuwp.dll.pdb', + 'C:/winuwp/flutter/ephemeral/icudtl.dat' ])); }, overrides: { FileSystem: () => fileSystem,