| # Copyright 2022 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/bazel/bazel_inputs.gni") |
| import("//build/board.gni") |
| import("//build/compiled_action.gni") |
| import("//build/images/args.gni") |
| import("//build/images/filesystem_limits.gni") |
| import("//build/images/size_checker/size_checker_input.gni") |
| import("//build/python/python_action.gni") |
| import("//build/tools/json_merge/json_merge.gni") |
| import("//src/developer/ffx/build/ffx_action.gni") |
| |
| assert(!bootfs_only) |
| |
| if (!use_bazel_images_only) { |
| _assembly_manifest = |
| "$root_build_dir/obj/build/images/fuchsia/fuchsia/images.json" |
| |
| ffx_action("run_product_size_checker") { |
| inputs = [ _assembly_manifest ] |
| outputs = [ |
| "$target_out_dir/size_breakdown.txt", |
| "$target_out_dir/visualization/data.js", |
| "$target_out_dir/visualization/index.html", |
| "$target_out_dir/visualization/D3BlobTreeMap.js", |
| "$target_out_dir/visualization/d3_v3/LICENSE", |
| "$target_out_dir/visualization/d3_v3/d3.js", |
| ] |
| testonly = true |
| ffx_tool = "//src/developer/ffx/plugins/assembly:ffx_assembly_tool" |
| ffx_tool_output_name = "ffx-assembly" |
| args = [ |
| "--config", |
| "assembly_enabled=true", |
| "assembly", |
| "size-check", |
| "product", |
| "--assembly-manifest", |
| rebase_path(_assembly_manifest, root_build_dir), |
| "--visualization-dir", |
| rebase_path("$target_out_dir/visualization", root_build_dir), |
| "--size-breakdown-output", |
| rebase_path("$target_out_dir/size_breakdown.txt", root_build_dir), |
| ] |
| |
| # Only create gerrit size report if necessary. |
| if (size_checker_input != { |
| }) { |
| args += [ |
| "--gerrit-output", |
| rebase_path("$target_out_dir/size_report_product.json", root_build_dir), |
| "--blobfs-creep-budget", |
| "$blobfs_size_creep_limit", |
| "--platform-resources-budget", |
| "6657271", |
| ] |
| outputs += [ "$target_out_dir/size_report_product.json" ] |
| } |
| deps = [ "//build/images/fuchsia:fuchsia.image_assembler" ] |
| metadata = { |
| product_size_checker_output = [ |
| { |
| visualization = |
| rebase_path("$target_out_dir/visualization", root_build_dir) |
| size_breakdown = |
| rebase_path("$target_out_dir/size_breakdown.txt", root_build_dir) |
| }, |
| ] |
| } |
| } |
| } |
| |
| if (size_checker_input != { |
| }) { |
| generated_file("size_checker_json") { |
| outputs = [ "$root_build_dir/size_checker.json" ] |
| contents = size_checker_input |
| output_conversion = "json" |
| } |
| |
| bazel_input_resource("size_checker_json_bazel_input") { |
| sources = [ "${root_build_dir}/size_checker.json" ] |
| outputs = [ "size_checker.json" ] |
| deps = [ ":size_checker_json" ] |
| } |
| } |
| |
| if (!use_bazel_images_only && blobfs_capacity != false && |
| max_blob_contents_size != false && |
| size_checker_input != { |
| }) { |
| _output_dir = |
| get_label_info(":convert_size_limits_to_size_budgets", "target_out_dir") |
| _size_budgets_blobfs_file = "${_output_dir}/size_budgets.json" |
| _blobs_config = "${_output_dir}/../fuchsia/fuchsia/gen/blobs.json" |
| _image_assembly_config = |
| "${_output_dir}/../fuchsia/fuchsia/image_assembly.json" |
| |
| action("convert_size_limits_to_size_budgets") { |
| script = "//build/bazel_sdk/bazel_rules_fuchsia/fuchsia/tools/convert_size_limits.py" |
| inputs = [ |
| "$root_build_dir/size_checker.json", |
| _image_assembly_config, |
| ] |
| outputs = [ _size_budgets_blobfs_file ] |
| deps = [ |
| ":size_checker_json", |
| "//build/images/fuchsia:fuchsia.product_assembler", |
| ] |
| testonly = true |
| args = [ |
| "--size-limits", |
| rebase_path("$root_build_dir/size_checker.json", root_build_dir), |
| "--image-assembly-config", |
| rebase_path(_image_assembly_config, root_build_dir), |
| "--output", |
| rebase_path(_size_budgets_blobfs_file, root_build_dir), |
| "--max-blob-contents-size", |
| "$max_blob_contents_size", |
| ] |
| |
| metadata = { |
| detailed_size_checker_data = [ |
| { |
| name = "size_budgets" |
| path = rebase_path(_size_budgets_blobfs_file, root_build_dir) |
| }, |
| ] |
| } |
| } |
| |
| # Path to a generated file enumerating runtime dependencies of the |
| # size budget verification tool. |
| _blobfs_hermetic_inputs = "${_output_dir}/verify_size_budget_blobfs.hi" |
| _blobfs_hermetic_inputs_target = |
| "create_verify_size_budget_blobfs_hermetic_inputs" |
| |
| python_hermetic_inputs_action(_blobfs_hermetic_inputs_target) { |
| binary_label = "//build/assembly/scripts:check_size_hermetic_inputs" |
| inputs = [ _size_budgets_blobfs_file ] |
| outputs = [ _blobfs_hermetic_inputs ] |
| deps = [ ":convert_size_limits_to_size_budgets" ] |
| testonly = true |
| args = [ |
| "--with-package-content", |
| "--budgets", |
| rebase_path(_size_budgets_blobfs_file, root_build_dir), |
| "--output", |
| rebase_path(_blobfs_hermetic_inputs, root_build_dir), |
| ] |
| } |
| |
| ffx_action("verify_size_budget_blobfs") { |
| deps = [ |
| ":convert_size_limits_to_size_budgets", |
| "//build/images/fuchsia:fuchsia_assembly", |
| ] |
| hermetic_inputs_target = ":${_blobfs_hermetic_inputs_target}" |
| hermetic_inputs_file = _blobfs_hermetic_inputs |
| inputs = [ |
| _size_budgets_blobfs_file, |
| _blobs_config, |
| ] |
| outputs = [ |
| "$target_out_dir/size_report_blobfs.json", |
| "$target_out_dir/verbose_output.json", |
| ] |
| testonly = true |
| ffx_tool = "//src/developer/ffx/plugins/assembly:ffx_assembly_tool" |
| ffx_tool_output_name = "ffx-assembly" |
| args = [ |
| "--config", |
| "assembly_enabled=true", |
| "assembly", |
| "size-check", |
| "package", |
| "--budgets", |
| rebase_path(_size_budgets_blobfs_file, root_build_dir), |
| "--blob-sizes", |
| rebase_path(_blobs_config, root_build_dir), |
| "--blobfs-layout", |
| "deprecated_padded", |
| "--gerrit-output", |
| rebase_path("$target_out_dir/size_report_blobfs.json", root_build_dir), |
| "--verbose-json-output", |
| rebase_path("$target_out_dir/verbose_output.json", root_build_dir), |
| ] |
| } |
| |
| json_merge("size_report.json") { |
| sources = [ |
| "$target_out_dir/size_report_blobfs.json", |
| "$target_out_dir/size_report_product.json", |
| ] |
| testonly = true |
| deps = [ |
| ":run_product_size_checker", |
| ":verify_size_budget_blobfs", |
| ] |
| metadata = { |
| gerrit_size_reports = |
| [ rebase_path("$target_out_dir/size_report.json", root_build_dir) ] |
| } |
| } |
| } |