| # 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/go/go_binary.gni") |
| import("//build/rust/rustc_binary.gni") |
| import("//build/sdk/sdk_atom.gni") |
| |
| _idk_only_parameters = [ |
| "category", |
| "sdk_area", |
| "sdk_name", |
| "output_name", |
| ] |
| |
| # Defines an IDK atom for a host tool. |
| # |
| # Parameters |
| # category (required) |
| # Publication level of the executable in the IDK. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # sdk_area (optional) |
| # [string] The API area responsible for maintaining this host tool. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # sdk_name (optional) |
| # Name of the library in the IDK. Defaults to `output_name`. |
| # |
| # binary (optional) |
| # Path to the tool binary. Defaults to "$root_out_dir/$output_name". |
| # |
| # output_name (optional) |
| # The tool's name. Defaults to `sdk_name` if specified or target_name. |
| # |
| # deps |
| # The tool target. |
| template("sdk_host_tool") { |
| assert(defined(invoker.category), "Must define an SDK category") |
| assert(is_host) |
| |
| output_name = target_name |
| if (defined(invoker.output_name)) { |
| output_name = invoker.output_name |
| } |
| |
| if (defined(invoker.sdk_name)) { |
| sdk_name = invoker.sdk_name |
| |
| # In the bazel macro, `output_name` is set to `sdk_name`, so when bazel2gn |
| # is used, the latter may be set while the former is not. Behave as if this |
| # value was specified as `output_name` instead, in which case they would |
| # be identical (via the else block below). |
| if (!defined(invoker.output_name)) { |
| output_name = sdk_name |
| } |
| } else { |
| sdk_name = output_name |
| } |
| |
| binary = "$root_out_dir/$output_name" |
| if (defined(invoker.binary)) { |
| binary = invoker.binary |
| } |
| |
| gn_deps = [] |
| if (defined(invoker.deps)) { |
| gn_deps += invoker.deps |
| } |
| |
| idk_path = "tools/$current_cpu/$sdk_name" |
| |
| sdk_atom(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "category", |
| "sdk_area", |
| ]) |
| |
| id = "sdk://$idk_path" |
| idk_name = output_name |
| |
| meta = { |
| dest = "$idk_path-meta.json" |
| type = "host_tool" |
| source_prebuild_info = { |
| file_base = "tools" |
| } |
| } |
| |
| files = [ |
| { |
| source = binary |
| dest = idk_path |
| }, |
| ] |
| |
| non_sdk_deps = invoker.deps |
| } |
| } |
| |
| # Defines an executable host tool and its IDK atom. |
| # |
| # Parameters |
| # category (required) |
| # Publication level of the executable in the IDK. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # sdk_area (optional) |
| # [string] The API area responsible for maintaining this host tool. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # sdk_name (optional) |
| # Name of the library in the IDK. Defaults to `output_name`. |
| # |
| # output_name (optional) |
| # The tool's name. Defaults to `sdk_name` if specified or target_name. |
| # |
| # sources, deps, etc. |
| # Usual GN meaning. |
| template("sdk_executable_host_tool") { |
| assert(defined(invoker.category), "Must define an SDK category") |
| assert(is_host) |
| |
| tool_name = target_name |
| sdk_target_name = target_name + "_sdk" |
| |
| executable(tool_name) { |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "category", |
| "sdk_area", |
| "sdk_name", |
| "output_name", |
| ]) |
| if (defined(visibility)) { |
| visibility += [ ":" + sdk_target_name ] |
| } |
| } |
| |
| sdk_host_tool(sdk_target_name) { |
| forward_variables_from(invoker, _idk_only_parameters) |
| deps = [ ":${tool_name}" ] |
| } |
| } |
| |
| # Defines a Go binary host tool and its IDK atom. |
| # |
| # Parameters |
| # category (required) |
| # Publication level of the executable in the IDK. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # sdk_area (optional) |
| # [string] The API area responsible for maintaining this host tool. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # sdk_name (optional) |
| # Name of the library in the IDK. Defaults to `output_name`. |
| # |
| # output_name (optional) |
| # The tool's name. Defaults to `sdk_name` if specified or target_name. |
| # |
| # sources, deps, etc. |
| # Usual GN meaning. |
| template("sdk_go_binary_host_tool") { |
| assert(defined(invoker.category), "Must define an SDK category") |
| assert(is_host) |
| |
| tool_name = target_name |
| sdk_target_name = target_name + "_sdk" |
| |
| go_binary(tool_name) { |
| forward_variables_from(invoker, "*", _idk_only_parameters) |
| if (defined(visibility)) { |
| visibility += [ ":" + sdk_target_name ] |
| } |
| } |
| |
| sdk_host_tool(sdk_target_name) { |
| forward_variables_from(invoker, _idk_only_parameters) |
| deps = [ ":${tool_name}" ] |
| } |
| } |
| |
| # Defines a Rust binary host tool and its IDK atom. |
| # |
| # Parameters |
| # category (required) |
| # Publication level of the executable in the IDK. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # sdk_area (optional) |
| # [string] The API area responsible for maintaining this host tool. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # sdk_name (optional) |
| # Name of the library in the IDK. Defaults to `output_name`. |
| # |
| # output_name (optional) |
| # The tool's name. Defaults to `sdk_name` if specified or target_name. |
| # |
| # sources, deps, etc. |
| # Usual GN meaning. |
| template("sdk_rustc_binary_host_tool") { |
| assert(defined(invoker.category), "Must define an SDK category") |
| assert(is_host) |
| |
| tool_name = target_name |
| |
| rustc_binary(tool_name) { |
| forward_variables_from(invoker, "*", _idk_only_parameters) |
| } |
| |
| sdk_host_tool(target_name + "_sdk") { |
| forward_variables_from(invoker, _idk_only_parameters) |
| deps = [ ":${tool_name}" ] |
| } |
| } |