| # Copyright 2021 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/bazel/bazel_inputs.gni") |
| import("//build/components/fuchsia_package.gni") |
| import("//build/dist/distribution_manifest.gni") |
| import("//build/packages/exported_fuchsia_package_archive.gni") |
| |
| # Defines a Fuchsia driver package. |
| # A fuchsia_driver_package is a fuchsia_package but with extra |
| # metadata so that the drivers inside the package can be collected into a |
| # Driver Manifest. |
| # |
| # A driver is a shared library that's placed in the /driver/ directory of the package. |
| # Drivers are normally built with the `fuchsia_driver` build target. |
| # |
| # The fuchsia_driver_package does not need to contain any components, although |
| # components placed in the package will behave normally. |
| # |
| # For more information on a fuchsia_package see: |
| # //build/components/fuchsia_package.gni |
| # |
| # Parameters: |
| # |
| # driver_components (required) |
| # A list of driver components to include in the package. |
| # Type: list(labels) |
| # |
| # package_name (optional) |
| # The name of the package. |
| # Type: string |
| # Default: target_name |
| # |
| # disable_elf_binaries_checks (optional) |
| # Set to true to disable ELF binaries verification checks. Useful |
| # if your package includes non-Fuchsia ELF binaries, or if some |
| # of them are unstripped. |
| # Type: boolean |
| # Default: false |
| # |
| # export_to_bazel (optional) |
| # When set, creates a target `${target_name}.bazel_input` that can be dep'ed |
| # on to export the GN-built package to the bazel build graph. |
| # Type: boolean |
| # Default: false |
| # |
| # gn_targets_name (optional) |
| # The target name to use in the @gn_targets repository for this package. |
| # Only applicable when `export_to_bazel` is set to true. |
| # Default: target_name |
| # |
| # deps |
| # testonly |
| # visibility |
| template("fuchsia_driver_package") { |
| if (current_toolchain == default_toolchain) { |
| assert( |
| defined(invoker.driver_components) && invoker.driver_components != [], |
| "`driver_components` must be specified when calling fuchsia_driver_package($target_name)") |
| |
| package_name = target_name |
| if (defined(invoker.package_name)) { |
| package_name = invoker.package_name |
| } |
| |
| export_to_bazel = false |
| if (defined(invoker.export_to_bazel)) { |
| export_to_bazel = invoker.export_to_bazel |
| } |
| |
| distribution_manifest_target = |
| "${target_name}_driver_package_manifest_distribution_manifest" |
| distribution_manifest_file = "${target_gen_dir}/${distribution_manifest_target}.distribution_manifest" |
| distribution_manifest(distribution_manifest_target) { |
| deps = invoker.driver_components |
| forward_variables_from(invoker, [ "testonly" ]) |
| outputs = [ "${distribution_manifest_file}" ] |
| } |
| |
| package_target = target_name |
| fuchsia_package(package_target) { |
| forward_variables_from(invoker, "*") |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += [ ":${distribution_manifest_target}" ] |
| deps += invoker.driver_components |
| } |
| |
| archive_target = target_name + "-archive" |
| exported_fuchsia_package_archive(archive_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| package = ":${package_target}" |
| } |
| |
| if (export_to_bazel) { |
| _gn_targets_name = target_name |
| if (defined(invoker.gn_targets_name)) { |
| _gn_targets_name = invoker.gn_targets_name |
| } |
| |
| bazel_input_file(target_name + ".bazel_input") { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| "applicable_licenses", |
| ]) |
| generator = ":${archive_target}" |
| outputs = get_target_outputs(":${archive_target}_archive") |
| gn_targets_name = _gn_targets_name |
| } |
| } |
| } else { |
| group(target_name) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| deps = [ ":$target_name($default_toolchain)" ] |
| } |
| not_needed(invoker, "*") |
| } |
| } |