blob: eae6e4eefb49857ce650b0dee1295d763d7c040f [file] [log] [blame]
# Copyright 2021 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/images/args.gni")
import("//build/zircon/tools.gni")
import("//build/zircon/zx_host_tool.gni")
# We only calculate filesystem sizes for non-bootfs-only builds.
assert(!bootfs_only)
assert(!use_bazel_images_only)
labels = {
images = "//build/images/fuchsia"
}
files = {
outdir = get_label_info(labels.images, "target_out_dir") + "/fuchsia"
gendir = "${outdir}/gen"
zbi = "${outdir}/fuchsia.zbi"
blobfs = "${outdir}/blob.blk"
fvm_sparse = "${outdir}/fvm.sparse.blk"
blobs_json = "${gendir}/blobs.json"
extracted_zbi_json = "$target_out_dir/fuchsia.zbi.json"
extracted_zbi_bootfs_dir = "$target_out_dir/fuchsia.zbi/bootfs"
}
# ZBI tool JSON output doesn't record paths of input files so there's no easy
# way to find out where each of the binaries in bootfs entry came from. Rather,
# we extract the ZBI and then pass this directory as an input to the elfinfo.py
# script which computes the ELF sizes.
#
# TODO(phosek): Try to come up with a more efficient solution that does not
# require extract the ZBI.
zx_host_tool_action("extract_bootfs") {
hermetic_deps = false
visibility = [ ":elf_sizes.json" ]
testonly = true
tool = "//zircon/tools/zbi"
inputs = [ files.zbi ]
outputs = [ files.extracted_zbi_json ]
deps = [ labels.images ]
args = [
"--extract",
"--output-dir=" +
rebase_path(files.extracted_zbi_bootfs_dir, root_build_dir),
"--json-output=" + rebase_path(files.extracted_zbi_json, root_build_dir),
rebase_path(files.zbi, root_out_dir),
]
}
action("elf_sizes.json") {
testonly = true
hermetic_deps = false
script = "//build/images/elfinfo.py"
deps = [
":extract_bootfs",
labels.images,
]
sources = [
files.blobs_json,
files.extracted_zbi_json,
]
_output = "${target_out_dir}/${target_name}"
outputs = [ _output ]
args = [
"--sizes",
rebase_path(_output, root_build_dir),
"--blobs",
rebase_path(files.blobs_json, root_build_dir),
"--zbi",
rebase_path(files.extracted_zbi_json, root_build_dir),
"--bootfs-dir",
rebase_path(files.extracted_zbi_bootfs_dir, root_build_dir),
]
metadata = {
images = [
{
name = "elf_sizes.json"
label = get_label_info(":elf_sizes.json", "label_with_toolchain")
type = "manifest"
path = rebase_path(_output, root_build_dir)
},
]
}
}