1#!/usr/bin/env bash
2
3# Copyright 2016 The Fuchsia Authors
4#
5# Use of this source code is governed by a MIT-style
6# license that can be found in the LICENSE file or at
7# https://opensource.org/licenses/MIT
8
9# Use this to use git bisect with prebuilt binary artifacts. To use, first copy the script somewhere
10# outside of the source tree (so git bisect won't mess with it) then run the following commands:
11#   git bisect start <bad> <good>
12#   git bisect run PATH_TO/bisect-helper <optional additional args to run-zircon>
13# The script will download the prebuilt zircon.bin associated with each commit, if it exists, and
14# start it up in qemu. After qemu exits, the script will ask if the build is good or bad.  Type 'y'
15# or 'n' and the bisect will proceed.
16
17set -e
18
19readonly SCRIPT_DIR="$1"
20
21readonly TEMP_DIR="$(mktemp -d)"
22trap "rm -rf -- "${TEMP_DIR}"" EXIT
23readonly CURRENT_COMMIT="$(git rev-parse HEAD)"
24readonly ZIRCON_BIN_URL="https://storage-download.googleapis.com/fuchsia-build/zircon/qemu-arm64/zircon.elf/${CURRENT_COMMIT}"
25readonly DOWNLOAD_STATUS="$(curl -s -w %{http_code} --progress-bar --output "${TEMP_DIR}/zircon.elf" "${ZIRCON_BIN_URL}")"
26if [[ "${DOWNLOAD_STATUS}" != 200 ]]; then
27    echo "Could not find prebuilt at ${ZIRCON_BIN_URL}: ${DOWNLOAD_STATUS}"
28    exit 125  # could not evaluate this commit, no prebuilt available
29fi
30"${SCRIPT_DIR}/run-zircon-arm64" -o "${TEMP_DIR}"
31
32echo "Did it work? y/n"
33read RESULT
34if [[ "${RESULT}" == y ]]; then
35    exit 0
36else
37    exit 1
38fi
39