From 25e9d0494b8b9c9e88aa1326337f509c1efa6072 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 18 May 2020 09:26:07 -0700 Subject: [PATCH] Add Linux GTK artifacts to unpack list (#57452) To simplify development of the in-progress GTK embedding, which will replace the GLFW embedding on Linux, add the GTK artifacts to the unpack list. This means that until the transition, both the GLFW and GTK artifacts will be unpacked. Part of #54860 --- packages/flutter_tools/lib/src/artifacts.dart | 6 +++ .../lib/src/build_system/targets/desktop.dart | 44 ++++++++++--------- .../lib/src/build_system/targets/linux.dart | 14 +++++- .../lib/src/build_system/targets/windows.dart | 2 +- packages/flutter_tools/lib/src/cache.dart | 1 + .../build_system/targets/desktop_test.dart | 6 +-- .../build_system/targets/linux_test.dart | 19 +++++++- 7 files changed, 64 insertions(+), 28 deletions(-) diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart index b15cd7ecb8..b664561821 100644 --- a/packages/flutter_tools/lib/src/artifacts.dart +++ b/packages/flutter_tools/lib/src/artifacts.dart @@ -49,6 +49,8 @@ enum Artifact { iproxy, /// The root of the Linux desktop sources. linuxDesktopPath, + // The root of the cpp headers for Linux desktop. + linuxHeaders, // The root of the cpp client code for Linux desktop. linuxCppClientWrapper, /// The root of the Windows desktop sources. @@ -118,6 +120,8 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo return 'iproxy'; case Artifact.linuxDesktopPath: return ''; + case Artifact.linuxHeaders: + return 'flutter_linux'; case Artifact.windowsDesktopPath: return ''; case Artifact.windowsCppClientWrapper: @@ -356,6 +360,7 @@ class CachedArtifacts extends Artifacts { case Artifact.linuxDesktopPath: case Artifact.windowsDesktopPath: case Artifact.flutterMacOSPodspec: + case Artifact.linuxHeaders: // TODO(jonahwilliams): remove once debug desktop artifacts are uploaded // under a separate directory from the host artifacts. // https://github.com/flutter/flutter/issues/38935 @@ -530,6 +535,7 @@ class LocalEngineArtifacts extends Artifacts { case Artifact.iproxy: return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path; case Artifact.linuxDesktopPath: + case Artifact.linuxHeaders: return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); case Artifact.linuxCppClientWrapper: return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); diff --git a/packages/flutter_tools/lib/src/build_system/targets/desktop.dart b/packages/flutter_tools/lib/src/build_system/targets/desktop.dart index 30525e0229..491ada835d 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/desktop.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/desktop.dart @@ -8,7 +8,7 @@ import '../../base/file_system.dart'; import '../depfile.dart'; /// Unpack the engine artifact list [artifacts] from [engineSourcePath] and -/// [clientSourcePath] (if provided) into a directory [outputDirectory]. +/// [clientSourcePaths] (if provided) into a directory [outputDirectory]. /// /// Returns a [Depfile] including all copied files. /// @@ -19,7 +19,7 @@ Depfile unpackDesktopArtifacts({ @required List artifacts, @required Directory outputDirectory, @required String engineSourcePath, - String clientSourcePath, + List clientSourcePaths, }) { final List inputs = []; final List outputs = []; @@ -46,28 +46,30 @@ Depfile unpackDesktopArtifacts({ inputs.add(inputFile); outputs.add(destinationFile); } - if (clientSourcePath == null) { + if (clientSourcePaths == null) { return Depfile(inputs, outputs); } - final Directory clientSourceDirectory = fileSystem.directory(clientSourcePath); - if (!clientSourceDirectory.existsSync()) { - throw Exception('Missing clientSourceDirectory: $clientSourcePath'); - } - for (final File input in clientSourceDirectory - .listSync(recursive: true) - .whereType()) { - final String outputPath = fileSystem.path.join( - outputDirectory.path, - fileSystem.path.relative(input.path, from: clientSourceDirectory.parent.path), - ); - final File destinationFile = fileSystem.file(outputPath); - if (!destinationFile.parent.existsSync()) { - destinationFile.parent.createSync(recursive: true); + for (final String clientSourcePath in clientSourcePaths) { + final Directory clientSourceDirectory = fileSystem.directory(clientSourcePath); + if (!clientSourceDirectory.existsSync()) { + throw Exception('Missing clientSourceDirectory: $clientSourcePath'); + } + for (final File input in clientSourceDirectory + .listSync(recursive: true) + .whereType()) { + final String outputPath = fileSystem.path.join( + outputDirectory.path, + fileSystem.path.relative(input.path, from: clientSourceDirectory.parent.path), + ); + final File destinationFile = fileSystem.file(outputPath); + if (!destinationFile.parent.existsSync()) { + destinationFile.parent.createSync(recursive: true); + } + final File inputFile = fileSystem.file(input); + inputFile.copySync(destinationFile.path); + inputs.add(inputFile); + outputs.add(destinationFile); } - final File inputFile = fileSystem.file(input); - inputFile.copySync(destinationFile.path); - inputs.add(inputFile); - outputs.add(destinationFile); } return Depfile(inputs, outputs); } diff --git a/packages/flutter_tools/lib/src/build_system/targets/linux.dart b/packages/flutter_tools/lib/src/build_system/targets/linux.dart index d6a7f67e1a..9d0a8e3ab3 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/linux.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/linux.dart @@ -15,11 +15,15 @@ import 'icon_tree_shaker.dart'; /// The only files/subdirectories we care out. const List _kLinuxArtifacts = [ + // GLFW. Will be removed after the switch to GTK. 'libflutter_linux_glfw.so', 'flutter_export.h', 'flutter_messenger.h', 'flutter_plugin_registrar.h', 'flutter_glfw.h', + // GTK. Not yet used by the template. + 'libflutter_linux_gtk.so', + // Shared. 'icudtl.dat', ]; @@ -55,12 +59,20 @@ class UnpackLinux extends Target { mode: buildMode, platform: TargetPlatform.linux_x64, ); + // For the GLFW embedding. final String clientSourcePath = environment.artifacts .getArtifactPath( Artifact.linuxCppClientWrapper, mode: buildMode, platform: TargetPlatform.linux_x64, ); + // For the GTK embedding. + final String headersPath = environment.artifacts + .getArtifactPath( + Artifact.linuxHeaders, + mode: buildMode, + platform: TargetPlatform.linux_x64, + ); final Directory outputDirectory = environment.fileSystem.directory( environment.fileSystem.path.join( environment.projectDir.path, @@ -73,7 +85,7 @@ class UnpackLinux extends Target { engineSourcePath: engineSourcePath, outputDirectory: outputDirectory, artifacts: _kLinuxArtifacts, - clientSourcePath: clientSourcePath, + clientSourcePaths: [clientSourcePath, headersPath], ); final DepfileService depfileService = DepfileService( fileSystem: environment.fileSystem, 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 eb37948e2c..44ed2731ec 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/windows.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/windows.dart @@ -77,7 +77,7 @@ class UnpackWindows extends Target { artifacts: _kWindowsArtifacts, engineSourcePath: engineSourcePath, outputDirectory: outputDirectory, - clientSourcePath: clientSourcePath, + clientSourcePaths: [clientSourcePath], ); final DepfileService depfileService = DepfileService( fileSystem: environment.fileSystem, diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index d9a1b8ca4a..28392d08cc 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -1392,6 +1392,7 @@ const List> _windowsDesktopBinaryDirs = >[ const List> _linuxDesktopBinaryDirs = >[ ['linux-x64', 'linux-x64/linux-x64-flutter-glfw.zip'], ['linux-x64', 'linux-x64/flutter-cpp-client-wrapper-glfw.zip'], + ['linux-x64', 'linux-x64/linux-x64-flutter-gtk.zip'], ]; const List> _macOSDesktopBinaryDirs = >[ diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/desktop_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/desktop_test.dart index ba032693f6..65baadfd63 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/desktop_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/desktop_test.dart @@ -29,7 +29,7 @@ void main() { 'a.txt', 'b.txt', ], - clientSourcePath: 'foo', + clientSourcePaths: ['foo'], ); // Files are copied @@ -61,7 +61,7 @@ void main() { artifacts: [ 'a.txt', ], - clientSourcePath: 'foo' + clientSourcePaths: ['foo'], ), throwsA(isA())); }); @@ -76,7 +76,7 @@ void main() { artifacts: [ 'a.txt', ], - clientSourcePath: 'foo' + clientSourcePaths: ['foo'], ), throwsA(isA())); }); diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/linux_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/linux_test.dart index b57ed372ee..05a6e90153 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/linux_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/linux_test.dart @@ -30,6 +30,11 @@ void main() { mode: anyNamed('mode'), platform: anyNamed('platform'), )).thenReturn('linux-x64/cpp_client_wrapper_glfw'); + when(mockArtifacts.getArtifactPath( + Artifact.linuxHeaders, + mode: anyNamed('mode'), + platform: anyNamed('platform'), + )).thenReturn('linux-x64/flutter_linux'); final Environment testEnvironment = Environment.test( fileSystem.currentDirectory, @@ -45,13 +50,18 @@ void main() { await const UnpackLinux().build(testEnvironment); + // GLFW. expect(fileSystem.file('linux/flutter/ephemeral/libflutter_linux_glfw.so'), exists); expect(fileSystem.file('linux/flutter/ephemeral/flutter_export.h'), exists); expect(fileSystem.file('linux/flutter/ephemeral/flutter_messenger.h'), exists); expect(fileSystem.file('linux/flutter/ephemeral/flutter_plugin_registrar.h'), exists); expect(fileSystem.file('linux/flutter/ephemeral/flutter_glfw.h'), exists); - expect(fileSystem.file('linux/flutter/ephemeral/icudtl.dat'), exists); expect(fileSystem.file('linux/flutter/ephemeral/cpp_client_wrapper_glfw/foo'), exists); + // GTK. + expect(fileSystem.file('linux/flutter/ephemeral/libflutter_linux_gtk.so'), exists); + expect(fileSystem.file('linux/flutter/ephemeral/flutter_linux/foo.h'), exists); + // Both. + expect(fileSystem.file('linux/flutter/ephemeral/icudtl.dat'), exists); expect(fileSystem.file('linux/flutter/ephemeral/unrelated-stuff'), isNot(exists)); }); @@ -94,13 +104,18 @@ void main() { void setUpCacheDirectory(FileSystem fileSystem) { fileSystem.file('linux-x64/unrelated-stuff').createSync(recursive: true); + // GLFW. fileSystem.file('linux-x64/libflutter_linux_glfw.so').createSync(recursive: true); fileSystem.file('linux-x64/flutter_export.h').createSync(); fileSystem.file('linux-x64/flutter_messenger.h').createSync(); fileSystem.file('linux-x64/flutter_plugin_registrar.h').createSync(); fileSystem.file('linux-x64/flutter_glfw.h').createSync(); - fileSystem.file('linux-x64/icudtl.dat').createSync(); fileSystem.file('linux-x64/cpp_client_wrapper_glfw/foo').createSync(recursive: true); + // GTK. + fileSystem.file('linux-x64/libflutter_linux_gtk.so').createSync(recursive: true); + fileSystem.file('linux-x64/flutter_linux/foo.h').createSync(recursive: true); + // Both. + fileSystem.file('linux-x64/icudtl.dat').createSync(); fileSystem.file('packages/flutter_tools/lib/src/build_system/targets/linux.dart').createSync(recursive: true); }