| # Copyright 2019 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") |
| |
| # A prebuilt host executable which can be bundled in an SDK. |
| # |
| # prebuilt (required) |
| # Label of the prebuilt executable. |
| # |
| # category (required) |
| # Publication level of the executable in SDKs. |
| # See //build/sdk/sdk_atom.gni. |
| # |
| # 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. |
| |
| template("sdk_prebuilt_executable") { |
| assert(defined(invoker.category), "Must define an SDK category") |
| assert(defined(invoker.prebuilt), "Must set the path") |
| if (is_fuchsia) { |
| assert(false, "Only valid for host tools") |
| } |
| |
| main_target_name = target_name |
| |
| group(main_target_name) { |
| # No-op target, only used to abide by naming conventions. |
| } |
| |
| tool_name = get_path_info(invoker.prebuilt, "file") |
| file_base = "tools/$tool_name" |
| |
| _legacy_tool_diff = sdk_legacy_tool_allowlist |
| _legacy_tool_diff += [ tool_name ] |
| _legacy_tool_diff -= [ tool_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}_sdk_legacy") { |
| id = "sdk://$file_base" |
| |
| category = invoker.category |
| |
| meta = { |
| dest = "$file_base-meta.json" |
| schema = "host_tool" |
| value = { |
| type = "host_tool" |
| name = tool_name |
| root = "tools" |
| files = [ file_base ] |
| } |
| } |
| |
| files = [ |
| { |
| source = invoker.prebuilt |
| dest = file_base |
| }, |
| ] |
| |
| if (defined(invoker.sdk_deps)) { |
| deps = invoker.sdk_deps |
| } |
| |
| non_sdk_deps = [ ":$main_target_name" ] |
| if (defined(invoker.non_sdk_deps)) { |
| non_sdk_deps += invoker.non_sdk_deps |
| } |
| } |
| } else { |
| # TODO(fxbug.dev/42999): dummy target to soften transition. |
| # Remove once all petal dependents are removed. |
| _non_legacy_name = ":" + target_name + "_sdk" |
| sdk_atom_alias("${target_name}_sdk_legacy") { |
| atom = _non_legacy_name |
| } |
| } |
| |
| if (host_os == "linux" || host_os == "mac") { |
| file_base = "tools/$current_cpu/$tool_name" |
| } |
| |
| sdk_atom("${target_name}_sdk") { |
| id = "sdk://$file_base" |
| |
| category = invoker.category |
| |
| meta = { |
| dest = "$file_base-meta.json" |
| schema = "host_tool" |
| value = { |
| type = "host_tool" |
| name = tool_name |
| root = "tools" |
| files = [ file_base ] |
| } |
| } |
| |
| files = [ |
| { |
| source = invoker.prebuilt |
| dest = file_base |
| }, |
| ] |
| |
| if (defined(invoker.sdk_deps)) { |
| deps = invoker.sdk_deps |
| } |
| |
| non_sdk_deps = [ ":$main_target_name" ] |
| if (defined(invoker.non_sdk_deps)) { |
| non_sdk_deps += invoker.non_sdk_deps |
| } |
| } |
| } |