1

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") 构建所有锆石内核映像吗?

4

1 回答 1

1

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

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

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

它没有。这些目标描述了当前的构建配置,它们并不规定构建生成的工件。在这种特定情况下,该images.json文件通常由 FEMU 等工具使用,并ffx确定在目标设备上使用哪些系统映像。

于 2021-08-02T16:14:04.880 回答