| #!/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. |
| # |
| # Updates the version of ffx used by this repository to the latest |
| # version. |
| # |
| # Usage: |
| # update_fuchsia_sdk.sh |
| # |
| # Arguments: |
| # --cleanup: Removes old product bundles and shuts down old emulators. |
| # Default: false |
| # --no-version-bump: Does all the cleanup that comes with updating the SDK version without |
| # changing the SDK version. You usually want to pass --cleanup with this. |
| # Default: false |
| |
| set -e # Fail on any error. |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $? |
| |
| ensure-embedder-dir |
| |
| # Parse arguments. |
| cleanup=0 |
| no_version_bump=0 |
| while [[ $# -gt 0 ]]; do |
| case $1 in |
| --cleanup) |
| cleanup=1 |
| shift # past argument |
| ;; |
| --no-version-bump) |
| no_version_bump=1 |
| shift # past argument |
| ;; |
| *) |
| shift # past value |
| ;; |
| esac |
| done |
| |
| if [[ "${no_version_bump}" -eq 0 ]] |
| then |
| echo-info "Updating the Fuchsia SDK checkout..." |
| git -C $FUCHSIA_EMBEDDER_DIR/third_party/sdk-integration pull origin main |
| fi |
| |
| echo-info "Building the embedder to fetch the updated Fuchsia SDK tools..." |
| pushd $FUCHSIA_EMBEDDER_DIR |
| $FUCHSIA_EMBEDDER_DIR/tools/bazel clean |
| $FUCHSIA_EMBEDDER_DIR/tools/bazel build --config=fuchsia_x64 //src/embedder |
| popd |
| |
| if [[ "${cleanup}" -eq 0 ]] |
| then |
| echo-info "flutter-embedder's Fuchsia SDK has been updated to version $($FUCHSIA_EMBEDDER_DIR/tools/ffx version)." |
| echo-warning 'You should restart any running emulators (`$FUCHSIA_EMBEDDER_DIR/tools/ffx emu stop`)' |
| echo-warning 'and update your product bundles (`$FUCHSIA_EMBEDDER_DIR/tools/ffx product-bundle get workstation_eng.qemu-x64`) as' |
| echo-warning 'old images may be incompatible with the updated SDK.' |
| echo-warning 'To do this automatically, run: $FUCHSIA_EMBEDDER_DIR/scripts/update_fuchsia_sdk.sh --cleanup --no-version-bump' |
| exit 0 |
| fi |
| |
| echo-info "Cleaning up old things that are incompatible with the new SDK." |
| echo-info "If you don't want this, don't run the script with --cleanup." |
| |
| echo-info "Killing any running emulators..." |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx emu stop |
| |
| # Installing the product-bundle fails when the user has product bundles |
| # from a previous version of ffx installed, so we clean up old product bundles |
| # here. |
| # TODO(akbiggs): Is there something less invasive we can do here? |
| echo-info "Deleting old product bundles..." |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx product-bundle remove --force |
| # If we don't stop the repository server here, `product-bundle get` |
| # can complain with "A package repository already exists" and fail to |
| # download the new product bundle. |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx repository server stop |
| |
| echo-info "Refetching the workstation_eng.qemu-x64 product bundle..." |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx product-bundle get workstation_eng.qemu-x64 |
| |
| echo |
| echo-info "flutter-embedder's Fuchsia SDK has been updated to version $($FUCHSIA_EMBEDDER_DIR/tools/ffx version)." |
| echo-info "You will need to restart your emulator by running:" |
| echo '$FUCHSIA_EMBEDDER_DIR/tools/ffx emu start workstation_eng.qemu-x64' |
| echo-info "Or if you're running from a non-graphical environment:" |
| echo '$FUCHSIA_EMBEDDER_DIR/tools/ffx emu start workstation_eng.qemu-x64 --headless' |