| # 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/compiled_action.gni") |
| import("//build/sdk/sdk_atom.gni") |
| |
| template("zx_host_tool") { |
| # NOTE: |is_linux| is required because some //vendor/ targets depend on |
| # //zircon/tools/zbi(//build/toolchain:linux_x64), and that toolchain |
| # doesn't set `is_host` to true. |
| if (is_host || is_linux) { |
| not_needed(invoker, [ "sdk_migrated" ]) |
| executable(target_name) { |
| forward_variables_from(invoker, |
| "*", |
| [ |
| "sdk_migrated", |
| "target_name", |
| "testonly", |
| ]) |
| forward_variables_from(invoker, [ "testonly" ]) |
| } |
| |
| output_dir = root_out_dir |
| if (defined(invoker.output_dir)) { |
| output_dir = invoker.output_dir |
| } |
| output_name = target_name |
| if (defined(invoker.output_name)) { |
| output_name = invoker.output_name |
| } |
| output_extension = "" |
| if (current_os == "win") { |
| output_extension = "exe" |
| } |
| if (defined(invoker.output_extension)) { |
| output_extension = invoker.output_extension |
| } |
| |
| output_file = "$output_dir/$output_name" |
| if (output_extension != "") { |
| output_file += ".$output_extension" |
| } |
| |
| tool_name = target_name |
| file_base = "tools/$tool_name" |
| tool_src = output_file |
| |
| # NOTE: Don't create SDK atoms for testonly host tools, this is |
| # necessary to deal with //zircon/system/ulib/hwreg/test/asm |
| forward_variables_from(invoker, [ "testonly" ]) |
| if (!defined(testonly)) { |
| testonly = false |
| } |
| |
| # TODO(fxbug.dev/42999): remove extra atom |
| if (current_cpu == host_cpu && !testonly) { |
| sdk_atom("${target_name}_sdk_legacy") { |
| id = "sdk://$file_base" |
| category = "partner" |
| |
| meta = { |
| dest = "$file_base-meta.json" |
| schema = "host_tool" |
| value = { |
| type = "host_tool" |
| name = tool_name |
| root = "tools" |
| files = [ file_base ] |
| } |
| } |
| |
| files = [ |
| { |
| source = tool_src |
| dest = file_base |
| }, |
| ] |
| non_sdk_deps = [ ":${tool_name}" ] |
| } |
| } |
| |
| if (host_os == "linux" || host_os == "mac") { |
| file_base = "tools/$current_cpu/$tool_name" |
| } |
| |
| sdk_atom("${tool_name}_sdk") { |
| id = "sdk://$file_base" |
| category = "partner" |
| |
| meta = { |
| dest = "$file_base-meta.json" |
| schema = "host_tool" |
| value = { |
| type = "host_tool" |
| name = tool_name |
| root = "tools" |
| files = [ file_base ] |
| } |
| } |
| |
| files = [ |
| { |
| source = tool_src |
| dest = file_base |
| }, |
| ] |
| non_sdk_deps = [ ":${tool_name}" ] |
| } |
| } else { |
| # Not on host, don't compile anything. |
| not_needed(invoker, "*") |
| not_needed([ "target_name" ]) |
| } |
| } |
| |
| set_defaults("zx_host_tool") { |
| configs = default_executable_configs |
| } |
| |
| template("zx_host_tool_action") { |
| assert(defined(invoker.tool), "tool must be defined for $target_name") |
| compiled_action(target_name) { |
| tool = invoker.tool |
| forward_variables_from(invoker, "*", [ "tool" ]) |
| } |
| } |
| |
| template("zx_host_tool_action_foreach") { |
| assert(defined(invoker.tool), "tool must be defined for $target_name") |
| compiled_action_foreach(target_name) { |
| tool = invoker.tool |
| forward_variables_from(invoker, "*", [ "tool" ]) |
| } |
| } |