From c1b58c4c221f9822796040f77e1a8e3155e16822 Mon Sep 17 00:00:00 2001 From: godofredoc Date: Mon, 28 Mar 2022 18:25:03 -0700 Subject: [PATCH] Targets to generate macos gen snapshot. (flutter/engine#31950) --- engine/src/flutter/build/archives/BUILD.gn | 37 ++++++++++++++- engine/src/flutter/common/config.gni | 10 ++++ .../shell/platform/darwin/macos/BUILD.gn | 14 ++++-- .../flutter/shell/platform/embedder/BUILD.gn | 33 ++++++++++++- engine/src/flutter/sky/tools/gen_snapshots.py | 47 +++++++++++++++++++ .../src/flutter/sky/tools/macos_snapshots.gni | 45 ++++++++++++++++++ 6 files changed, 178 insertions(+), 8 deletions(-) create mode 100755 engine/src/flutter/sky/tools/gen_snapshots.py create mode 100644 engine/src/flutter/sky/tools/macos_snapshots.gni diff --git a/engine/src/flutter/build/archives/BUILD.gn b/engine/src/flutter/build/archives/BUILD.gn index 1ade93a731..99f8ae0ab6 100644 --- a/engine/src/flutter/build/archives/BUILD.gn +++ b/engine/src/flutter/build/archives/BUILD.gn @@ -1,12 +1,17 @@ import("//flutter/build/zip_bundle.gni") +import("//flutter/sky/tools/macos_snapshots.gni") zip_bundle("artifacts") { - output = "$full_platform_name/artifacts.zip" deps = [ "//flutter/flutter_frontend_server:frontend_server", "//flutter/lib/snapshot:generate_snapshot_bin", "//flutter/shell/testing:testing", ] + prefix = "$full_platform_name/" + if (flutter_runtime_mode != "debug") { + prefix = "$full_platform_name-$flutter_runtime_mode/" + } + output = "$prefix/artifacts.zip" files = [ { source = "//third_party/icu/flutter/icudtl.dat" @@ -78,7 +83,8 @@ zip_bundle("flutter_patched_sdk") { if (build_engine_artifacts && flutter_prebuilt_dart_sdk) { copy("dart_sdk_archive") { sources = [ prebuilt_dart_sdk_archive ] - outputs = [ "$root_out_dir/zip_archives/dart-sdk-$full_platform_name.zip" ] + outputs = + [ "$root_out_dir/zip_archives/dart-sdk-$full_target_platform_name.zip" ] } } @@ -134,4 +140,31 @@ if (is_mac) { "//flutter/shell/platform/darwin/macos:macos_flutter_framework_archive", ] } + + macos_gen_snapshots("create_macos_gen_snapshots") { + visibility = [ ":*" ] + deps = [ "//flutter/lib/snapshot:generate_snapshot_bins" ] + arch = "$target_cpu" + } + + zip_bundle("archive_gen_snapshot") { + deps = [ ":create_macos_gen_snapshots" ] + suffix = "-$flutter_runtime_mode" + if (flutter_runtime_mode == "debug") { + suffix = "" + } + output = "$full_platform_name$suffix/gen_snapshot.zip" + files = [ + { + source = "$root_out_dir/gen_snapshot_$target_cpu" + destination = "gen_snapshot_$target_cpu" + }, + ] + } + + group("flutter_embedder_framework") { + deps = [ + "//flutter/shell/platform/embedder:flutter_embedder_framework_archive", + ] + } } diff --git a/engine/src/flutter/common/config.gni b/engine/src/flutter/common/config.gni index 45e3cc962e..128ba65905 100644 --- a/engine/src/flutter/common/config.gni +++ b/engine/src/flutter/common/config.gni @@ -77,6 +77,16 @@ if (_platform_name == "mac") { full_platform_name = "$_platform_name-$host_cpu" +_platform_target_name = target_os +if (_platform_target_name == "mac") { + _platform_target_name = "darwin" +} else if (_platform_target_name == "win" || + _platform_target_name == "winuwp") { + _platform_target_name = "windows" +} + +full_target_platform_name = "$_platform_target_name-$target_cpu" + # Prebuilt Dart SDK location if (flutter_prebuilt_dart_sdk) { diff --git a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn index 2ddb5babbc..8013f31b22 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn @@ -323,26 +323,30 @@ if (build_glfw_shell) { } zip_bundle("zip_macos_flutter_framework") { - output = "FlutterMacOS.framework.zip" - visibility = [ ":*" ] deps = [ ":_generate_symlinks" ] + output = "tmp/FlutterMacOS.framework.zip" + visibility = [ ":*" ] files = [ { source = "$root_out_dir/FlutterMacOS.framework" - destination = "FlutterMacOS.framework.zip" + destination = "FlutterMacOS.framework" }, ] } zip_bundle("macos_flutter_framework_archive") { - output = "$full_platform_name/FlutterMacOS.framework.zip" deps = [ ":copy_framework_podspec", ":zip_macos_flutter_framework", ] + prefix = "$full_platform_name-$flutter_runtime_mode/" + if (flutter_runtime_mode == "debug") { + prefix = "$full_platform_name/" + } + output = "${prefix}FlutterMacOS.framework.zip" files = [ { - source = "$root_out_dir/zip_archives/FlutterMacOS.framework.zip" + source = "$root_out_dir/zip_archives/tmp/FlutterMacOS.framework.zip" destination = "FlutterMacOS.framework.zip" }, { diff --git a/engine/src/flutter/shell/platform/embedder/BUILD.gn b/engine/src/flutter/shell/platform/embedder/BUILD.gn index 5bd5d667f4..b54a0d25a5 100644 --- a/engine/src/flutter/shell/platform/embedder/BUILD.gn +++ b/engine/src/flutter/shell/platform/embedder/BUILD.gn @@ -379,7 +379,13 @@ if (is_mac && !embedder_for_target) { action("generate_symlinks") { visibility = [ ":*" ] script = "//build/config/mac/package_framework.py" - outputs = [ "$root_build_dir/FlutterEmbedder.stamp" ] + outputs = [ + "$root_build_dir/FlutterEmbedder.stamp", + _flutter_embedder_framework_dir, + "$_flutter_embedder_framework_dir/Resources", + "$_flutter_embedder_framework_dir/Headers", + "$_flutter_embedder_framework_dir/Modules", + ] args = [ "--framework", "FlutterEmbedder.framework", @@ -428,6 +434,31 @@ group("flutter_engine") { } } +if (is_mac) { + zip_bundle("flutter_embedder_framework_archive") { + deps = [ ":generate_symlinks" ] + output = "$full_platform_name/FlutterEmbedder.framework.zip" + files = [ + { + source = "$root_out_dir/FlutterEmbedder.framework" + destination = "FlutterEmbedder.framework" + }, + { + source = "$root_out_dir/FlutterEmbedder.framework/Resources" + destination = "FlutterEmbedder.framework/Resources" + }, + { + source = "$root_out_dir/FlutterEmbedder.framework/Headers" + destination = "FlutterEmbedder.framework/Headers" + }, + { + source = "$root_out_dir/FlutterEmbedder.framework/Modules" + destination = "FlutterEmbedder.framework/Modules" + }, + ] + } +} + if (host_os == "linux" || host_os == "win") { zip_bundle("embedder-archive") { output = "$full_platform_name/$full_platform_name-embedder.zip" diff --git a/engine/src/flutter/sky/tools/gen_snapshots.py b/engine/src/flutter/sky/tools/gen_snapshots.py new file mode 100755 index 0000000000..bd4b8662cd --- /dev/null +++ b/engine/src/flutter/sky/tools/gen_snapshots.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import argparse +import subprocess +import sys +import os + + +def main(): + parser = argparse.ArgumentParser( + description='Copies architecture-dependent gen_snapshot binaries to output dir' + ) + + parser.add_argument('--dst', type=str, required=True) + parser.add_argument('--out-dir', type=str) + parser.add_argument('--arch', type=str) + + args = parser.parse_args() + + subdir = '' + if args.arch != 'x64': + subdir = 'clang_x64' + + generate_gen_snapshot( + os.path.join(args.out_dir, subdir), + os.path.join(args.dst, 'gen_snapshot_%s' % args.arch) + ) + + +def generate_gen_snapshot(directory, destination): + gen_snapshot_dir = os.path.join(directory, 'gen_snapshot') + if not os.path.isfile(gen_snapshot_dir): + print('Cannot find gen_snapshot at %s' % gen_snapshot_dir) + sys.exit(1) + + subprocess.check_call( + ['xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination] + ) + + +if __name__ == '__main__': + sys.exit(main()) + diff --git a/engine/src/flutter/sky/tools/macos_snapshots.gni b/engine/src/flutter/sky/tools/macos_snapshots.gni new file mode 100644 index 0000000000..105ff2dcfa --- /dev/null +++ b/engine/src/flutter/sky/tools/macos_snapshots.gni @@ -0,0 +1,45 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//flutter/common/config.gni") + +# Generates macos gen snapshots $root_build_dir/zip_archives folder. +# + +# The output variable specifies the name of the zip file to create. +# The files variable is an array of scopes that specify a source file or +# directory and a destination path in the archive to create. +# +# For example, to create a zip file named archive.zip with all files in the +# root directory of the archive: +# +# zip_bundle("sample") { +# output = "archive.zip" +# files = [ +# { +# source = "$root_build_dir/some/path/to/lib.so" +# destination = "lib.so" +# }, +# { +# source = "$root_build_dir/some/other/path/with/files" +# destination = "other_files" +# }, +# ] +# } +template("macos_gen_snapshots") { + action(target_name) { + forward_variables_from(invoker, [ "visibility" ]) + deps = invoker.deps + outputs = [ "$root_build_dir/gen_snapshot_${invoker.arch}" ] + script = "//flutter/sky/tools/gen_snapshots.py" + args = [ + "--dst", + rebase_path("$root_out_dir/"), + "--out-dir", + rebase_path("$root_out_dir"), + "--arch", + invoker.arch, + ] + } +}