blob: 892c5b8cd31bf6ea536d9c13c35e7a7c1c631aae [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
### forward local ports to Dart VMs on the device.
## usage: fx dart-tunnel [-h|--help] [-v|--verbose] [<isolate>]
##
## Creates an SSH tunnel with the device's running Dart VM(s) and leaves it open
## until the user chooses to close it. Supplying an Isolate name will attempt to
## connect to all isolates whose name match.
##
## The verbose flag is strongly discouraged unless you are debugging.
##
## This command requires:
## > Ommitting `--release` from `fx set`
## (Observatory isn't available in --release builds).
##
## > "bundles/tools" to be available on the system (for the `find` command).
##
## Arguments:
## -h|--help Print out this message.
VERBOSE=false
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $?
fx-config-read
case $1 in
-h|--help)
fx-command-help
exit 0
;;
-v|--verbose)
shift # name
VERBOSE=true
;;
esac
case "$(uname -s)" in
Linux)
PREBUILT_DART="${FUCHSIA_DIR}/prebuilt/third_party/dart/linux-x64/bin/dart"
;;
Darwin)
PREBUILT_DART="${FUCHSIA_DIR}/prebuilt/third_party/dart/mac-x64/bin/dart"
;;
esac
IP_ADDR_LINK_LOCAL="$(get-fuchsia-device-addr)"
# Strips the back of the string the longest match of '%' followed by
# any characters (the first two '%' characters are just the bash syntax).
IP_ADDR="${IP_ADDR_LINK_LOCAL%%%*}"
# Splits from the front of the string the longest match of any character
# followed by '%'.
IP_IFACE="${IP_ADDR_LINK_LOCAL##*%}"
SSH_CONFIG="${FUCHSIA_BUILD_DIR}/ssh-keys/ssh_config"
# Just compress the rest of the args to an array here.
ARGS="$(echo "$@")"
DART_TUNNEL_LIB_DIR="${FUCHSIA_DIR}/tools/devshell/contrib/dart-tunnel-lib"
DART_TUNNEL_PACKAGES="${DART_TUNNEL_LIB_DIR}/package_config.json"
DART_BIN="${DART_TUNNEL_LIB_DIR}/dart-tunnel.dart"
# Conditionally prints the --verbose flag.
function _verbose_flag() {
if [ "${VERBOSE}" = true ]; then
echo "--verbose"
fi
}
"${PREBUILT_DART}" \
--packages="${DART_TUNNEL_PACKAGES}" \
--enable-experiment=non-nullable \
--no-sound-null-safety \
"${DART_BIN}" \
--ssh-config="${SSH_CONFIG}" \
--ip-address="${IP_ADDR}" \
--network-interface="${IP_IFACE}" \
--isolate="$ARGS" \
"$(_verbose_flag)"