| # Copyright 2024 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. |
| |
| # This template will generate a `.ifs` text file based on parameters set in GN. |
| # The generated output of this target can be set as the $abi for an |
| # ifs_shared_library() target. |
| # |
| # Parameters: |
| # |
| # * soname |
| # - Optional: The name of the linkable library file to write. This should |
| # include a `lib` prefix (if applicable) and the `.so` extension. |
| # - Type: string |
| # |
| # * symbols |
| # - Required: The list of symbols defined by this generated ELF file. Each |
| # symbol must have a $name and a $type. The object may optionally have a |
| # $size or $weak boolean, if applicable. |
| # - Type: list(scope or string) |
| # - A string is shorthand for a scope `{ name = "..." type = "Func" }`. |
| # - A scope must have the following schema: |
| # * name |
| # - Required: The symbol name. |
| # - Type: string |
| # * type |
| # - Required: The symbol type. |
| # - Type: `Func`, `Object`, `TLS` |
| # * size |
| # - Optional: The symbol size (st_size) field. |
| # - Type: integer |
| # - Default: 0 |
| # * weak |
| # - Optional: If true, STB_WEAK rather than STB_GLOBAL. |
| # - Type: boolean |
| # - Default: false |
| # |
| # * needed_libs |
| # - Optional: The list of DT_NEEDEDs of this generated ELF file. |
| # Each element is a full SONAME, such as `libfoo.so`. |
| # - Type: list(string) |
| # |
| template("generated_ifs_file") { |
| generated_file(target_name) { |
| outputs = [ "$target_gen_dir/$target_name.ifs" ] |
| output_conversion = "list lines" |
| |
| contents = [ |
| "--- !ifs-v1", |
| "IfsVersion: 3.0", |
| ] |
| if (defined(invoker.soname)) { |
| contents += [ "SoName: ${invoker.soname}" ] |
| } |
| |
| contents += [ "Symbols:" ] |
| |
| foreach(symbol, invoker.symbols) { |
| if (symbol == "$symbol") { # String shorthand for common Func case. |
| symbol = { |
| name = symbol |
| type = "Func" |
| } |
| } |
| symbol_string = " - { Name: ${symbol.name}, Type: ${symbol.type}" |
| if (defined(symbol.size)) { |
| symbol_string += ", Size: ${symbol.size}" |
| } |
| if (defined(symbol.weak)) { |
| symbol_string += ", Weak: ${symbol.weak}" |
| } |
| symbol_string += " }" |
| contents += [ symbol_string ] |
| } |
| |
| if (defined(invoker.needed_libs)) { |
| contents += [ "NeededLibs:" ] |
| foreach(lib, invoker.needed_libs) { |
| contents += [ " - ${lib}" ] |
| } |
| } |
| |
| contents += [ "..." ] |
| |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| } |
| } |