| #!/bin/bash | |
| # Copyright 2024 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=Build | |
| ### get the output path to the provided product bundle | |
| ## usage: fx get-main-pb-path //products/minimal:product_bundle.x64 | |
| readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" | |
| source "$SCRIPT_DIR/../lib/vars.sh" || exit $? | |
| fx-config-read | |
| if [[ ! -d "${FUCHSIA_BUILD_DIR}" ]]; then | |
| fx-error "Build directory ${FUCHSIA_BUILD_DIR} does not exist, run \"fx set\" first." | |
| exit 1 | |
| fi | |
| product_bundles_path="$FUCHSIA_BUILD_DIR/product_bundles.json" | |
| args_json_path="${FUCHSIA_BUILD_DIR}/args.json" | |
| main_pb_label="" | |
| product_bundle="" | |
| set -e | |
| # If an argument was provided, assume that it is the label for the main PB. | |
| if [[ $# -eq 1 ]]; then | |
| main_pb_label="$1" | |
| # Otherwise, look for main_pb_label in the args.json. | |
| else | |
| main_pb_label="$(fx-command-run jq -r ".main_pb_label // empty" "$FUCHSIA_BUILD_DIR/args.json")" | |
| fi | |
| # Find the product bundle that is built from main_pb_label. | |
| if [[ -n $main_pb_label ]]; then | |
| jq_filter=".[] | select(.label | startswith(\"${main_pb_label}\")) | .path" | |
| product_bundle=$(fx-command-run jq -r "${jq_filter}" ${product_bundles_path}) | |
| # If we didn't find a main_pb_label, look in product_bundles.json for a product | |
| # bundle named build_info_product.build_info_board. | |
| else | |
| product=$(fx-command-run jq ".build_info_product" ${args_json_path}) | |
| board=$(fx-command-run jq ".build_info_board" ${args_json_path}) | |
| product_name="${product//\"}.${board//\"}" | |
| jq_filter=".[] | select(.name == \"${product_name}\") | .path" | |
| product_bundle=$(fx-command-run jq -r "${jq_filter}" ${product_bundles_path}) | |
| fi | |
| if [[ -z $product_bundle ]]; then | |
| echo "No matching product found!" | |
| exit 1 | |
| fi | |
| echo $product_bundle |