| # Copyright 2023 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/toolchain/zircon/gcc.gni") |
| import("//build/zircon/c_utils.gni") |
| |
| # Extract a text ABI (.ifs) specification file from a binary. |
| # |
| # This defines an action() target that extracts a `.ifs` file describing the |
| # ABI of an ELF binary. The binary is found via $deps. |
| # |
| # Parameters |
| # |
| # * args |
| # - Optional: Extra arguments (switches) passed to the `llvm-ifs` tool. |
| # - Type: list(string) |
| # - Default: [] |
| # |
| # * deps |
| # - Required: Must reach one linking target. See link_output_rspfile(). |
| # - Type: list(label) |
| # |
| # * outputs |
| # - Required: Must be a singleton list of the output .ifs file path. |
| # - Type: list(file) |
| # |
| # * visibility, testonly |
| # - Optional: Usual GN meanings., |
| # |
| template("ifs_extract") { |
| ifs_outputs = invoker.outputs |
| assert(ifs_outputs == [ ifs_outputs[0] ], |
| "ifs_extract() requires exactly one file in `outputs`") |
| |
| if (defined(invoker.args)) { |
| ifs_args = invoker.args |
| } else { |
| ifs_args = [] |
| } |
| |
| main_target = target_name |
| rspfile_target = "_ifs_extract.$main_target.rsp" |
| rspfile = "$target_gen_dir/$main_target.rsp" |
| |
| link_output_rspfile(rspfile_target) { |
| visibility = [ ":$main_target" ] |
| forward_variables_from(invoker, [ "testonly" ]) |
| outputs = [ rspfile ] |
| deps = invoker.deps |
| } |
| |
| toolchain_utils_action(main_target) { |
| forward_variables_from(invoker, |
| [ |
| "visibility", |
| "testonly", |
| ]) |
| script = true |
| utils = [ "ifs" ] |
| sources = [ rspfile ] |
| deps = [ ":$rspfile_target" ] |
| outputs = ifs_outputs |
| args = ifs_args + ifs_extra_switches |
| args += [ |
| "--input-format=ELF", |
| "--write-if-changed", |
| "--output-ifs=" + rebase_path(ifs_outputs[0], root_build_dir), |
| "@" + rebase_path(rspfile, root_build_dir), |
| ] |
| } |
| } |