blob: 2b9b4983978e500b5a0a25c70967c69bd028177e [file] [log] [blame]
#!/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
set -e # Fail on any error.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
ensure-embedder-dir
# bootstrap_bazel.sh fails quietly if run outside the Bazel workspace.
pushd $FUCHSIA_EMBEDDER_DIR
echo-info "Initializing submodules..."
git 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 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..."
$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 "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
popd # $FUCHSIA_EMBEDDER_DIR
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"