【问题标题】:Understanding the GN build system in Fuchsia OS, what is `build_api_module`?了解 Fuchsia OS 中的 GN 构建系统,什么是`build_api_module`?
【发布时间】:2021-08-03 00:14:04
【问题描述】:

GN 代表生成忍者。它生成构建东西的忍者文件。主文件是BUILD.GN在紫红色源码树的根目录

它包含很多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 gn fuchsia


    【解决方案1】:

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

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

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

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

    【讨论】:

    猜你喜欢
    • 2019-10-09
    • 2013-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-01
    相关资源
    最近更新 更多