blob: 9f3e18debfcdbecfbcf05cc89f5d06493597bcea [file] [log] [blame]
# 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") # For dart_force_product
import("//build/dart/dart.gni")
import("//build/flutter/internal/flutter_dart_component.gni")
# Defines a Dart component which can be used in a fuchsia package
#
# Dart components require at least one library which contains a main
# entry point. The library should be defined using the dart_library.gni.
#
# ```
# dart_library("lib") {
# package_name = "my_library"
# sources = [ "main.dart" ]
# }
# ```
#
# Once a library is defined a flutter component can be created which
# depends on this package. If the component needs any other resources they may
# be defined using the resource target and added to the components deps.
#
# ```
# resource("text-file") {
# sources = [ "text_file.txt" ]
# outputs = [ "data/text_file.txt" ]
# }
#
# dart_component("my-component") {
# manifest = "meta/my-component.cmx"
# main_package = "my_library"
# deps = [
# ":lib",
# ":text-file",
# ]
# }
# ```
#
# Once a component is defined it can be added as a dep of a fuchsia_package
# ```
# fuchsia_package("my-package") {
# deps = [
# ":my-component",
# ]
# }
# ```
#
# Parameters
#
# manifest (required)
# The component manifest
# Type: path
#
# main_package (required)
# The name of the package containing main_dart
# Type: string
#
# component_name (optional)
# The name of the component.
# Type: string
# Default: target_name
#
# main_dart (optional)
# File containing the main function of the component.
# Type: string
# Default: main.dart
#
# package_root (optional)
# The root of the package generated for this component. Each component must
# have a unique package_root. For each component, there must be a
# pubspec.yaml and an analysis_options.yaml at the package root.
# Type: path
# Default: "."
#
# deps
# testonly
# visibility
template("dart_component") {
assert(defined(invoker.main_package), "Must define main_package")
assert(defined(invoker.manifest), "Must define manifest")
_component_deps = []
if (defined(invoker.deps)) {
_component_deps += invoker.deps
}
_product_suffix = ""
if (dart_force_product) {
_product_suffix = "_product"
}
_runtime_meta =
"//build/dart/meta/${dart_compilation_mode}${_product_suffix}_runtime"
_component_deps += [ "//topaz/runtime/dart_runner:dart_${dart_compilation_mode}${_product_suffix}_runner" ]
if (defined(invoker.main_dart)) {
_main_dart = invoker.main_dart
} else {
_main_dart = "main.dart"
}
flutter_dart_component(target_name) {
forward_variables_from(invoker,
"*",
[
"deps",
"main_dart",
])
deps = _component_deps
main_dart = _main_dart
runtime_meta = _runtime_meta
platform_name = dart_platform_name
generate_asset_manifest = false
}
}