forked from lowRISC/opentitan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-package-dependencies.sh
executable file
·151 lines (119 loc) · 4.74 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
# Copyright lowRISC contributors.
# 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"
echo " --rust-version V"
exit 1
}
error()
{
echo >&2 "$@"
exit 1
}
# TODO(#15846) Stop accepting --openocd-version once Private CI stops using it.
long="verilator-version:,openocd-version:,verible-version:,rust-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 ;;
--openocd-version) echo "Ignoring --openocd-version"; shift 2 ;;
--verible-version) VERIBLE_VERSION="$2"; shift 2 ;;
--rust-version) RUST_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"
test -n "$RUST_VERSION" || error "Missing --rust-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 verilator from experimental OBS repository
# apt-requirements.txt doesn't cover this dependency as we don't support
# using the repository below for anything but our CI (yet).
lsb_sr="$(lsb_release -sr)"
OBS_URL="https://download.opensuse.org/repositories"
OBS_PATH="/home:/phiwag:/edatools/xUbuntu_${lsb_sr}"
REPO_URL="${OBS_URL}${OBS_PATH}"
EDATOOLS_REPO_KEY="${REPO_URL}/Release.key"
EDATOOLS_REPO="deb ${REPO_URL}/ /"
curl -f -sL -o "$TMPDIR/obs.asc" "$EDATOOLS_REPO_KEY" || {
error "Failed to download repository key from ${REPO_URL}"
}
echo "$EDATOOLS_REPO" > "$TMPDIR/obs.list"
sudo mv "$TMPDIR/obs.asc" /etc/apt/trusted.gpg.d/obs.asc
sudo mv "$TMPDIR/obs.list" /etc/apt/sources.list.d/edatools.list
# 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 "verilator-${VERILATOR_VERSION}" >> "$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
# Explicitly updating pip and setuptools is required to have these tools
# properly parse Python-version metadata, which some packages uses to
# specify that an older version of a package must be used for a certain
# Python version. If that information is not read, pip installs the latest
# version, which then fails to run.
python3 -m pip install --user -U pip setuptools
pip3 install --user -r python-requirements.txt
# Install Verible
lsb_sc="$(lsb_release -sc)"
VERIBLE_BASE_URL="https://github.com/google/verible/releases/download"
VERIBLE_TARBALL="verible-${VERIBLE_VERSION}-Ubuntu-${lsb_sr}-${lsb_sc}-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 Rust
sw/vendor/rustup/rustup-init.sh -y \
--default-toolchain "${RUST_VERSION}"
export PATH=$HOME/.cargo/bin:$PATH
# Propagate PATH changes to all subsequent steps of the job
echo "##vso[task.setvariable variable=PATH]$PATH"