blob: 8683e8f9da7d56010e6d78240bd1530c68662c4f [file] [log] [blame]
# Copyright 2019 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("$zx/public/gn/build_api_module.gni")
import("$zx/public/gn/config/standard.gni")
import("$zx/public/gn/toolchain/environment_redirect.gni")
import("$zx/public/gn/zbi.gni")
# Build the native host tools intended for developer use.
_tools_targets = [ "tools" ]
foreach(host, standard_build_hosts) {
_tools_targets += [ "tools-${host.os}-${host.cpu}" ]
environment_redirect("tools-${host.os}-${host.cpu}.redirect") {
visibility = [ ":*" ]
testonly = true
environment_label = "$zx/public/gn/toolchain:host"
cpu = host.cpu
os = host.os
deps = [
"$zx/system/host:tools",
]
}
}
group("tools.redirect") {
visibility = [ ":*" ]
testonly = true
public_deps = [
":tools-${host_os}-${host_cpu}",
]
}
if (current_toolchain == default_toolchain) {
# Install the host developer tools for the running host platform in the
# "$root_build_dir/tools/" directory.
foreach(tools_target, _tools_targets) {
tools_rspfile = "$target_gen_dir/${tools_target}.rsp"
generated_file("$tools_target.rsp") {
visibility = [ ":$tools_target" ]
testonly = true
outputs = [
tools_rspfile,
]
deps = [
":$tools_target.redirect",
]
output_conversion = "list lines"
data_keys = [ "tool_executables" ]
}
action(tools_target) {
testonly = true
deps = [
":$tools_target.rsp",
]
script = "$zx/scripts/copy-files"
depfile = "$target_out_dir/$target_name.d"
outputs = [
depfile,
]
sources = [
tools_rspfile,
]
args = [
tools_target,
rebase_path(depfile, root_build_dir),
rebase_path(tools_rspfile, root_build_dir),
]
}
}
}
group("default") {
testonly = true
deps = [
":images",
":tools",
]
}
group("all-cpu") {
testonly = true
deps = []
foreach(cpu, standard_fuchsia_cpus) {
deps += [
":$cpu",
":core-tests-$cpu",
]
}
}
foreach(cpu, standard_fuchsia_cpus) {
if (current_toolchain == default_toolchain) {
zbi("core-tests-$cpu") {
output_dir = root_build_dir
testonly = true
cpu = cpu
deps = [
":core-tests-$cpu-deps",
]
}
zbi(cpu) {
output_dir = root_build_dir
testonly = true
cpu = cpu
deps = [
":everything-$cpu",
]
}
}
environment_redirect("core-tests-$cpu-deps") {
visibility = [ ":*" ]
testonly = true
cpu = cpu
environment_label = "$zx/public/gn/toolchain:user"
deps = [
"kernel",
"system/utest:core-tests",
]
}
environment_redirect("everything-$cpu") {
visibility = [ ":*" ]
testonly = true
environment_label = "$zx/public/gn/toolchain:user"
cpu = cpu
deps = [
"$zx/kernel",
"$zx/system/core",
"$zx/system/dev",
"$zx/system/uapp",
"$zx/system/utest",
"$zx/third_party/uapp",
]
if (cpu == "x64") {
deps += [ "$zx/bootloader" ]
}
}
}
# This is the top-level build API module that just lists all the others.
# Each element of the list is the simple name of the API module; the
# module's contents are found at "$root_build_dir/$target_name.json".
# Type: list(string)
build_api_module("api") {
testonly = true
data_keys = [ "build_api_modules" ]
deps = [
":buildargs",
":images",
]
}
# This just regurgitates the build arguments specified to `gn gen`. This is
# the exact JSON representation of the settings in "$root_build_dir/args.gn".
# It does not include build arguments left to their default values. So to
# reproduce the settings of this build, one could put in `args.gn`:
# ```
# forward_variables_from(read_file("buildargs.json", "json"), "*")
# ```
# Type: scope
build_api_module("buildargs") {
# The file does not exist at all if `gn gen` is run with no `--args`. But
# read_file() can't handle an optional file and there's no direct way to test
# for file existence from GN.
contents = exec_script("/bin/sh",
[
"-c",
"test ! -e args.gn || cat args.gn",
],
"scope")
}
# This describes all the "image" files the build can produce.
#
# Consumers of the build should look here for the images to be built.
# The $cpu, $name, and $type fields identify the purpose of each image.
# Consumers are expected to ignore extra images they have no use for or
# whose fields they don't understand.
#
# The $path field indicates where the file is found in the build
# directory. The presence of an image in the list means that the build
# *can* produce it, not that the build *will* produce it. Hence,
# consumers should use $path as an explicit argument to Ninja to ensure
# that each needed image gets built.
#
# Type: list(scope)
#
# cpu
# Required: CPU architecture the image is for, e.g. "arm64" or "x64".
# Type: string
#
# name
# Required: The primary way that this image is known to consumers.
# Note that the name need not be unique within the images list.
# The tuple of ($name, $type, $cpu) should be unique.
# Type: string
#
# label
# Required: The GN label of the image target.
# Type: label_with_toolchain
#
# path
# Required: Path to where the file is found, relative to $root_build_dir.
# This is also the argument to Ninja that ensures this image will be built.
# Type: path relative to $root_build_dir
#
# type
# Required: Type of file, e.g. "zbi". This often corresponds to the
# extension used on the image file name, but not always. For many
# miscellaneous formats, this is just "bin" and the consumer is
# expected to understand what the particular format is for particular
# $name, $cpu combinations. Other types include:
# * "zbi": the ZBI (<zircon/boot/image.h>) format
# * "efi": an EFI executable that an EFI boot loader can load
# * "kernel": some other format loaded by a boot loader or emulator
# * "blk": contents to be written to a storage device or partition
# Type: string
#
build_api_module("images") {
testonly = true
data_keys = [ "images" ]
deps = [
":all-cpu",
]
}