| #!/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. |
| # |
| # Sets up this repository and all its dependencies. |
| # |
| # Usage: |
| # bootstrap.sh |
| # |
| # Requirements: |
| # 1. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout. |
| |
| set -e # Fail on any error. |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/echo_helpers.sh || exit $? |
| |
| if [[ -z $FUCHSIA_EMBEDDER_DIR ]] |
| then |
| echo-error '$FUCHSIA_EMBEDDER_DIR must be set to your flutter-embedder folder before running this script.' |
| echo-error 'Add this line to your shell profile:' |
| echo-error "export FUCHSIA_EMBEDDER_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && cd .. && pwd)" |
| exit 1 |
| fi |
| |
| echo-info "Initializing submodules..." |
| git -C $FUCHSIA_EMBEDDER_DIR submodule update --recursive --init |
| |
| echo-info "Configuring git to update submodules when pulling changes in this repo..." |
| echo-info "(This is necessary to keep libflutter_engine.so and third_party/dart-pkg/flutter aligned" |
| echo-info "to avoid crashes from Dart SDK incompatibilities)" |
| git -C $FUCHSIA_EMBEDDER_DIR config submodule.recurse true |
| |
| echo-info "Bootstrapping Bazel..." |
| $FUCHSIA_EMBEDDER_DIR/third_party/sdk-integration/bazel_rules_fuchsia/scripts/bootstrap_bazel.sh |
| $FUCHSIA_EMBEDDER_DIR/tools/bazel clean |
| |
| echo-info 'Building the embedder to fetch external dependencies (clang)...' |
| $FUCHSIA_EMBEDDER_DIR/tools/bazel build --config=fuchsia_x64 //src/embedder |
| |
| echo-info "Initializing Fuchsia SSH keys (if not already created)..." |
| [[ -f "${HOME}/.ssh/fuchsia_ed25519" ]] || ssh-keygen -P "" -t ed25519 -f "${HOME}/.ssh/fuchsia_ed25519" -C "${USER}@$(hostname -f) Shared SSH Key for Fuchsia" |
| [[ -f "${HOME}/.ssh/fuchsia_authorized_keys" ]] || ssh-keygen -y -f "${HOME}/.ssh/fuchsia_ed25519" > "${HOME}/.ssh/fuchsia_authorized_keys" |
| |
| echo-info "Installing Git hooks..." |
| $FUCHSIA_EMBEDDER_DIR/scripts/install_hooks.sh |
| |
| # 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-warning "Deleting other product bundles to ensure the new product bundle installs... Sorry..." |
| rm -rf ~/.local/share/Fuchsia/ffx/pbms |
| |
| echo-info "Installing the workstation_eng.qemu-x64 product bundle..." |
| $FUCHSIA_EMBEDDER_DIR/tools/ffx product-bundle get workstation_eng.qemu-x64 |
| echo |
| |
| if [[ -r /dev/kvm ]] && grep '^flags' /proc/cpuinfo | grep -qE 'vmx|svm' |
| then |
| # I'm bad at shell and couldn't figure out how to invert this condition properly. |
| : |
| else |
| echo-warning 'VM acceleration (KVM) is not enabled on your machine. Consider enabling it by following https://fuchsia.dev/fuchsia-src/get-started/set_up_femu?hl=en#enable-vm-acceleration.' |
| echo-warning 'Without KVM enabled, emulator performance will be terrible.' |
| echo-warning 'If you have already enabled KVM, you may need to reboot your machine.' |
| fi |
| |
| echo "Done. You're now ready to run a Flutter on Fuchsia example app:" |
| echo "https://fuchsia.googlesource.com/flutter-embedder#run-an-example-app" |
| |