| #!/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. | |
| ### 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. | |
| DEVSHELL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| source "${DEVSHELL_DIR}"/lib/vars.sh | |
| 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 | |
| case "$(uname -s)" in | |
| Linux) | |
| PREBUILT_DART="${DEVSHELL_DIR}/../../topaz/tools/prebuilt-dart-sdk/linux-x64/bin/dart" | |
| ;; | |
| Darwin) | |
| PREBUILT_DART="${DEVSHELL_DIR}/../../topaz/tools/prebuilt-dart-sdk/mac-x64/bin/dart" | |
| ;; | |
| esac | |
| if [[ -z "$PREBUILT_DART" ]]; then | |
| >&2 echo "PRREBUILT DART binary not supported on current platform" | |
| exit 1 | |
| fi | |
| 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}" \ | |
| "${ARGS[@]}" |