| # Copyright 2020 The Fuchsia 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("//build/components.gni") |
| import("//build/dart/config.gni") |
| import("//build/dart/dart.gni") |
| import("//build/dart/dart_package_config.gni") |
| import("//build/dart/kernel/dart_kernel.gni") |
| import("//build/flutter/config.gni") |
| import("//tools/cmc/build/cmc.gni") |
| |
| # Creates a flutter asset manifest from the pubspec.yaml file. |
| # |
| # Parameters |
| # |
| # pubsec (required) |
| # The path to the pubsec.yaml file which contains the assets |
| # Type: path |
| # |
| # component_name (required) |
| # The name of the component |
| # Type: string |
| # |
| # package_config (required) |
| # The path to the package_config.json file which contains the source map |
| # Type: path |
| # |
| template("_flutter_asset_manifest") { |
| action(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "testonly", |
| "visibility", |
| ]) |
| assert(defined(invoker.component_name), "component_name is required") |
| assert(defined(invoker.package_config), "package_config is required") |
| assert(defined(invoker.pubspec), "pubspec is required") |
| |
| _flutter_base = "//third_party/dart-pkg/git/flutter" |
| _flutter_asset_tools_label = "$_flutter_base/packages/flutter_tools:fuchsia_asset_builder($host_toolchain)" |
| _flutter_asset_tools_out_dir = |
| get_label_info(_flutter_asset_tools_label, "root_out_dir") |
| _flutter_asset_tools_bin = |
| "$_flutter_asset_tools_out_dir/dart-tools/fuchsia_asset_builder" |
| |
| _flutter_asset_tools_snapshot_label = "$_flutter_base/packages/flutter_tools:fuchsia_asset_builder_snapshot($host_toolchain)" |
| _flutter_asset_tools_target_gen_dir = |
| get_label_info(_flutter_asset_tools_snapshot_label, "target_gen_dir") |
| _flutter_asset_tools_snapshot = |
| "$_flutter_asset_tools_target_gen_dir/fuchsia_asset_builder.snapshot" |
| |
| script = "//build/flutter/internal/gen_asset_manifest.py" |
| |
| inputs = [ |
| invoker.pubspec, |
| _flutter_asset_tools_bin, |
| _flutter_asset_tools_snapshot, |
| ] |
| |
| _asset_manifest = |
| "$target_gen_dir/build/${invoker.component_name}_pkgassets" |
| depfile = "${_asset_manifest}.d" |
| outputs = [ _asset_manifest ] |
| |
| args = [ |
| "--flutter-root", |
| rebase_path(_flutter_base, root_build_dir), |
| "--flutter-tools", |
| rebase_path(_flutter_asset_tools_bin, root_build_dir), |
| "--asset-dir", |
| rebase_path("$target_gen_dir/build/__untraced_flutter_assets__", |
| root_build_dir), |
| "--packages", |
| rebase_path(invoker.package_config, root_build_dir), |
| "--output", |
| rebase_path(_asset_manifest, root_build_dir), |
| "--component-name", |
| invoker.component_name, |
| "--manifest", |
| rebase_path(invoker.pubspec, root_build_dir), |
| "--depfile", |
| rebase_path(depfile, root_build_dir), |
| ] |
| |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += [ |
| _flutter_asset_tools_label, |
| _flutter_asset_tools_snapshot_label, |
| ] |
| |
| metadata = { |
| distribution_entries = [ |
| { |
| file = rebase_path(_asset_manifest, root_build_dir) |
| label = get_label_info(target_name, "label_with_toolchain") |
| }, |
| ] |
| } |
| } |
| } |
| |
| # Defines a component which will run in a flutter_runner or dart_runner |
| # |
| # This template is not intended to be used directly. Users should use the |
| # flutter_component and dart_component actions instead. |
| # |
| # Parameters |
| # |
| # manifest (required) |
| # The component manifest |
| # Type: path |
| # |
| # test_runtime_shard (optional) |
| # The path to the dart test shard. |
| # Type: path |
| # |
| # main_package (required) |
| # The name of the package containing the main_dart |
| # Type: string |
| # |
| # component_name (optional) |
| # The name of the component. |
| # Type: string |
| # Default: target_name |
| # |
| # build_cfg (required) |
| # A description of how to build this component. This object needs |
| # to contain the following variables: |
| # runtime_meta: a path to the partial cmx file containing the runner |
| # runtime_meta_v2: a path to the partial cml file containing the runner |
| # platform_name: either 'dart_runner' or 'flutter_runner' |
| # is_aot: a boolean indicating if this is an AOT build |
| # is_product: a boolean indicating if this is a product build |
| # enable_asserts: whether we should enable asserts when compiling |
| # is_debug: whether to build the dart kernel with debugging information |
| # |
| # main_dart (required) |
| # File containing the main function of the component. |
| # Type: string |
| # |
| # generate_asset_manifest (optional) |
| # If true, will generate an asset manifest for this component |
| # Type: boolean |
| # Default: false |
| # |
| # null_safe (optional) |
| # If true, this component will be compiled with --sound-null-safety |
| # |
| # deps |
| # testonly |
| # visibility |
| template("flutter_dart_component") { |
| assert(defined(invoker.manifest), "must specify a manifest file") |
| assert(defined(invoker.build_cfg), "must specify build_cfg") |
| assert(defined(invoker.main_dart), "Must specify main_dart") |
| assert(defined(invoker.main_package), "Must specify main_package") |
| |
| build_cfg = invoker.build_cfg |
| |
| _component_deps = [] |
| if (defined(invoker.deps)) { |
| _component_deps += invoker.deps |
| } |
| |
| if (defined(invoker.component_name)) { |
| _component_name = invoker.component_name |
| } else { |
| _component_name = target_name |
| } |
| |
| # Flutter and Dart components must run inside the runner which matches how |
| # the component was compiled. For example, a JIT component must run in the JIT |
| # runner. This is done by merging the component's manifest with the |
| # build_cfg.runtime_meta manifest. |
| _manifest_extension = get_path_info(invoker.manifest, "extension") |
| _merged_target_name = "${target_name}_merged.${_manifest_extension}" |
| |
| _merge_manifests = [ invoker.manifest ] |
| if (_manifest_extension == "cml") { |
| _merge_manifests += [ rebase_path(build_cfg.runtime_meta_v2, ".") ] |
| } else { |
| _merge_manifests += [ rebase_path(build_cfg.runtime_meta, ".") ] |
| } |
| |
| # Add test runtime shard to make sure test component's fuchsia.test.Suite |
| # protocol is exposed for the test_manager to use. |
| if (defined(invoker.test_runtime_shard)) { |
| _merge_manifests += [ rebase_path(invoker.test_runtime_shard, ".") ] |
| } |
| |
| cmc_merge(_merged_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| sources = _merge_manifests |
| } |
| |
| _merged_outputs = get_target_outputs(":$_merged_target_name") |
| _manifest = _merged_outputs[0] |
| _manifest_deps = [ ":$_merged_target_name" ] |
| |
| _dart_package_config_target_name = "${target_name}_dart_package" |
| dart_package_config(_dart_package_config_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| |
| deps = _component_deps |
| } |
| |
| _package_config_outputs = |
| get_target_outputs(":$_dart_package_config_target_name") |
| _packages_path = _package_config_outputs[0] |
| |
| _kernel_target_name = _component_name + "_kernel" |
| _kernel_target_dep_name = _kernel_target_name + "_gen_file" |
| _kernel_path = "$target_gen_dir/__untraced_dart_kernel__/${target_name}.dil" |
| |
| dart_kernel(_kernel_target_name) { |
| kernel_path = _kernel_path |
| |
| # establishes a dependency chain for the snapshot since |
| # the kernel is wrapped in a group |
| kernel_target_name = _kernel_target_dep_name |
| |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| "main_dart", |
| "main_package", |
| "null_safe", |
| ]) |
| |
| deps = [ ":$_dart_package_config_target_name" ] |
| |
| packages_path = _packages_path |
| args = [ |
| "--component-name", |
| _component_name, |
| ] |
| |
| # always generate a manifest for fuchsia builds. If this is an aot build |
| # the kernel will ignore this variable. |
| generate_manifest = true |
| |
| platform_name = build_cfg.platform_name |
| product = build_cfg.is_product |
| is_aot = build_cfg.is_aot |
| is_debug = build_cfg.is_debug |
| } |
| |
| _component_deps += [ ":$_kernel_target_name" ] |
| |
| if (defined(invoker.generate_asset_manifest) && |
| invoker.generate_asset_manifest) { |
| _asset_manifest_target_name = "${target_name}_asset_manifest" |
| _flutter_asset_manifest(_asset_manifest_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| component_name = _component_name |
| package_config = _packages_path |
| pubspec = "pubspec.yaml" |
| deps = [ ":$_dart_package_config_target_name" ] |
| } |
| |
| _component_deps += [ ":$_asset_manifest_target_name" ] |
| } |
| |
| if (build_cfg.is_aot) { |
| _snapshot_path = "$target_gen_dir/${_component_name}_snapshot.so" |
| _snapshot_target_name = target_name + "_snapshot" |
| |
| _stats_json_path = |
| "$target_gen_dir/${_component_name}/stats/symbol_sizes.json" |
| |
| action(_snapshot_target_name) { |
| no_output_dir_leaks = false |
| |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| |
| deps = [ ":$_kernel_target_dep_name" ] |
| inputs = [ _kernel_path ] |
| outputs = [ |
| _snapshot_path, |
| _stats_json_path, |
| ] |
| |
| if (build_cfg.is_product) { |
| script = gen_snapshot_product |
| } else { |
| script = gen_snapshot |
| } |
| |
| args = [ |
| "--deterministic", |
| "--snapshot_kind=app-aot-elf", |
| "--elf=" + rebase_path(_snapshot_path, root_build_dir), |
| "--print-instructions-sizes-to=" + |
| rebase_path(_stats_json_path, root_build_dir), |
| ] |
| |
| # No asserts in debug or release product. |
| # No asserts in non-product release |
| # Yes asserts in non-product debug. |
| if (build_cfg.enable_asserts) { |
| args += [ "--enable_asserts" ] |
| } |
| args += [ rebase_path(_kernel_path, root_build_dir) ] |
| |
| pool = "//build/config:local($default_toolchain)" |
| } |
| |
| # copy the snapshot as a resource |
| _snapshot_resource_target_name = "${target_name}_snapshot_resource" |
| resource(_snapshot_resource_target_name) { |
| sources = [ _snapshot_path ] |
| outputs = [ "data/${_component_name}/app_aot_snapshot.so" ] |
| } |
| |
| _component_deps += [ |
| ":$_snapshot_resource_target_name", |
| ":$_snapshot_target_name", |
| ] |
| } |
| |
| fuchsia_component(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| "component_name", |
| ]) |
| deps = _component_deps |
| manifest_deps = _manifest_deps |
| manifest = _manifest |
| } |
| } |