-
Notifications
You must be signed in to change notification settings - Fork 717
/
install-package-dependencies.sh
executable file
·130 lines (102 loc) · 3.72 KB
/
install-package-dependencies.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
set -e
usage()
{
echo "Usage: install-package-dependencies.sh --verilator-version V"
echo " --verible-version V"
exit 1
}
error()
{
echo >&2 "$@"
exit 1
}
long="verilator-version:,verible-version:"
ARGS="$(getopt -o "" -l "$long" -- "$@")" || usage
VERILATOR_VERSION=
VERIBLE_VERSION=
eval set -- "$ARGS"
while :
do
case "$1" in
--verilator-version) VERILATOR_VERSION="$2"; shift 2 ;;
--verible-version) VERIBLE_VERSION="$2"; shift 2 ;;
--) shift; break ;;
*) error "getopt / case statement mismatch"
esac
done
# Check that we've seen all the expected versions
test -n "$VERILATOR_VERSION" || error "Missing --verilator-version"
test -n "$VERIBLE_VERSION" || error "Missing --verible-version"
# Check that there aren't any positional arguments
test $# = 0 || error "Unexpected positional arguments"
CI_DIR="$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")"
REPO_TOP="$(readlink -e "$CI_DIR/..")"
cd "$REPO_TOP"
# Use apt-fast if available for faster installation.
if command -v apt-fast >/dev/null; then
APT_CMD=apt-fast
else
APT_CMD=apt-get
fi
TMPDIR="$(mktemp -d)" || {
error "Failed to create temporary directory"
}
trap 'rm -rf "$TMPDIR"' EXIT
# Install gcc-9 and set it as the default.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test \
&& sudo $APT_CMD update \
&& sudo $APT_CMD install -y gcc-9 g++-9 \
&& sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 \
&& sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90 || {
error "Failed to set up gcc-9"
}
# Ensure apt package index is up-to-date.
sudo $APT_CMD update || {
error "Failed to run apt update"
}
ci_reqs="$TMPDIR/apt-requirements-ci.txt"
cp apt-requirements.txt "$ci_reqs"
echo rsync >> "$ci_reqs"
# NOTE: We use sed to remove all comments from apt-requirements-ci.txt,
# since apt-get/apt-fast doesn't actually provide such a feature.
sed -i -e '/^$/d' -e '/^#/d' -e 's/#.*//' "$ci_reqs"
echo "Amended apt-requirements:"
cat "$ci_reqs"
xargs sudo $APT_CMD install -y <"$ci_reqs"
# Python requirements are installed to the local user directory so prepend
# appropriate bin directory to the PATH
export PATH=$HOME/.local/bin:$PATH
python3 -m pip install --user -r python-requirements.txt --require-hashes
# Install Verible
lsb_sr="$(lsb_release -sr)"
VERIBLE_BASE_URL="https://github.com/chipsalliance/verible/releases/download"
VERIBLE_TARBALL="verible-${VERIBLE_VERSION}-linux-static-x86_64.tar.gz"
VERIBLE_URL="${VERIBLE_BASE_URL}/${VERIBLE_VERSION}/${VERIBLE_TARBALL}"
verible_tar="$TMPDIR/verible.tar.gz"
curl -f -Ls -o "$verible_tar" "${VERIBLE_URL}" || {
error "Failed to download verible from ${VERIBLE_URL}"
}
sudo mkdir -p /tools/verible
sudo chmod 777 /tools/verible
tar -C /tools/verible -xf "$verible_tar" --strip-components=1
export PATH=/tools/verible/bin:$PATH
# Install verilator
if [ $lsb_sr = "18.04" ]; then
UBUNTU_SUFFIX="-u18"
fi
VERILATOR_TARBALL=verilator"$UBUNTU_SUFFIX-v$VERILATOR_VERSION".tar.gz
VERILATOR_URL=https://storage.googleapis.com/verilator-builds/$VERILATOR_TARBALL
echo "Fetching verilator tarball" $VERILATOR_URL
curl -f -Ls -o "$VERILATOR_TARBALL" "$VERILATOR_URL" || {
error "Failed to download verilator from ${VERILATOR_URL}"
}
sudo mkdir -p /tools/verilator
sudo chmod 777 /tools/verilator
tar -C /tools/verilator -xvzf $VERILATOR_TARBALL
export PATH=/tools/verilator/v$VERILATOR_VERSION/bin:$PATH
# Propagate PATH changes to all subsequent steps of the job
echo "##vso[task.setvariable variable=PATH]$PATH"