blob: 71e8645fe09390cab920e7b1cca5c76487209967 [file] [log] [blame]
#!/bin/bash
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
set -ux
run() {
echo ">> $@"
local OUTPUT
OUTPUT=$("$@" 2>&1)
if [[ "$?" -eq 0 ]]; then
echo ">> OK"
else
echo ">> FAILED"
echo "${OUTPUT}"
exit 1
fi
}
check_environment() {
# Check that the JIRI_ROOT environment variable is set.
if [[ -z "${JIRI_ROOT}" ]]; then
echo "The JIRI_ROOT environment variable is not set."
echo "Set the environment variable and re-run."
exit 1
fi
# Check that the JIRI_ROOT environment variable does not contain space.
local -r PATTERN="[ ']"
if [[ "${JIRI_ROOT}" =~ "${PATTERN}" ]]; then
echo "The JIRI_ROOT environment variable cannot contain space."
echo "NOTE: This limitation is inherited from Autotools."
exit 1
fi
# Check that the JIRI_ROOT path does not exist.
if [[ -e "${JIRI_ROOT}" ]]; then
echo "The ${JIRI_ROOT} path already exists."
echo "Remove it or choose a different path and re-run."
exit 1
fi
# Check that the "jiri" command is not in the PATH already.
local -r JIRI_CMD=$(which jiri)
if [[ -n "${JIRI_CMD}" ]]; then
echo "Your PATH already contains \"jiri\" command: ${JIRI_CMD}"
echo "Remove it from the PATH and re-run."
exit 1
fi
# Check that Go compiler version 1.4 or newer exists on the host.
local -r GO_VERSION=$(go version 2> /dev/null)
local -r RESULT="$?"
local -a TOKENS=(${GO_VERSION})
TOKENS=($(echo "${TOKENS[2]}" | tr '.' ' '))
if [[ "${RESULT}" -ne 0 ]] || [[ "${TOKENS[0]}" = "go1" && "${TOKENS[1]}" -lt 4 ]]; then
echo "Go compiler version 1.4 or newer is required for vanadium installation."
echo "Install it and re-run."
exit 1
fi
# Check that git exists on the host.
local -r GIT_VERSION=$(git version 2> /dev/null)
if [[ "$?" -ne 0 ]]; then
echo "The 'git' command does not exist in your PATH."
echo "Add it to the PATH and re-run."
exit 1
fi
}
main() {
check_environment
trap "rm -rf ${JIRI_ROOT}" INT TERM EXIT
# Create initial directories.
run mkdir -p "${JIRI_ROOT}/devtools/bin"
# Clone the manifest repository.
run git clone https://mojo.googlesource.com/mojo-manifest "${JIRI_ROOT}/.manifest"
# Get and install the jiri tool.
GOPATH="${JIRI_ROOT}/tmp" run go get -d github.com/vanadium/go.jiri
GOPATH="${JIRI_ROOT}/tmp" run go build -o "${JIRI_ROOT}/devtools/bin/jiri" github.com/vanadium/go.jiri
rm -rf "${JIRI_ROOT}/tmp"
pushd .
cd "${JIRI_ROOT}"
# Install all vanadium repositories and tools.
local -r NATTEMPTS=3
for attempt in $(seq 1 "${NATTEMPTS}"); do
"${JIRI_ROOT}/devtools/bin/jiri" update && break
if [[ "${attempt}" == "${NATTEMPTS}" ]]; then
echo "\"jiri update\" failed ${NATTEMPTS} times in a row."
echo "This can happen when our repository servers are"
echo "temporarily unavailable. Please try again later."
exit 1
fi
echo "\"jiri update\" failed, trying again."
done
echo "Please add ${JIRI_ROOT}/devtools/bin and ${JIRI_ROOT}/depot_tools to your PATH."
popd
trap - EXIT
}
main "$@"