| #!/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. |
| # |
| # Common helpers specific for Fuchsia in-tree testing. |
| |
| btf::setup_fx() { |
| if [[ -z "${BT_TEMP_DIR}" ]]; then |
| echo "Cannot proceed, BT_TEMP_DIR is unset" 1>&2 |
| exit 1 |
| fi |
| local _HOST_OUT_DIR="host_x64" |
| local _REL_BUILD_DIR="out/default" |
| local _FUCHSIA_DIR="${BT_TEMP_DIR}" |
| local _FUCHSIA_BUILD_DIR="${_FUCHSIA_DIR}/${_REL_BUILD_DIR}" |
| |
| # Fake fuchsia dir configuration. |
| local _FX="${_FUCHSIA_DIR}/scripts/fx" |
| BT_ASSERT_FILE_EXISTS "${_FX}" |
| BT_ASSERT_FILE_EXISTS "${_FUCHSIA_DIR}/tools/devshell/lib/vars.sh" |
| BT_ASSERT_FILE_EXISTS "${_FUCHSIA_DIR}/tools/devshell/lib/prebuilt.sh" |
| |
| # Fake a build directory with the minimal content so that fx work |
| mkdir -p "${_FUCHSIA_BUILD_DIR}" "${_FUCHSIA_BUILD_DIR}/${_HOST_OUT_DIR}" "${_FUCHSIA_DIR}/.jiri_root" |
| echo "${_REL_BUILD_DIR}" > "${_FUCHSIA_DIR}/.fx-build-dir" |
| touch "${_FUCHSIA_BUILD_DIR}/args.gn" |
| cat > "${_FUCHSIA_BUILD_DIR}/fx.config" << EOF |
| # Generated by fuchsia-mock.sh. |
| FUCHSIA_BUILD_DIR='${_REL_BUILD_DIR}' |
| FUCHSIA_ARCH='x64' |
| FUCHSIA_BOARD_NAME=pc |
| FUCHSIA_ZBI_COMPRESSION=zstd |
| HOST_OUT_DIR='${_HOST_OUT_DIR}' |
| EOF |
| btf::make_mock "${_FUCHSIA_DIR}/tools/devshell/lib/metrics.sh" |
| cat > "${_FUCHSIA_DIR}/tools/devshell/lib/metrics.sh.mock_side_effects" <<EOF |
| function track-command-execution { |
| : |
| } |
| function track-command-finished { |
| : |
| } |
| EOF |
| echo "${_FX}" |
| } |
| |
| btf::make_hosttools_mock() { |
| local -r _HOST_OUT_DIR="host_x64" |
| local -r _REL_BUILD_DIR="out/default" |
| local -r _FUCHSIA_DIR="${BT_TEMP_DIR}" |
| local -r _FUCHSIA_BUILD_DIR="${_FUCHSIA_DIR}/${_REL_BUILD_DIR}" |
| |
| local hosttool_name="$1" |
| local hosttool_path="${_FUCHSIA_BUILD_DIR}/${_HOST_OUT_DIR}/${hosttool_name}" |
| btf::make_mock "${hosttool_path}" |
| echo "${hosttool_path}" |
| } |
| |
| btf::make_zircontools_mock() { |
| local -r _ZIRCON_TOOLS_DIR="tools" |
| local -r _REL_BUILD_DIR="out/default.zircon" |
| local -r _FUCHSIA_DIR="${BT_TEMP_DIR}" |
| local -r _ZIRCON_BUILD_DIR="${_FUCHSIA_DIR}/${_REL_BUILD_DIR}" |
| |
| local zircontool_name="$1" |
| local zircontool_path="${_ZIRCON_BUILD_DIR}/${_ZIRCON_TOOLS_DIR}/${zircontool_name}" |
| btf::make_mock "${zircontool_path}" |
| echo "${zircontool_path}" |
| } |
| |