blob: 1eb613c8617550c66397bec149e7a6207deb50dc [file] [log] [blame] [edit]
#!/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
fx-error "No prebuilt dart found in ${PREBUILT_DART_DIR}."
exit 1
fi
DEV_FINDER="${FUCHSIA_BUILD_DIR}/host-tools/device-finder"
if [[ ! -x "$DEV_FINDER" ]]; then
fx-error "Cannot find Fuchsia device finder in ${DEV_FINDER}."
fx-error "Run 'fx build' to build host tools."
exit 1
fi
FUCHSIA_ATTACH_BIN="${FUCHSIA_BUILD_DIR}/host_x64/dart-tools/fuchsia_attach"
if [[ ! -x "$FUCHSIA_ATTACH_BIN" ]]; then
fx-error "No fuchsia_attach tool in ${FUCHSIA_ATTACH_BIN}."
fx-error "Make sure it is in your 'fx set' config and run 'fx build' to build it."
exit 1
fi
# 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[@]}"