diff --git a/packages/flutter_tools/lib/src/build_system/targets/windows.dart b/packages/flutter_tools/lib/src/build_system/targets/windows.dart index 55666c5894..32b05734e6 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/windows.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/windows.dart @@ -4,6 +4,8 @@ // @dart = 2.8 +import 'package:meta/meta.dart'; + import '../../artifacts.dart'; import '../../base/file_system.dart'; import '../../build_info.dart'; @@ -253,13 +255,57 @@ abstract class BundleWindowsAssetsUwp extends BundleWindowsAssets { /// A wrapper for AOT compilation that copies app.so into the output directory. class WindowsAotBundle extends Target { /// Create a [WindowsAotBundle] wrapper for [aotTarget]. - const WindowsAotBundle(this.aotTarget); + const WindowsAotBundle(this.aotTarget, {@required this.uwp}); + + /// The [AotElfBase] subclass that produces the app.so. + final AotElfBase aotTarget; + + /// Whether this is the UWP target. + final bool uwp; + + @override + String get name => uwp ? 'windows_uwp_aot_bundle' : 'windows_aot_bundle'; + + @override + List get inputs => const [ + Source.pattern('{BUILD_DIR}/app.so'), + ]; + + @override + List get outputs => uwp ? + const [ + Source.pattern('{OUTPUT_DIR}/winuwp/app.so'), + ] : + const [ + Source.pattern('{OUTPUT_DIR}/windows/app.so'), + ]; + + @override + List get dependencies => [ + aotTarget, + ]; + + @override + Future build(Environment environment) async { + final File outputFile = environment.buildDir.childFile('app.so'); + final Directory outputDirectory = environment.outputDir.childDirectory(uwp ? 'winuwp' : 'windows'); + if (!outputDirectory.existsSync()) { + outputDirectory.createSync(recursive: true); + } + outputFile.copySync(outputDirectory.childFile('app.so').path); + } +} + +/// A wrapper for AOT compilation that copies app.so into the output directory. +class WindowsUwpAotBundle extends Target { + /// Create a [WindowsAotBundle] wrapper for [aotTarget]. + const WindowsUwpAotBundle(this.aotTarget); /// The [AotElfBase] subclass that produces the app.so. final AotElfBase aotTarget; @override - String get name => 'windows_aot_bundle'; + String get name => 'windows_uwp_aot_bundle'; @override List get inputs => const [ @@ -268,7 +314,7 @@ class WindowsAotBundle extends Target { @override List get outputs => const [ - Source.pattern('{OUTPUT_DIR}/windows/app.so'), + Source.pattern('{OUTPUT_DIR}/winuwp/app.so'), ]; @override @@ -279,7 +325,7 @@ class WindowsAotBundle extends Target { @override Future build(Environment environment) async { final File outputFile = environment.buildDir.childFile('app.so'); - final Directory outputDirectory = environment.outputDir.childDirectory('windows'); + final Directory outputDirectory = environment.outputDir.childDirectory('winuwp'); if (!outputDirectory.existsSync()) { outputDirectory.createSync(recursive: true); } @@ -299,7 +345,7 @@ class ReleaseBundleWindowsAssets extends BundleWindowsAssets { @override List get dependencies => [ ...super.dependencies, - const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_x64)), + const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_x64), uwp: false), ]; } @@ -315,7 +361,7 @@ class ProfileBundleWindowsAssets extends BundleWindowsAssets { @override List get dependencies => [ ...super.dependencies, - const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_x64)), + const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_x64), uwp: false), ]; } @@ -348,7 +394,7 @@ class ReleaseBundleWindowsAssetsUwp extends BundleWindowsAssetsUwp { @override List get dependencies => [ ...super.dependencies, - const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_uwp_x64)), + const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_uwp_x64), uwp: true), ]; } @@ -364,7 +410,7 @@ class ProfileBundleWindowsAssetsUwp extends BundleWindowsAssetsUwp { @override List get dependencies => [ ...super.dependencies, - const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_uwp_x64)), + const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_uwp_x64), uwp: true), ]; } diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/windows_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/windows_test.dart index 21dcbd8f76..57e65f692b 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/windows_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/windows_test.dart @@ -289,7 +289,7 @@ void main() { environment.buildDir.childFile('app.so').createSync(recursive: true); - await const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_x64)).build(environment); + await const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_x64), uwp: false).build(environment); await const ProfileBundleWindowsAssets().build(environment); // Depfile is created and so is copied. @@ -302,6 +302,60 @@ void main() { ProcessManager: () => FakeProcessManager.any(), }); + testUsingContext('ReleaseBundleWindowsAssets creates correct bundle structure with UWP', () async { + final Environment environment = Environment.test( + fileSystem.currentDirectory, + artifacts: Artifacts.test(), + processManager: FakeProcessManager.any(), + fileSystem: fileSystem, + logger: BufferLogger.test(), + defines: { + kBuildMode: 'release', + } + ); + + environment.buildDir.childFile('app.so').createSync(recursive: true); + + await const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_x64), uwp: true).build(environment); + await const ReleaseBundleWindowsAssets().build(environment); + + // Depfile is created and so is copied. + expect(environment.buildDir.childFile('flutter_assets.d'), exists); + expect(fileSystem.file(r'C:\winuwp\app.so'), exists); + expect(fileSystem.file(r'C:\flutter_assets\kernel_blob.bin').existsSync(), false); + expect(fileSystem.file(r'C:\flutter_assets\AssetManifest.json'), exists); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => FakeProcessManager.any(), + }); + + testUsingContext('ProfileBundleWindowsAssets creates correct bundle structure with UWP', () async { + final Environment environment = Environment.test( + fileSystem.currentDirectory, + artifacts: Artifacts.test(), + processManager: FakeProcessManager.any(), + fileSystem: fileSystem, + logger: BufferLogger.test(), + defines: { + kBuildMode: 'profile', + } + ); + + environment.buildDir.childFile('app.so').createSync(recursive: true); + + await const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_x64), uwp: true).build(environment); + await const ProfileBundleWindowsAssets().build(environment); + + // Depfile is created and so is copied. + expect(environment.buildDir.childFile('flutter_assets.d'), exists); + expect(fileSystem.file(r'C:\winuwp\app.so'), exists); + expect(fileSystem.file(r'C:\flutter_assets\kernel_blob.bin').existsSync(), false); + expect(fileSystem.file(r'C:\flutter_assets\AssetManifest.json'), exists); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => FakeProcessManager.any(), + }); + testUsingContext('ReleaseBundleWindowsAssets creates correct bundle structure', () async { final Environment environment = Environment.test( fileSystem.currentDirectory, @@ -316,7 +370,7 @@ void main() { environment.buildDir.childFile('app.so').createSync(recursive: true); - await const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_x64)).build(environment); + await const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_x64), uwp: false).build(environment); await const ReleaseBundleWindowsAssets().build(environment); // Depfile is created and so is copied.