| #!/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. |
| |
| set -e |
| |
| readonly REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/.. |
| |
| help() { |
| echo |
| echo "Checks that your repository is in a valid state and has downloaded the sdk prebuilts." |
| echo |
| echo "Usage:" |
| echo " $(basename "$0") [<options>]" |
| echo |
| echo "Options:" |
| echo |
| echo " -o <output_base>" |
| echo " This is a bazel parameter. More about it can be found in" |
| echo " https://docs.bazel.build/versions/main/command-line-reference.html#flag--output_base" |
| echo |
| } |
| |
| run_bootstrap_script() { |
| echo "Updating the bazel binary at tools/bazel" |
| scripts/bootstrap.sh > /dev/null |
| } |
| |
| ffx_sdk_version() { |
| local sdk_version=$(tools/ffx sdk version) |
| echo "${sdk_version}" |
| } |
| |
| verify_submodules_updated() { |
| git submodule status | while read -r repo; do |
| if [[ "$repo" =~ ^\+ ]]; then |
| echo "Your git submodules are not updated. To fix this run 'git submodule update'" |
| exit 1 |
| fi |
| done |
| } |
| |
| download_sdk_toolchain() { |
| echo "Updating the Fuchsia SDK and clang toolchains." |
| tools/bazel build @fuchsia_sdk//:fuchsia_toolchain_sdk 2> /dev/null |
| # TODO: explicitly fetch the clang toolchain. Might require having a dummy target |
| } |
| |
| download_product_bundle_if_needed() { |
| #TODO: allow the user to specify a product name |
| |
| local sdk_version=$(ffx_sdk_version) |
| local url="gs://fuchsia/development/${sdk_version}/sdk/product_bundles.json#workstation_eng.qemu-x64" |
| |
| # Check to see if we have the product-bundle already because calling the command twice will |
| # always download the bundle again. |
| while read -r pb; do ( ( |
| # This is a bit of a hacky solution based on what we can get back from product-bundle get |
| # We want to check to see if they line matches the exact url and optionally end with |
| # a '*' which indicates if the product bundle is downloaded already. We want to make sure |
| # to avoid matching somelike like 'foo' when 'foo2' exists instead. |
| if [[ "$pb" =~ ^$url\*?$ ]]; then |
| if [[ "$pb" =~ $url\*$ ]]; then |
| echo "Product bundle already exists, skipping download" |
| else |
| echo "Fetching product bundle: $url" |
| echo "This may take a few minutes" |
| # TODO: allow user to specity repository here. |
| tools/ffx product-bundle get "${url}" --repository workstation-repo |
| # add an extra echo becauase pb get doesn't |
| echo |
| |
| fi |
| fi |
| ) ); done < <(tools/ffx product-bundle list) |
| } |
| |
| assert_expected_sdk_version() { |
| local expected_sdk_version=$(third_party/sdk-integration/scripts/sdk_version.sh) |
| local actual_sdk_version=$(ffx_sdk_version) |
| |
| if [[ "${expected_sdk_version}" != "${actual_sdk_version}" ]]; then |
| echo "ERROR: expected sdk version does not match actual SDK version." |
| exit 1 |
| fi |
| } |
| |
| |
| main() { |
| cd "${REPO_ROOT}" |
| |
| while getopts ":ho:" opt; do |
| case ${opt} in |
| 'h' | '?') |
| help |
| exit 1 |
| ;; |
| 'o') OUTPUT_BASE=$OPTARG ;; |
| esac |
| done |
| |
| # Checking that our submodules are up-to-date is done first so we can ensure |
| # that the user has the newest version of the sdk-integration repo |
| verify_submodules_updated |
| |
| # Download everything |
| run_bootstrap_script |
| download_sdk_toolchain |
| download_product_bundle_if_needed |
| assert_expected_sdk_version |
| |
| echo "New SDK version: $(ffx_sdk_version)" |
| echo "All Set!" |
| } |
| |
| main "$@" |