blob: 7278e2eff828096d3fccb645a0c35cdd6a82fd4e [file] [log] [blame]
# Copyright 2018 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/config/clang/clang.gni")
import("//build/images/zircon/bootsvc.gni")
declare_args() {
# Manifest files describing target libraries from toolchains.
# Can be either // source paths or absolute system paths.
toolchain_manifests = [
# clang_prefix is relative to root_build_dir.
rebase_path("${clang_prefix}/../lib/${clang_target}.manifest",
"",
root_build_dir),
]
# Path to Clang lib directory.
clang_lib_dir = rebase_path("${clang_prefix}/../lib", root_build_dir)
# Extra args to globally apply to the manifest generation script.
extra_manifest_args = []
}
# Manifests inherited from Zircon.
# Paths in these manifest are relative to this build's root directory.
zircon_boot_manifests = []
zircon_boot_manifests_deps = []
zircon_aux_manifests = []
zircon_aux_manifests_deps = []
foreach(flavor,
[
"legacy-image",
"migrated-image",
]) {
_image_flavor = {
}
_image_flavor = {
target = "//build/unification/images:$flavor"
gen_dir = get_label_info(target, "target_out_dir")
name = get_label_info(target, "name")
file = "$gen_dir/$name.unification.manifest"
}
zircon_boot_manifests += [ _image_flavor.file ]
zircon_boot_manifests_deps += [ _image_flavor.target ]
}
foreach(flavor, bootsvc_flavors) {
legacy_bootsvc = {
}
legacy_bootsvc = {
target = "//build/images/zircon:${flavor.name}"
gen_dir = get_label_info(target, "target_gen_dir")
name = get_label_info(target, "name")
file = "$gen_dir/$name.rebased.manifest"
}
zircon_boot_manifests += [ legacy_bootsvc.file ]
zircon_boot_manifests_deps += [ legacy_bootsvc.target ]
}
foreach(flavor,
[
"legacy-aux",
"migrated-aux",
]) {
_aux_flavor = {
}
_aux_flavor = {
target = "//build/unification/images:$flavor"
gen_dir = get_label_info(target, "target_out_dir")
name = get_label_info(target, "name")
file = "$gen_dir/$name.unification.manifest"
}
zircon_aux_manifests += [ _aux_flavor.file ]
zircon_aux_manifests_deps += [ _aux_flavor.target ]
}
# Action target that generates a response file in GN's "shlex" format.
#
# Parameters
#
# output_name (optional, default: target_name)
# [path] Response file to write (if relative, relative to target_out_dir).
#
# response_file_contents (required)
# data_deps (optional)
# deps (optional)
# metadata (optional)
# public_deps (optional)
# testonly (optional)
# visibility (optional)
# Same as for any GN `action()` target.
#
template("generate_response_file") {
action(target_name) {
forward_variables_from(invoker,
[
"data_deps",
"deps",
"metadata",
"output_name",
"public_deps",
"response_file_contents",
"testonly",
"visibility",
])
if (!defined(output_name)) {
output_name = target_name
}
outputs = [
"$target_out_dir/$output_name",
]
assert(
defined(response_file_contents),
"generate_response_file(\"${target_name}\") must define response_file_contents")
if (response_file_contents == []) {
# GN doesn't allow an empty response file.
script = "/bin/cp"
args = [
"-f",
"/dev/null",
]
} else {
script = "/bin/ln"
args = [
"-f",
"{{response_file_name}}",
]
}
args += rebase_path(outputs, root_build_dir)
}
}
# Action target that generates a manifest file in the `target=/abs/file`
# format used by `zbi`, `blobfs`, etc. ELF files in the manifest have
# their dynamic linking details examined and other necessary ELF files
# implicitly added to the manifest. All such files have their build IDs
# and unstripped files recorded in a build ID map (`ids.txt` file).
# Outputs: $target_out_dir/$target_name, $target_out_dir/$target_name.ids.txt
#
# Parameters
#
# args (required)
# [list of strings] Additional arguments to finalize_manifests.py;
# `sources` should list any files directly referenced.
#
# bootfs_manifest (optional)
# [string] Output a separate manifest file for the Zircon BOOTFS. This
# manifest will get the `bootfs_zircon_groups` selections, while the
# main manifest will get `zircon_groups` and the other entries
# indicated by `args`. The main output manifest will assume that
# libraries from the BOOTFS are available and not duplicate them.
#
# bootfs_zircon_groups (required with `bootfs_manifest`)
# [string] Comma-separated list of Zircon manifest groups to include
# in `bootfs_manifest`.
#
# bootfs_allowlist (optional with `bootfs_manifest`)
# [list of strings] Comma-separated list of files to include in the bootfs
# manifest created. This overrides the option set by `bootfs_zircon_groups`
#
# output_name (optional, default: target_name)
# [string] Root name of the output manifest file.
#
# zircon_groups (optional, default: "")
# [string] Comma-separated list of Zircon manifest groups to include.
# If this is "", then the Zircon manifest only provides binaries
# to satisfy dependencies.
#
# deps (optional)
# sources (optional)
# testonly (optional)
# visibility (optional)
# Same as for any GN `action()` target.
#
template("generate_manifest") {
assert(defined(invoker.args),
"generate_manifest(\"${target_name}\") requires args")
action(target_name) {
forward_variables_from(invoker,
[
"deps",
"public_deps",
"sources",
"testonly",
"visibility",
"zircon_groups",
])
if (!defined(sources)) {
sources = []
}
if (!defined(deps)) {
deps = []
}
if (!defined(zircon_groups)) {
zircon_groups = ""
}
if (defined(invoker.output_name)) {
manifest_file = "$target_out_dir/${invoker.output_name}"
} else {
manifest_file = "$target_out_dir/$target_name"
}
depfile = "${manifest_file}.d"
build_id_file = "${manifest_file}.ids.txt"
stripped_dir = "${manifest_file}.stripped"
script = "//build/images/finalize_manifests.py"
inputs = rebase_path([
"elfinfo.py",
"manifest.py",
"variant.py",
],
"",
"//build/images")
outputs = [
manifest_file,
build_id_file,
]
args = extra_manifest_args + [
"--depfile=" + rebase_path(depfile, root_build_dir),
"--build-id-file=" + rebase_path(build_id_file, root_build_dir),
"--stripped-dir=" + rebase_path(stripped_dir, root_build_dir),
"--build-id-dir=" + rebase_path("$root_build_dir/.build-id"),
"--clang-lib-dir=" + clang_lib_dir,
"@{{response_file_name}}",
]
response_file_contents = []
# Collected by //build/images:ids.txt
metadata = {
build_ids_barrier = []
build_ids = [ rebase_path(build_id_file, root_build_dir) ]
}
# First the toolchain and Zircon manifests are pure auxiliaries:
# they just supply libraries that might satisfy dependencies.
sources += toolchain_manifests
foreach(manifest, toolchain_manifests) {
manifest_cwd = get_path_info(rebase_path(manifest), "dir")
response_file_contents += [
"--cwd=$manifest_cwd",
"--manifest=" + rebase_path(manifest),
]
}
sources += zircon_aux_manifests + zircon_boot_manifests
deps += zircon_aux_manifests_deps + zircon_boot_manifests_deps
foreach(manifest, zircon_aux_manifests + zircon_boot_manifests) {
response_file_contents += [
"--cwd=.",
"--manifest=" + rebase_path(manifest),
]
}
manifests = []
if (defined(invoker.bootfs_manifest)) {
assert(
defined(invoker.bootfs_zircon_groups),
"generate_manifest with bootfs_manifest needs bootfs_zircon_groups")
outputs += [ invoker.bootfs_manifest ]
# Omit both devhost variants from the Zircon input manifest.
# Each variant will be included if there is a driver that needs it.
# That way we can tell whether both variants are actually in use.
response_file_contents += [
"--exclude=bin/devhost",
"--exclude=bin/devhost.asan",
# Omit the empty file deposited by the Zircon build, since
# we will add our own.
"--exclude=config/devmgr",
]
# Omit virtual-console from the Zircon manifest since it is built in //src.
response_file_contents += [ "--exclude=bin/virtual-console" ]
if (defined(invoker.bootfs_allowlist) && invoker.bootfs_allowlist != []) {
not_needed(invoker, [ "bootfs_zircon_groups" ])
response_file_contents += [ "--output=" +
rebase_path(invoker.bootfs_manifest,
root_build_dir) ]
foreach(binary, invoker.bootfs_allowlist) {
response_file_contents += [ "--binary=" + binary ]
}
} else {
manifests += [
{
output = invoker.bootfs_manifest
groups = invoker.bootfs_zircon_groups
},
]
}
}
manifests += [
{
output = manifest_file
groups = zircon_groups
},
]
foreach(manifest, manifests) {
response_file_contents +=
[ "--output=" + rebase_path(manifest.output, root_build_dir) ]
if (manifest.groups != "") {
# The boot manifests were already listed as auxiliaries, but now
# list them again with selected groups to go in the output. This
# means the script processes these manifests twice, but we can't
# just omit them as auxiliaries because dependencies from the
# binaries selected here have to be found by target name in a
# previously-processed manifest.
response_file_contents += [ "--groups=${manifest.groups}" ]
sources += zircon_boot_manifests
foreach(manifest, zircon_boot_manifests) {
response_file_contents += [
"--cwd=.",
"--manifest=" + rebase_path(manifest),
]
}
}
}
response_file_contents += [ "--groups=all" ]
# Now further `--manifest` or `--entry` arguments in invoker.args will
# contribute to the output manifest.
response_file_contents += [ "--cwd=." ] + invoker.args
}
}