| # Copyright 2022 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_archive.gni") |
| import("//build/packages/prebuilt_package.gni") |
| |
| # Exports a fuchsia package built via GN to be used within |
| # the Bazel build graph as bazel_input_resource with a .far resource. |
| # |
| # Usage: |
| # |
| # 1. Wrap an existing GN fuchsia_package rule with: |
| # ``` |
| # fuchsia_package("foo") { |
| # ... |
| # } |
| # |
| # export_fuchsia_package_to_bazel("foo_for_bazel") { |
| # package = ":foo" |
| # } |
| # ``` |
| # 2. On the Bazel side, the .far file should be loaded using: |
| # ``` |
| # fuchsia_prebuilt_package( |
| # name = "foo", |
| # archive = "@gn_targets//{gn_dir}:foo.archive" |
| # ) |
| # ``` |
| # Where {gn_dir} matches the target's definition's directory. |
| # |
| # Parameters |
| # |
| # package (required) |
| # A 'fuchsia_package' target label. |
| # |
| # package_name (optional) |
| # The name to overwrite the underlying fuchsia_package target name. |
| # Default is the name of the 'package' label. |
| # |
| # gn_targets_name (optional) |
| # Which target name to use in the @gn_targets repository for |
| # this package. Default is package_name. |
| # |
| # deps (optional) |
| # testonly (optional) |
| # visibility (optional) |
| # Usual GN meanings. |
| # |
| template("export_fuchsia_package_to_bazel") { |
| assert(defined(invoker.package), "Must specify package.") |
| |
| targets = { |
| package_name = get_label_info(invoker.package, "name") |
| if (defined(invoker.package_name)) { |
| package_name = invoker.package_name |
| } |
| archive_label = "${target_name}.archive" |
| } |
| |
| files = { |
| bazel_output = "${targets.package_name}.far" |
| } |
| |
| fuchsia_package_archive(targets.archive_label) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "testonly", |
| "visibility", |
| "applicable_licenses", |
| ]) |
| package = invoker.package |
| } |
| |
| bazel_input_resource(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "gn_target_names", |
| "deps", |
| "testonly", |
| "visibility", |
| "applicable_licenses", |
| ]) |
| deps = [ ":${targets.archive_label}" ] |
| sources = get_target_outputs(":${targets.archive_label}") |
| outputs = [ files.bazel_output ] |
| |
| if (!defined(gn_targets_name)) { |
| gn_targets_name = targets.package_name |
| } |
| } |
| } |