blob: b060068f24d98a2f013cb551a6278815596091c9 [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.
#
# Usage:
# build_and_run_example.sh <name_of_dir_in_examples>
#
# Requirements:
# 1. You are currently running Workstation (`ffx emu start --headless workstation_eng.qemu-x64`).
# 2. The example folder must contain a fuchsia_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/helpers.sh || exit $?
ensure-embedder-dir
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:"
"${FUCHSIA_EMBEDDER_DIR}"/tools/bazel build --config=fuchsia_x64 //src/examples/"${app_name}":"${app_name}"_pkg
"${far_tool}" extract --archive="$(find -L ${FUCHSIA_EMBEDDER_DIR}/bazel-out -name "${app_name}".far | head -n 1)" --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