blob: 17b7f85812000529b332293d12e4cd926e715c8b [file] [log] [blame]
#!/bin/bash
# Copyright 2023 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
### Create pb.zip based on product_bundles.json file. The created zip file will
## default to ${pwd}/pb.zip
## usage: fx create-pb-zip [-o <output>]
## -o Output location of built zip file
set -o errexit
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh
fx-config-read
main() {
local output="$(pwd)"
while [[ $# -ge 1 ]]; do
case "$1" in
-o)
shift
output="$1"
;;
esac
shift
done
if [[ -d $output ]]; then
output="${output}/pb.zip"
fi
local product_bundles_path="${FUCHSIA_BUILD_DIR}/product_bundles.json"
# Determine the name of main product
local args_json_path="${FUCHSIA_BUILD_DIR}/args.json"
local product=$(fx-command-run jq .build_info_product ${args_json_path})
local board=$(fx-command-run jq .build_info_board ${args_json_path})
local product_name="\"${product//\"}.${board//\"}\""
local product_bundle_path=$(fx-command-run jq ".[] | select(.name==${product_name}) | .path" ${product_bundles_path})
fx-info "Start creating ${output} ..."
(
cd "${FUCHSIA_BUILD_DIR}/${product_bundle_path//\"}/.."
local tmpfile_path="${FUCHSIA_BUILD_DIR}/tmp-pb-zip-$$"
fx-command-run ffx product get-artifacts product_bundle -r -g flash > "$tmpfile_path"
echo "product_bundle.json" >> "$tmpfile_path"
sed -i -e 's/^/product_bundle\//' "$tmpfile_path"
zip pb.zip -@ < "$tmpfile_path"
rm -rf "$tmpfile_path"
if [[ $output != "$(pwd)/pb.zip" ]]; then
mv -f pb.zip "${output}"
fi
)
fx-info "Done! Output: ${output}"
}
main "$@"