blob: 8bd2dfec2015210b317907788387c76eccd772e7 [file] [log] [blame]
#!/bin/bash
# Copyright 2018 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.
#### CATEGORY=Run, inspect and debug
### attach to a running flutter module to enable hot reload and debugging
## usage: fx flutter-attach //topaz/examples/hello_world:hello_world
##
## This command requires Topaz in order to run.
##
## Arguments:
## -v|--verbose Enable verbose logging.
## -h|--help Print out this message.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $?
fx-config-read
ARGS=()
NAME="$(get-device-name)"
if [[ -n "$name" ]]; then
ARGS+=("--device", "${name}")
fi
for var in "$@"
do
case "$var" in
-h|--help)
fx-command-help
exit 0
;;
-v|--verbose)
ARGS+=("--verbose")
;;
*)
TARGET="$var"
;;
esac
done
PREBUILT_DART="${PREBUILT_DART_DIR}/bin/dart"
if [[ ! -x "$PREBUILT_DART" ]]; then
echo >&2 "No prebuilt dart found in ${PREBUILT_DART_DIR}"
exit 1
fi
DEV_FINDER="${HOST_OUT_DIR}/dev_finder"
FUCHSIA_ATTACH_BIN="${FUCHSIA_BUILD_DIR}/host_x64/dart-tools/fuchsia_attach"
# The flutter tool expects the working directory is the fuchsia root.
cd "${FUCHSIA_DIR}"
"${FUCHSIA_ATTACH_BIN}" \
"--dart-sdk=${PREBUILT_DART}" \
"--build-dir=${FUCHSIA_BUILD_DIR}"\
"--target=${TARGET}" \
"--dev-finder=${DEV_FINDER}" \
"${ARGS[@]}"