| #!/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. |
| # |
| # Usage: |
| # build_and_run_example.sh <name_of_dir_in_examples> |
| # |
| # Requirements: |
| # 1. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout directory. |
| # 2. You are currently running Workstation (`ffx emu start --headless workstation_eng.qemu-x64`). |
| # 3. The example folder must contain a package target named `<example>_pkg`. |
| # |
| # TODO(akbiggs): Port this workflow to Bazel. |
| |
| set -e # Fail on any error. |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/echo_helpers.sh || exit $? |
| |
| far_debug_dir=/tmp/"${app_name}"_far_contents |
| far_tool="${FUCHSIA_EMBEDDER_DIR}"/bazel-flutter-embedder/external/fuchsia_sdk/tools/x64/far |
| |
| # Parse arguments. |
| headless=0 |
| app_name="hello_flutter" |
| while [[ $# -gt 0 ]]; do |
| case $1 in |
| --headless) |
| echo-warning "--headless apps will not work yet because there's no collection to run JIT components in." |
| headless=1 |
| shift # past argument |
| ;; |
| *) |
| app_name="$1" |
| shift # past value |
| ;; |
| esac |
| done |
| |
| session_args="-- --session" |
| release_args= |
| if [[ "${headless}" -ne 0 ]] |
| then |
| session_args= |
| release_args="--release" |
| fi |
| |
| pushd "${FUCHSIA_EMBEDDER_DIR}" |
| |
| echo-info "Building Flutter sample app bundle." |
| cd "${FUCHSIA_EMBEDDER_DIR}"/src/examples/"${app_name}" |
| "${FUCHSIA_EMBEDDER_DIR}"/tools/flutter build bundle |
| |
| echo-info "Running Flutter sample app." |
| cd "${FUCHSIA_EMBEDDER_DIR}" |
| "${FUCHSIA_EMBEDDER_DIR}"/tools/bazel run --config=fuchsia_x64 //src/examples/"${app_name}":"${app_name}"_pkg.component ${session_args} |
| |
| echo-info "Package contents for debugging:" |
| "${far_tool}" extract --archive="${FUCHSIA_EMBEDDER_DIR}"/bazel-bin/src/examples/"${app_name}"/"${app_name}".far --output="${far_debug_dir}" |
| "${far_tool}" extract --archive="${far_debug_dir}"/meta.far --output="${far_debug_dir}" |
| cat "${far_debug_dir}"/meta/contents |
| rm -r "${far_debug_dir}" |
| |
| popd |