了解 Fuchsia OS 中的 GN 构建系统,什么是 `build_api_module`?

问题描述

GN 代表生成忍者。它生成构建事物的忍者文件。主文件BUILD.GN在fuchsia源码树的根目录

它包含很多 build_api_module 调用

build_api_module("images") {
  testonly = true
  data_keys = [ "images" ]
  deps = [
    # XXX(46415): as the build is specialized by board (bootfs_only)
    # for bringup,it is not possible for this to be complete. As this
    # is used in the formation of the build API with infrastructure,# and infrastructure assumes that the board configuration modulates
    # the deFinition of `zircon-a` between bringup/non-bringup,we can
    # not in fact have a complete description. See the associated
    # conditional at this group also.
    "build/images",# This has the images referred to by $qemu_kernel_label entries.
    "//build/zircon/zbi_tests",]
}

但是,我不清楚这到底是做什么的。例如查看它在 build/config/build_api_module.gn 上的定义:

template("build_api_module") {
  if (current_toolchain == default_toolchain) {
    generated_file(target_name) {
      outputs = [ "$root_build_dir/$target_name.json" ]
      forward_variables_from(invoker,[
                               "contents","data_keys","deps","Metadata","testonly","visibility","walk_keys","rebase",])
      output_conversion = "json"
      Metadata = {
        build_api_modules = [ target_name ]
        if (defined(invoker.Metadata)) {
          forward_variables_from(invoker.Metadata,"*",[ "build_api_modules" ])
        }
      }
    }
  } else {
    not_needed([ "target_name" ])
    not_needed(invoker,"*")
  }
}

看起来它只是生成一个文件

有人可以向我解释一下 build_api_module("images") 是如何构建所有锆石内核映像的吗?

解决方法

build_api_module() 目标生成 JSON 文件,描述有关当前构建系统配置的一些信息。这些文件通常由需要了解当前构建的其他工具(在某些情况下依赖于其他构建规则)使用。

一个例子是生成 tests.json 文件的 tests targetfx test 使用此文件来确定哪些测试可用,并将您提供的测试名称与要调用的组件 URL 相匹配。

有人可以向我解释一下 build_api_module("images") 是如何构建所有锆石内核映像的吗?

它没有。这些目标是对当前构建配置的描述性,而不是对构建生成的工件的描述性。在这种特定情况下,FEMU 和 images.json 等工具通常使用 ffx 文件来确定要在目标设备上使用的系统映像。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...