| #!/bin/bash |
| # Copyright 2020 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=Other |
| ### execute ffx - developer tools for fuchsia devices. |
| ## See fx ffx help for more information. |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/vars.sh || exit $? |
| fx-config-read |
| |
| # Parse arguments to find the subcommand, skipping global flags |
| subcommand="" |
| skip_next=false |
| for arg in "$@"; do |
| if $skip_next; then |
| skip_next=false |
| continue |
| fi |
| case "$arg" in |
| -c|--config|-e|--env|--env-root|--machine|--stamp|-t|--target|--timeout|-l|--log-level|--isolate-dir|-o|--log-output) |
| skip_next=true |
| ;; |
| --schema|-v|--verbose|--no-environment|--strict|-d|--direct) |
| ;; |
| -*) |
| ;; |
| *) |
| subcommand="$arg" |
| break |
| ;; |
| esac |
| done |
| |
| if [[ -n "$subcommand" ]]; then |
| toolname="ffx-$subcommand" |
| |
| # 1. Check if the tool already exists on disk to avoid latency |
| if [[ ! -f "${FUCHSIA_BUILD_DIR}/host-tools/${toolname}" ]]; then |
| # 2. Fast check if it's a known external tool in ffx_tools.json. |
| # This avoids calling list-build-artifacts for built-in commands. |
| if [[ -f "${FUCHSIA_BUILD_DIR}/ffx_tools.json" ]] && grep -q "\"name\": \"${toolname}\"" "${FUCHSIA_BUILD_DIR}/ffx_tools.json"; then |
| # 3. Only run list-build-artifacts if it's a known tool |
| if fx-command-run list-build-artifacts --name "${toolname}" tools >/dev/null 2>&1; then |
| echo "Building required subtool '${toolname}'..." 1>&2 |
| # 4. Do not suppress stderr so build failures are visible. |
| # NOTE: We hardcode 'host-tools/' here instead of using the path |
| # returned by list-build-artifacts (which might be 'host_x64/') |
| # because we need to trigger the install step that places the tool |
| # in 'host-tools/' where ffx expects it according to ffx_tools.json. |
| fx-command-run build "host-tools/${toolname}" >/dev/null |
| fi |
| fi |
| fi |
| fi |
| |
| fx-command-exec host-tool ffx "$@" |