| #!/bin/bash | |
| # 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. | |
| #### CATEGORY=Other | |
| ### Convenience wrapper for running the product size checker. | |
| ## usage: fx size-check [--assembly-manifest <assembly-manifest-file>] | |
| ## [--base-assembly-manifest <assembly-manifest-file>] | |
| ## [--visualization-dir <output-directory>] | |
| ## | |
| ## Convenience wrapper for running the product size checker. | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $? | |
| fx-config-read | |
| readonly ASSEMBLY_MANIFESTS_JSON="assembly_manifests.json" | |
| function _query_manifest { | |
| local manifest="$1" | |
| local jq_filter="$2" | |
| local paths=($(fx-command-run jq --raw-output "${jq_filter}" "${FUCHSIA_BUILD_DIR}/${manifest}")) | |
| # At most one path is supported. | |
| if [[ ${#paths[@]} -gt 1 ]]; then | |
| fx-error "More than one 'fuchsia' assembly manifest found in ${FUCHSIA_BUILD_DIR}/${manifest}!" | |
| exit 1 | |
| fi | |
| printf %s "${paths[0]}" | |
| } | |
| # Find the assembly manifest for the "fuchsia" product (the main one). | |
| manifest_query=$(_query_manifest "${ASSEMBLY_MANIFESTS_JSON}" '.[] | select(.image_name == "fuchsia") | .assembly_manifest_path') | |
| if [[ -z "${manifest_query}" ]]; then | |
| exit 1 | |
| fi | |
| assembly_manifest="$FUCHSIA_BUILD_DIR/$manifest_query" | |
| visualization_dir="$FUCHSIA_BUILD_DIR/size_visualization" | |
| flags="" | |
| # Flag parsing. | |
| while [[ "$1" =~ ^- ]]; do | |
| case "$1" in | |
| --assembly-manifest) | |
| shift | |
| assembly_manifest="$1" | |
| ;; | |
| --base-assembly-manifest) | |
| shift | |
| flags="${flags} --base-assembly-manifest $1" | |
| ;; | |
| --visualization-dir) | |
| shift | |
| visualization_dir="$1" | |
| ;; | |
| *) | |
| echo Bad option "$1" | |
| echo | |
| fx-command-help | |
| exit 1 | |
| esac | |
| shift | |
| done | |
| ffx --config assembly_enabled=true assembly size-check product \ | |
| --assembly-manifest $assembly_manifest \ | |
| --visualization-dir $visualization_dir \ | |
| --verbose $flags |