| # 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/components/fuchsia_component.gni") |
| import("//build/dist/distribution_manifest.gni") |
| import("//build/drivers/driver_manifest.gni") |
| import("//tools/cmc/build/cmc.gni") |
| |
| # Defines a Fuchsia driver component. |
| # A driver component is a normal component that launches a driver. |
| # For more information on components see: |
| # https://fuchsia.dev/fuchsia-src/development/components/build |
| # |
| # At the moment this template will generate the Component Manifest |
| # at build time. If you'd like to write your own Component Manifest, |
| # simply use the fuchsia_component build template. |
| # |
| # The component manifest is automatically generated that points to the |
| # correct driver library and bind file. If 'deps' includes more than |
| # one driver library or more than one bind file, this will cause a build-time |
| # error. |
| # |
| # Parameters |
| # |
| # manifest (optional) |
| # The component manifest. If this is not present then this target will |
| # generate a component manifest for the driver. |
| # Type: path |
| # deps |
| # testonly |
| # visibility |
| template("fuchsia_driver_component") { |
| generate_manifest = true |
| if (defined(invoker.manifest)) { |
| generate_manifest = false |
| } |
| |
| if (generate_manifest) { |
| distribution_manifest_target = "${target_name}_distribution_manifest" |
| distribution_manifest_file = |
| "${target_gen_dir}/${target_name}.distribution_manifest" |
| distribution_manifest(distribution_manifest_target) { |
| visibility = [ ":*" ] |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "testonly", |
| ]) |
| outputs = [ "${distribution_manifest_file}" ] |
| } |
| |
| manifest_target = "${target_name}_manifest" |
| manifest_path = "${target_gen_dir}/meta/${target_name}.cml" |
| action(manifest_target) { |
| visibility = [ ":*" ] |
| forward_variables_from(invoker, [ "testonly" ]) |
| deps = [ ":${distribution_manifest_target}" ] |
| script = "//build/drivers/create_component_manifest.py" |
| inputs = [ distribution_manifest_file ] |
| outputs = [ manifest_path ] |
| args = [ |
| "--distribution_manifest", |
| rebase_path(distribution_manifest_file, root_build_dir), |
| "--output", |
| rebase_path(outputs[0], root_build_dir), |
| ] |
| } |
| |
| full_manifest_target = "${target_name}_full_manifest" |
| cmc_merge(full_manifest_target) { |
| visibility = [ ":*" ] |
| forward_variables_from(invoker, [ "testonly" ]) |
| output_name = invoker.target_name + ".cml" |
| deps = [ ":${manifest_target}" ] |
| sources = [] |
| foreach(dep, deps) { |
| sources += get_target_outputs(dep) |
| } |
| } |
| } |
| |
| fuchsia_component(target_name) { |
| # TODO(fxbug.dev/80980): Remove check_includes = false. |
| check_includes = false |
| forward_variables_from(invoker, |
| [ |
| "visibility", |
| "component_name", |
| "testonly", |
| "manifest", |
| "deps", |
| ]) |
| if (generate_manifest) { |
| deps += [ ":${full_manifest_target}" ] |
| manifest = get_target_outputs(":${full_manifest_target}") |
| manifest = manifest[0] |
| } |
| metadata = { |
| # Used by the assert_driver_components template. |
| driver_component_barrier = [] |
| } |
| } |
| } |