From be2c68c85ca1e3b49ac3b947b023e8c03a92ced4 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 9 Apr 2021 10:59:01 -0700 Subject: [PATCH] [flutter_tools] cache for UWP artifacts (#80069) --- packages/flutter_tools/bin/tool_backend.dart | 2 +- packages/flutter_tools/lib/src/artifacts.dart | 30 +++++++++------- .../flutter_tools/lib/src/base/build.dart | 1 + .../flutter_tools/lib/src/build_info.dart | 2 ++ .../lib/src/build_system/targets/windows.dart | 9 ++--- packages/flutter_tools/lib/src/cache.dart | 4 +++ .../lib/src/commands/build_winuwp.dart | 3 +- .../lib/src/commands/precache.dart | 2 ++ .../flutter_tools/lib/src/flutter_cache.dart | 35 +++++++++++++++++++ .../test/general.shard/artifacts_test.dart | 26 ++++++++++++++ .../build_system/targets/windows_test.dart | 2 +- .../test/general.shard/cache_test.dart | 14 ++++++++ 12 files changed, 107 insertions(+), 23 deletions(-) diff --git a/packages/flutter_tools/bin/tool_backend.dart b/packages/flutter_tools/bin/tool_backend.dart index cdfaa62f8c..d316618712 100644 --- a/packages/flutter_tools/bin/tool_backend.dart +++ b/packages/flutter_tools/bin/tool_backend.dart @@ -62,7 +62,7 @@ or 'flutter' ]); final bool uwp = targetPlatform.contains('uwp'); - final String bundlePlatform = targetPlatform.startsWith('windows-x64') ? 'windows' : targetPlatform; + final String bundlePlatform = targetPlatform.startsWith('windows') ? 'windows' : targetPlatform; final String target = '${buildMode}_bundle_${bundlePlatform}_assets${uwp ? '_uwp' : ''}'; final Process assembleProcess = await Process.start( flutterExecutable, diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart index 3d7dade0fd..d27fc1c869 100644 --- a/packages/flutter_tools/lib/src/artifacts.dart +++ b/packages/flutter_tools/lib/src/artifacts.dart @@ -74,8 +74,10 @@ enum Artifact { linuxHeaders, /// The root of the Windows desktop sources. windowsDesktopPath, - /// The root of the cpp client code for Windows desktop. + /// The root of the cpp client code for Windows desktop and Windows UWP desktop. windowsCppClientWrapper, + /// The root of the Windows UWP desktop sources. + windowsUwpDesktopPath, /// The root of the sky_engine package. skyEnginePath, /// The location of the macOS engine podspec file. @@ -146,10 +148,11 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo return ''; case Artifact.linuxHeaders: return 'flutter_linux'; - case Artifact.windowsDesktopPath: - return ''; case Artifact.windowsCppClientWrapper: return 'cpp_client_wrapper'; + case Artifact.windowsUwpDesktopPath: + case Artifact.windowsDesktopPath: + return ''; case Artifact.skyEnginePath: return 'sky_engine'; case Artifact.flutterMacOSPodspec: @@ -284,6 +287,7 @@ class CachedArtifacts implements Artifacts { case TargetPlatform.linux_x64: case TargetPlatform.linux_arm64: case TargetPlatform.windows_x64: + case TargetPlatform.windows_uwp_x64: return _getDesktopArtifactPath(artifact, platform, mode); case TargetPlatform.fuchsia_arm64: case TargetPlatform.fuchsia_x64: @@ -444,6 +448,9 @@ class CachedArtifacts implements Artifacts { } final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path; return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode)); + case Artifact.windowsUwpDesktopPath: + final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path; + return _fileSystem.path.join(engineArtifactsPath, 'windows-uwp-x64-${getNameForBuildMode(mode)}', _artifactToFileName(artifact, platform, mode)); case Artifact.windowsCppClientWrapper: final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path; return _fileSystem.path.join(engineArtifactsPath, 'windows-x64', _artifactToFileName(artifact, platform, mode)); @@ -515,15 +522,13 @@ class CachedArtifacts implements Artifacts { case TargetPlatform.android_arm64: case TargetPlatform.android_x64: case TargetPlatform.android_x86: + case TargetPlatform.windows_uwp_x64: assert(mode != null, 'Need to specify a build mode for platform $platform.'); final String suffix = mode != BuildMode.debug ? '-${snakeCase(getModeName(mode), '-')}' : ''; return _fileSystem.path.join(engineDir, platformName + suffix); 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; @@ -679,13 +684,6 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { return _cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path; case Artifact.iproxy: return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path; - case Artifact.linuxDesktopPath: - case Artifact.linuxHeaders: - return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); - case Artifact.windowsDesktopPath: - return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); - case Artifact.windowsCppClientWrapper: - return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); case Artifact.skyEnginePath: return _fileSystem.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName); case Artifact.flutterMacOSPodspec: @@ -735,6 +733,12 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { return _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', 'amd-canvaskit-html-sound', artifactFileName); case Artifact.pubExecutable: return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', _artifactToFileName(artifact, platform, mode)); + case Artifact.windowsUwpDesktopPath: + case Artifact.linuxDesktopPath: + case Artifact.linuxHeaders: + case Artifact.windowsDesktopPath: + case Artifact.windowsCppClientWrapper: + return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); } assert(false, 'Invalid artifact $artifact.'); return null; diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 74e40a37a9..0fe01960f6 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart @@ -315,6 +315,7 @@ class AOTSnapshotter { TargetPlatform.linux_x64, TargetPlatform.linux_arm64, TargetPlatform.windows_x64, + TargetPlatform.windows_uwp_x64, ].contains(platform); } } diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart index 3b4d02c71c..571546d8f2 100644 --- a/packages/flutter_tools/lib/src/build_info.dart +++ b/packages/flutter_tools/lib/src/build_info.dart @@ -600,6 +600,8 @@ TargetPlatform? getTargetPlatformForName(String platform) { return TargetPlatform.linux_arm64; case 'windows-x64': return TargetPlatform.windows_x64; + case 'windows-uwp-x64': + return TargetPlatform.windows_uwp_x64; case 'web-javascript': return TargetPlatform.web_javascript; } 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 9e2460031b..55666c5894 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/windows.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/windows.dart @@ -133,12 +133,10 @@ class UnpackWindowsUwp extends Target { @override Future build(Environment environment) async { - // These artifact look ups need to modified to windows-x64-uwp once - // the cache updates have landed. final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]); final String engineSourcePath = environment.artifacts .getArtifactPath( - Artifact.windowsDesktopPath, + Artifact.windowsUwpDesktopPath, platform: TargetPlatform.windows_x64, mode: buildMode, ); @@ -338,7 +336,6 @@ class DebugBundleWindowsAssets extends BundleWindowsAssets { ]; } - class ReleaseBundleWindowsAssetsUwp extends BundleWindowsAssetsUwp { const ReleaseBundleWindowsAssetsUwp(); @@ -351,7 +348,7 @@ class ReleaseBundleWindowsAssetsUwp extends BundleWindowsAssetsUwp { @override List get dependencies => [ ...super.dependencies, - const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_x64)), + const WindowsAotBundle(AotElfRelease(TargetPlatform.windows_uwp_x64)), ]; } @@ -367,7 +364,7 @@ class ProfileBundleWindowsAssetsUwp extends BundleWindowsAssetsUwp { @override List get dependencies => [ ...super.dependencies, - const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_x64)), + const WindowsAotBundle(AotElfProfile(TargetPlatform.windows_uwp_x64)), ]; } diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 152d4e75e5..b3ba3ee0a7 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -69,6 +69,9 @@ class DevelopmentArtifact { /// Artifacts required for the Flutter Runner. static const DevelopmentArtifact flutterRunner = DevelopmentArtifact._('flutter_runner', feature: flutterFuchsiaFeature); + /// Artifacts required for desktop Windows UWP. + static const DevelopmentArtifact windowsUwp = DevelopmentArtifact._('winuwp', feature: windowsUwpEmbedding); + /// Artifacts required for any development platform. /// /// This does not need to be explicitly returned from requiredArtifacts as @@ -88,6 +91,7 @@ class DevelopmentArtifact { fuchsia, universal, flutterRunner, + windowsUwp, ]; @override diff --git a/packages/flutter_tools/lib/src/commands/build_winuwp.dart b/packages/flutter_tools/lib/src/commands/build_winuwp.dart index 71023a0d69..c9801f5ce4 100644 --- a/packages/flutter_tools/lib/src/commands/build_winuwp.dart +++ b/packages/flutter_tools/lib/src/commands/build_winuwp.dart @@ -31,8 +31,7 @@ class BuildWindowsUwpCommand extends BuildSubCommand { @override Future> get requiredArtifacts async => { - // TODO(flutter): add a windows_uwp artifact here once that is updated. - // https://github.com/flutter/flutter/issues/78627 + DevelopmentArtifact.windowsUwp, }; @override diff --git a/packages/flutter_tools/lib/src/commands/precache.dart b/packages/flutter_tools/lib/src/commands/precache.dart index 5d15a0a0ea..56ec32c4f7 100644 --- a/packages/flutter_tools/lib/src/commands/precache.dart +++ b/packages/flutter_tools/lib/src/commands/precache.dart @@ -50,6 +50,8 @@ class PrecacheCommand extends FlutterCommand { help: 'Precache artifacts for Linux desktop development.'); argParser.addFlag('windows', negatable: true, defaultsTo: false, help: 'Precache artifacts for Windows desktop development.'); + argParser.addFlag('winuwp', negatable: true, defaultsTo: false, + help: 'Precache artifacts for Windows UWP desktop development.'); argParser.addFlag('macos', negatable: true, defaultsTo: false, help: 'Precache artifacts for macOS desktop development.'); argParser.addFlag('fuchsia', negatable: true, defaultsTo: false, diff --git a/packages/flutter_tools/lib/src/flutter_cache.dart b/packages/flutter_tools/lib/src/flutter_cache.dart index 3808af887a..89cb8ffa1b 100644 --- a/packages/flutter_tools/lib/src/flutter_cache.dart +++ b/packages/flutter_tools/lib/src/flutter_cache.dart @@ -41,6 +41,7 @@ class FlutterCache extends Cache { registerArtifact(FlutterWebSdk(this, platform: platform)); registerArtifact(FlutterSdk(this, platform: platform)); registerArtifact(WindowsEngineArtifacts(this, platform: platform)); + registerArtifact(WindowsUwpEngineArtifacts(this, platform: platform)); registerArtifact(MacOSEngineArtifacts(this, platform: platform)); registerArtifact(LinuxEngineArtifacts(this, platform: platform)); registerArtifact(LinuxFuchsiaSDKArtifacts(this, platform: platform)); @@ -300,6 +301,33 @@ class WindowsEngineArtifacts extends EngineCachedArtifact { List getLicenseDirs() => const []; } +class WindowsUwpEngineArtifacts extends EngineCachedArtifact { + WindowsUwpEngineArtifacts(Cache cache, { + @required Platform platform, + }) : _platform = platform, + super( + 'windows-uwp-sdk', + cache, + DevelopmentArtifact.windowsUwp, + ); + + final Platform _platform; + + @override + List getPackageDirs() => const []; + + @override + List> getBinaryDirs() { + if (_platform.isWindows || ignorePlatformFiltering) { + return _windowsUwpDesktopBinaryDirs; + } + return const >[]; + } + + @override + List getLicenseDirs() => const []; +} + /// Artifacts required for desktop Linux builds. class LinuxEngineArtifacts extends EngineCachedArtifact { LinuxEngineArtifacts(Cache cache, { @@ -832,6 +860,13 @@ const List> _windowsDesktopBinaryDirs = >[ ['windows-x64-release', 'windows-x64-release/windows-x64-flutter.zip'], ]; +const List> _windowsUwpDesktopBinaryDirs = >[ + ['windows-uwp-x64-debug', 'windows-x64-debug/windows-uwp-x64-flutter.zip'], + ['windows-uwp-x64-debug', 'windows-x64/flutter-cpp-client-wrapper.zip'], + ['windows-uwp-x64-profile', 'windows-x64-profile/windows-uwp-x64-flutter.zip'], + ['windows-uwp-x64-release', 'windows-x64-release/windows-uwp-x64-flutter.zip'], +]; + const List> _macOSDesktopBinaryDirs = >[ ['darwin-x64', 'darwin-x64/FlutterMacOS.framework.zip'], ['darwin-x64-profile', 'darwin-x64-profile/FlutterMacOS.framework.zip'], diff --git a/packages/flutter_tools/test/general.shard/artifacts_test.dart b/packages/flutter_tools/test/general.shard/artifacts_test.dart index 0a0502d8ff..9d932a32d4 100644 --- a/packages/flutter_tools/test/general.shard/artifacts_test.dart +++ b/packages/flutter_tools/test/general.shard/artifacts_test.dart @@ -118,6 +118,18 @@ void main() { artifacts.getArtifactPath(Artifact.flutterTester, platform: TargetPlatform.linux_arm64), fileSystem.path.join('root', 'bin', 'cache', 'artifacts', 'engine', 'linux-arm64', 'flutter_tester'), ); + expect( + artifacts.getArtifactPath(Artifact.windowsUwpDesktopPath, platform: TargetPlatform.windows_uwp_x64, mode: BuildMode.debug), + fileSystem.path.join('root', 'bin', 'cache', 'artifacts', 'engine', 'windows-uwp-x64-debug'), + ); + expect( + artifacts.getArtifactPath(Artifact.windowsUwpDesktopPath, platform: TargetPlatform.windows_uwp_x64, mode: BuildMode.profile), + fileSystem.path.join('root', 'bin', 'cache', 'artifacts', 'engine', 'windows-uwp-x64-profile'), + ); + expect( + artifacts.getArtifactPath(Artifact.windowsUwpDesktopPath, platform: TargetPlatform.windows_uwp_x64, mode: BuildMode.release), + fileSystem.path.join('root', 'bin', 'cache', 'artifacts', 'engine', 'windows-uwp-x64-release'), + ); }); testWithoutContext('precompiled web artifact paths are correct', () { @@ -314,6 +326,20 @@ void main() { expect(artifacts.getArtifactPath(Artifact.engineDartBinary), contains('.exe')); }); + testWithoutContext('Looks up windows UWP artifacts in host engine', () async { + artifacts = LocalEngineArtifacts( + fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'winuwp_debug_unopt'), + fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'winuwp_debug_unopt'), + cache: cache, + fileSystem: fileSystem, + platform: FakePlatform(operatingSystem: 'windows'), + processManager: FakeProcessManager.any(), + operatingSystemUtils: FakeOperatingSystemUtils(), + ); + + expect(artifacts.getArtifactPath(Artifact.windowsUwpDesktopPath), '/out/winuwp_debug_unopt'); + }); + testWithoutContext('Looks up dart on linux platforms', () async { expect(artifacts.getArtifactPath(Artifact.engineDartBinary), isNot(contains('.exe'))); }); 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 913e715c94..21dcbd8f76 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 @@ -145,7 +145,7 @@ void main() { ); environment.buildDir.createSync(recursive: true); - final String windowsDesktopPath = artifacts.getArtifactPath(Artifact.windowsDesktopPath, platform: TargetPlatform.windows_x64, mode: BuildMode.debug); + final String windowsDesktopPath = artifacts.getArtifactPath(Artifact.windowsUwpDesktopPath, platform: TargetPlatform.windows_x64, mode: BuildMode.debug); final String windowsCppClientWrapper = artifacts.getArtifactPath(Artifact.windowsCppClientWrapper, platform: TargetPlatform.windows_x64, mode: BuildMode.debug); final String icuData = artifacts.getArtifactPath(Artifact.icuData, platform: TargetPlatform.windows_x64); final List requiredFiles = [ diff --git a/packages/flutter_tools/test/general.shard/cache_test.dart b/packages/flutter_tools/test/general.shard/cache_test.dart index 9844ea3c89..b9ba5773e7 100644 --- a/packages/flutter_tools/test/general.shard/cache_test.dart +++ b/packages/flutter_tools/test/general.shard/cache_test.dart @@ -589,6 +589,20 @@ void main() { ])); }); + testWithoutContext('Windows UWP desktop artifacts include profile, debug, and release artifacts', () { + final Cache cache = Cache.test(processManager: FakeProcessManager.any()); + final WindowsUwpEngineArtifacts artifacts = WindowsUwpEngineArtifacts( + cache, + platform: FakePlatform(operatingSystem: 'windows'), + ); + + expect(artifacts.getBinaryDirs(), containsAll([ + contains(contains('profile')), + contains(contains('release')), + contains(contains('debug')), + ])); + }); + testWithoutContext('Linux desktop artifacts ignore filtering when requested', () { fakeProcessManager.addCommand(unameCommandForX64);