blob: 84700bdf0510ba0934c642e29fd2dd3392431c1c [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/images/filesystem_limits.gni")
import("//build/images/fvm.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)
labels = {
images = "//build/images/fuchsia"
}
files = {
outdir = get_label_info(labels.images, "target_out_dir") + "/fuchsia"
gendir = "${outdir}/gen"
zbi = "${outdir}/fuchsia.zbi"
minfs = "${outdir}/data.blk"
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,
]
outputs = [ "$root_build_dir/$target_name" ]
args = [
"--sizes",
rebase_path(outputs[0], 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),
]
}