blob: 42708169151d385c48a1e67e255d64af36ef8dc6 [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.
#
# Prerequisites:
# 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`).
#
# TODO(akbiggs): Port this workflow to Bazel.
set -e # Exit if any program returns an error.
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 "--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
function is-stderr-tty {
[[ -t 2 ]]
}
# echo-info prints a line to stderr with a green INFO: prefix.
function echo-info {
if is-stderr-tty; then
echo -e >&2 "\033[1;32mINFO:\033[0m $*"
else
echo -e >&2 "INFO: $*"
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