| # 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/dart/config.gni") |
| import("//build/dart/dart.gni") |
| import("//build/dart/dart_package_config.gni") |
| import("//build/dart/kernel/dart_kernel.gni") |
| import("//src/sys/build/components.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" |
| |
| _asset_manifest = |
| "$target_gen_dir/build/${invoker.component_name}_pkgassets" |
| |
| hermetic_deps = false |
| script = "//build/flutter/internal/gen_asset_manifest.py" |
| |
| args = [ |
| "--flutter-root", |
| rebase_path(_flutter_base), |
| "--flutter-tools", |
| rebase_path(_flutter_asset_tools_bin), |
| "--asset-dir", |
| rebase_path("$target_gen_dir/build"), |
| "--app-dir", |
| rebase_path("."), |
| "--packages", |
| rebase_path(invoker.package_config), |
| "--output", |
| rebase_path(_asset_manifest), |
| "--component-name", |
| invoker.component_name, |
| "--manifest", |
| rebase_path(invoker.pubspec), |
| ] |
| |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += [ _flutter_asset_tools_label ] |
| |
| outputs = [ _asset_manifest ] |
| |
| 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 |
| # |
| # 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 |
| # 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 |
| # |
| # 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 |
| # |
| # 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 |
| } |
| |
| # merge the runner cmx into this one which allows us to switch runners based |
| # on compilation modes |
| _merged_target_name = "${target_name}_merged.cmx" |
| |
| cmc_merge(_merged_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| sources = [ |
| invoker.manifest, |
| rebase_path(build_cfg.runtime_meta, "."), |
| ] |
| } |
| |
| _merged_outputs = [] |
| _merged_outputs += get_target_outputs(":$_merged_target_name") |
| _merged_manifest = _merged_outputs[0] |
| |
| _component_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_output = [] |
| _package_config_output = |
| get_target_outputs(":$_dart_package_config_target_name") |
| _packages_path = _package_config_output[0] |
| |
| _kernel_target_name = _component_name + "_kernel" |
| _kernel_target_dep_name = _kernel_target_name + "_gen_file" |
| _kernel_path = "$target_gen_dir/${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", |
| ]) |
| |
| 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 |
| } |
| |
| _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) { |
| 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 = [ |
| "--no_causal_async_stacks", |
| "--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 (is_debug && !dart_force_product) { |
| if (build_cfg.enable_asserts) { |
| args += [ "--enable_asserts" ] |
| } |
| args += [ rebase_path(_kernel_path, root_build_dir) ] |
| |
| pool = "//build/dart:dart_pool($dart_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 = _merged_manifest |
| } |
| } |