| # 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/sdk/sdk_atom.gni") |
| import("//build/sdk/sdk_atom_alias.gni") |
| |
| # Defines a host tool in the SDK. |
| # |
| # Parameters |
| # category (required) |
| # Publication level of the executable in SDKs. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # binary (optional) |
| # Path to the tool binary. Defaults to "$root_out_dir/$output_name". |
| # |
| # output_name (optional) |
| # The tool's name. Inferred from target_name by default. |
| # |
| # sdk_deps (optional) |
| # List of labels representing elements that should be added to SDKs |
| # alongside the present binary. |
| # Labels in the list must represent SDK-ready targets. |
| # |
| # deps, etc. |
| # Usual GN meaning. |
| template("sdk_host_tool") { |
| assert(defined(invoker.category), "Must define an SDK category") |
| |
| output_name = target_name |
| if (defined(invoker.output_name)) { |
| output_name = invoker.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 |
| } |
| |
| file_base = "tools/$output_name" |
| |
| _legacy_tool_diff = sdk_legacy_tool_allowlist |
| _legacy_tool_diff += [ output_name ] |
| _legacy_tool_diff -= [ output_name ] |
| is_legacy_tool = _legacy_tool_diff != sdk_legacy_tool_allowlist |
| |
| # TODO(fxbug.dev/42999): remove extra atom |
| if (is_legacy_tool && current_cpu == host_cpu) { |
| sdk_atom("${target_name}_legacy") { |
| id = "sdk://$file_base" |
| |
| category = invoker.category |
| |
| meta = { |
| dest = "$file_base-meta.json" |
| schema = "host_tool" |
| value = { |
| type = "host_tool" |
| name = output_name |
| root = "tools" |
| files = [ file_base ] |
| } |
| } |
| |
| files = [ |
| { |
| source = binary |
| dest = file_base |
| }, |
| ] |
| |
| if (defined(invoker.sdk_deps)) { |
| deps = invoker.sdk_deps |
| } |
| |
| non_sdk_deps = gn_deps |
| } |
| } else { |
| # TODO(fxbug.dev/42999): dummy target to soften transition. |
| # Remove once all petal dependents are removed. |
| _non_legacy_name = ":" + target_name |
| sdk_atom_alias("${target_name}_legacy") { |
| atom = _non_legacy_name |
| } |
| } |
| |
| if (host_os == "linux" || host_os == "mac") { |
| file_base = "tools/$current_cpu/$output_name" |
| } |
| |
| sdk_atom(target_name) { |
| id = "sdk://$file_base" |
| |
| category = invoker.category |
| |
| meta = { |
| dest = "$file_base-meta.json" |
| schema = "host_tool" |
| value = { |
| type = "host_tool" |
| name = output_name |
| root = "tools" |
| files = [ file_base ] |
| } |
| } |
| |
| files = [ |
| { |
| source = binary |
| dest = file_base |
| }, |
| ] |
| |
| if (defined(invoker.sdk_deps)) { |
| deps = invoker.sdk_deps |
| } |
| |
| non_sdk_deps = invoker.deps |
| } |
| } |