blob: 975a1977c20185ee824d72d714a1aa7906bd7d1a [file] [log] [blame]
Rupert Swarbrickd0ca7e92021-03-15 13:00:32 +00001#!/bin/bash
2# Copyright lowRISC contributors.
3# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4# SPDX-License-Identifier: Apache-2.0
5
6set -e
7
8usage()
9{
10 echo "Usage: install-package-dependencies.sh --verilator-version V"
11 echo " --openocd-version V"
12 echo " --verible-version V"
Alphan Ulusoye2205892021-05-13 09:36:17 -040013 echo " --rust-version V"
Rupert Swarbrickd0ca7e92021-03-15 13:00:32 +000014 exit 1
15}
16
17error()
18{
19 echo >&2 "$@"
20 exit 1
21}
22
Alphan Ulusoye2205892021-05-13 09:36:17 -040023long="verilator-version:,openocd-version:,verible-version:,rust-version:"
Rupert Swarbrickd0ca7e92021-03-15 13:00:32 +000024ARGS="$(getopt -o "" -l "$long" -- "$@")" || usage
25
26VERILATOR_VERSION=
27OPENOCD_VERSION=
28VERIBLE_VERSION=
29
30eval set -- "$ARGS"
31while :
32do
33 case "$1" in
34 --verilator-version) VERILATOR_VERSION="$2"; shift 2 ;;
35 --openocd-version) OPENOCD_VERSION="$2"; shift 2 ;;
36 --verible-version) VERIBLE_VERSION="$2"; shift 2 ;;
Alphan Ulusoye2205892021-05-13 09:36:17 -040037 --rust-version) RUST_VERSION="$2"; shift 2 ;;
Rupert Swarbrickd0ca7e92021-03-15 13:00:32 +000038 --) shift; break ;;
39 *) error "getopt / case statement mismatch"
40 esac
41done
42
43# Check that we've seen all the expected versions
44test -n "$VERILATOR_VERSION" || error "Missing --verilator-version"
45test -n "$OPENOCD_VERSION" || error "Missing --openocd-version"
46test -n "$VERIBLE_VERSION" || error "Missing --verible-version"
Alphan Ulusoye2205892021-05-13 09:36:17 -040047test -n "$RUST_VERSION" || error "Missing --rust-version"
Rupert Swarbrickd0ca7e92021-03-15 13:00:32 +000048
49# Check that there aren't any positional arguments
50test $# = 0 || error "Unexpected positional arguments"
51
52CI_DIR="$(dirname "$(readlink -e "$BASH_SOURCE")")"
53REPO_TOP="$(readlink -e "$CI_DIR/..")"
54
55cd "$REPO_TOP"
56
57# Use apt-fast if available for faster installation.
58if command -v apt-fast >/dev/null; then
59 APT_CMD=apt-fast
60else
61 APT_CMD=apt-get
62fi
63
64TMPDIR="$(mktemp -d)" || {
65 error "Failed to create temporary directory"
66}
67trap 'rm -rf "$TMPDIR"' EXIT
68
69
70# Install verilator from experimental OBS repository
71# apt-requirements.txt doesn't cover this dependency as we don't support
72# using the repository below for anything but our CI (yet).
73lsb_sr="$(lsb_release -sr)"
74OBS_URL="https://download.opensuse.org/repositories"
75OBS_PATH="/home:/phiwag:/edatools/xUbuntu_${lsb_sr}"
76REPO_URL="${OBS_URL}${OBS_PATH}"
77
78EDATOOLS_REPO_KEY="${REPO_URL}/Release.key"
79EDATOOLS_REPO="deb ${REPO_URL}/ /"
80
81curl -f -sL -o "$TMPDIR/obs.asc" "$EDATOOLS_REPO_KEY" || {
82 error "Failed to download repository key from ${REPO_URL}"
83}
84echo "$EDATOOLS_REPO" > "$TMPDIR/obs.list"
85
86sudo mv "$TMPDIR/obs.asc" /etc/apt/trusted.gpg.d/obs.asc
87sudo mv "$TMPDIR/obs.list" /etc/apt/sources.list.d/edatools.list
88
Drew Macrae010b8252022-01-25 04:34:13 -080089# Install gcc-9 and set it as the default.
90sudo add-apt-repository ppa:ubuntu-toolchain-r/test \
91 && sudo $APT_CMD update \
92 && sudo $APT_CMD install -y gcc-9 g++-9 \
93 && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 \
94 && sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90 || {
95 error "Failed to set up gcc-9"
96 }
97
Rupert Swarbrickd0ca7e92021-03-15 13:00:32 +000098# Ensure apt package index is up-to-date.
99sudo $APT_CMD update || {
100 error "Failed to run apt update"
101}
102
103ci_reqs="$TMPDIR/apt-requirements-ci.txt"
104cp apt-requirements.txt "$ci_reqs"
105echo "verilator-${VERILATOR_VERSION}" >> "$ci_reqs"
106echo "openocd-${OPENOCD_VERSION}" >> "$ci_reqs"
107echo rsync >> "$ci_reqs"
108
109# NOTE: We use sed to remove all comments from apt-requirements-ci.txt,
110# since apt-get/apt-fast doesn't actually provide such a feature.
111sed -i -e '/^$/d' -e '/^#/d' -e 's/#.*//' "$ci_reqs"
112
113echo "Amended apt-requirements:"
114cat "$ci_reqs"
115
116xargs sudo $APT_CMD install -y <"$ci_reqs"
117
118# Python requirements are installed to the local user directory so prepend
119# appropriate bin directory to the PATH
120export PATH=$HOME/.local/bin:$PATH
121
122# Explicitly updating pip and setuptools is required to have these tools
123# properly parse Python-version metadata, which some packages uses to
124# specify that an older version of a package must be used for a certain
125# Python version. If that information is not read, pip installs the latest
126# version, which then fails to run.
127python3 -m pip install --user -U pip setuptools
128
129pip3 install --user -r python-requirements.txt
130
131# Install Verible
132lsb_sc="$(lsb_release -sc)"
133VERIBLE_BASE_URL="https://github.com/google/verible/releases/download"
134VERIBLE_TARBALL="verible-${VERIBLE_VERSION}-Ubuntu-${lsb_sr}-${lsb_sc}-x86_64.tar.gz"
135VERIBLE_URL="${VERIBLE_BASE_URL}/${VERIBLE_VERSION}/${VERIBLE_TARBALL}"
136
137verible_tar="$TMPDIR/verible.tar.gz"
138
139curl -f -Ls -o "$verible_tar" "${VERIBLE_URL}" || {
140 error "Failed to download verible from ${VERIBLE_URL}"
141}
142
143sudo mkdir -p /tools/verible
144sudo chmod 777 /tools/verible
145tar -C /tools/verible -xf "$verible_tar" --strip-components=1
Alphan Ulusoyb91333a2021-05-13 09:45:14 -0400146export PATH=/tools/verible/bin:$PATH
Alphan Ulusoye2205892021-05-13 09:36:17 -0400147
Philipp Wagner48fe27a2021-09-29 15:08:58 +0100148# Install Rust
149sw/vendor/rustup/rustup-init.sh -y \
150 --default-toolchain "${RUST_VERSION}"
151export PATH=$HOME/.cargo/bin:$PATH
152
Alphan Ulusoyb91333a2021-05-13 09:45:14 -0400153# Propagate PATH changes to all subsequent steps of the job
154echo "##vso[task.setvariable variable=PATH]$PATH"