| # Copyright 2018 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/compiled_action.gni") |
| import("//build/fidl/toolchain.gni") |
| |
| # Declares a source_set that contains code generated by fidlmerge from a |
| # template and a FIDL JSON file. |
| # |
| # Parameters |
| # |
| # fidl_target (required) |
| # Specifies the fidl target from which to read fidl json. For example, |
| # "//zircon/system/fidl/fuchsia-mem" for fuchsia.mem or |
| # "//sdk/fidl/fuchsia.sys" for fuchsia.sys. |
| # |
| # template_path (required) |
| # Specifies the template to use to generate the source code for the |
| # source_set. For example, "//garnet/public/build/fostr/fostr.fidlmerge". |
| # |
| # generated_source_base (required) |
| # The base file name from which the source_set's 'source' file names are |
| # generated. For example, "formatting". |
| # |
| # generated_source_extensions (optional) |
| # The list of extensions of source_set 'source' files that will be generated |
| # and included in the source set. By default, this is [ ".cc", ".h" ] |
| # |
| # options (optional) |
| # A single string with comma-separated key=value pairs. |
| # |
| # amendments_path (optional) |
| # Specifies a JSON file that contains amendments to be made to the fidl |
| # model before the template is applied. For example, |
| # "//garnet/public/build/fostr/fidl/fuchsia.media/amendments.fidlmerge". |
| # See the fidlmerge README for details. |
| # |
| # deps, public_deps, test_only, visibility (optional) |
| # These parameters are forwarded to the source_set. |
| # |
| |
| template("fidlmerge_cpp") { |
| assert(defined(invoker.fidl_target), |
| "fidlmerge_cpp requires parameter fidl_target.") |
| |
| assert(defined(invoker.template_path), |
| "fidlmerge_cpp requires parameter template_path.") |
| |
| assert(defined(invoker.generated_source_base), |
| "fidlmerge_cpp requires parameter generated_source_base.") |
| |
| fidl_target = invoker.fidl_target |
| template_path = invoker.template_path |
| source_base = invoker.generated_source_base |
| |
| if (defined(invoker.generated_source_extensions)) { |
| generated_source_extensions = invoker.generated_source_extensions |
| } else { |
| generated_source_extensions = [ |
| ".cc", |
| ".h", |
| ] |
| } |
| |
| main_target_name = target_name |
| generation_target_name = "${target_name}_generate" |
| |
| fidl_target_gen_dir = |
| get_label_info("$fidl_target($fidl_toolchain)", "target_gen_dir") |
| fidl_target_name = get_path_info(fidl_target_gen_dir, "file") |
| json_representation = "$fidl_target_gen_dir/$fidl_target_name.fidl.json" |
| |
| # Subtle: rebase dance, so that we allow paths up to and including the build |
| # dir to contain periods: |
| include_stem = |
| string_replace(rebase_path(target_gen_dir, root_build_dir), ".", "/") |
| file_stem = "$root_build_dir/$include_stem/$source_base" |
| |
| compiled_action(generation_target_name) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| visibility = [ ":$main_target_name" ] |
| |
| tool = "//tools/fidl/fidlmerge" |
| |
| inputs = [ |
| json_representation, |
| template_path, |
| ] |
| |
| outputs = [] |
| foreach(ext, generated_source_extensions) { |
| outputs += [ "$file_stem$ext" ] |
| } |
| |
| args = [ |
| "--template", |
| rebase_path(template_path, root_build_dir), |
| "--json", |
| rebase_path(json_representation, root_build_dir), |
| "--output-base", |
| rebase_path(file_stem, root_build_dir), |
| ] |
| |
| if (defined(invoker.options)) { |
| args += [ |
| "--options", |
| invoker.options, |
| ] |
| } |
| |
| if (defined(invoker.amendments_path)) { |
| args += [ |
| "--amend", |
| rebase_path(invoker.amendments_path, root_build_dir), |
| ] |
| } |
| |
| deps = [ "$fidl_target($fidl_toolchain)" ] |
| |
| if (defined(invoker.deps)) { |
| deps += invoker.deps |
| } |
| } |
| |
| source_set(main_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "testonly", |
| "visibility", |
| ]) |
| |
| sources = [] |
| foreach(ext, generated_source_extensions) { |
| sources += [ "$file_stem$ext" ] |
| } |
| |
| public_deps = [ ":$generation_target_name" ] |
| if (defined(invoker.public_deps)) { |
| public_deps += invoker.public_deps |
| } |
| } |
| } |