Rupert Swarbrick | d0ca7e9 | 2021-03-15 13:00:32 +0000 | [diff] [blame] | 1 | #!/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 | |
| 6 | set -e |
| 7 | |
| 8 | usage() |
| 9 | { |
| 10 | echo "Usage: install-package-dependencies.sh --verilator-version V" |
| 11 | echo " --openocd-version V" |
| 12 | echo " --verible-version V" |
Alphan Ulusoy | e220589 | 2021-05-13 09:36:17 -0400 | [diff] [blame] | 13 | echo " --rust-version V" |
Rupert Swarbrick | d0ca7e9 | 2021-03-15 13:00:32 +0000 | [diff] [blame] | 14 | exit 1 |
| 15 | } |
| 16 | |
| 17 | error() |
| 18 | { |
| 19 | echo >&2 "$@" |
| 20 | exit 1 |
| 21 | } |
| 22 | |
Alphan Ulusoy | e220589 | 2021-05-13 09:36:17 -0400 | [diff] [blame] | 23 | long="verilator-version:,openocd-version:,verible-version:,rust-version:" |
Rupert Swarbrick | d0ca7e9 | 2021-03-15 13:00:32 +0000 | [diff] [blame] | 24 | ARGS="$(getopt -o "" -l "$long" -- "$@")" || usage |
| 25 | |
| 26 | VERILATOR_VERSION= |
| 27 | OPENOCD_VERSION= |
| 28 | VERIBLE_VERSION= |
| 29 | |
| 30 | eval set -- "$ARGS" |
| 31 | while : |
| 32 | do |
| 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 Ulusoy | e220589 | 2021-05-13 09:36:17 -0400 | [diff] [blame] | 37 | --rust-version) RUST_VERSION="$2"; shift 2 ;; |
Rupert Swarbrick | d0ca7e9 | 2021-03-15 13:00:32 +0000 | [diff] [blame] | 38 | --) shift; break ;; |
| 39 | *) error "getopt / case statement mismatch" |
| 40 | esac |
| 41 | done |
| 42 | |
| 43 | # Check that we've seen all the expected versions |
| 44 | test -n "$VERILATOR_VERSION" || error "Missing --verilator-version" |
| 45 | test -n "$OPENOCD_VERSION" || error "Missing --openocd-version" |
| 46 | test -n "$VERIBLE_VERSION" || error "Missing --verible-version" |
Alphan Ulusoy | e220589 | 2021-05-13 09:36:17 -0400 | [diff] [blame] | 47 | test -n "$RUST_VERSION" || error "Missing --rust-version" |
Rupert Swarbrick | d0ca7e9 | 2021-03-15 13:00:32 +0000 | [diff] [blame] | 48 | |
| 49 | # Check that there aren't any positional arguments |
| 50 | test $# = 0 || error "Unexpected positional arguments" |
| 51 | |
| 52 | CI_DIR="$(dirname "$(readlink -e "$BASH_SOURCE")")" |
| 53 | REPO_TOP="$(readlink -e "$CI_DIR/..")" |
| 54 | |
| 55 | cd "$REPO_TOP" |
| 56 | |
| 57 | # Use apt-fast if available for faster installation. |
| 58 | if command -v apt-fast >/dev/null; then |
| 59 | APT_CMD=apt-fast |
| 60 | else |
| 61 | APT_CMD=apt-get |
| 62 | fi |
| 63 | |
| 64 | TMPDIR="$(mktemp -d)" || { |
| 65 | error "Failed to create temporary directory" |
| 66 | } |
| 67 | trap '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). |
| 73 | lsb_sr="$(lsb_release -sr)" |
| 74 | OBS_URL="https://download.opensuse.org/repositories" |
| 75 | OBS_PATH="/home:/phiwag:/edatools/xUbuntu_${lsb_sr}" |
| 76 | REPO_URL="${OBS_URL}${OBS_PATH}" |
| 77 | |
| 78 | EDATOOLS_REPO_KEY="${REPO_URL}/Release.key" |
| 79 | EDATOOLS_REPO="deb ${REPO_URL}/ /" |
| 80 | |
| 81 | curl -f -sL -o "$TMPDIR/obs.asc" "$EDATOOLS_REPO_KEY" || { |
| 82 | error "Failed to download repository key from ${REPO_URL}" |
| 83 | } |
| 84 | echo "$EDATOOLS_REPO" > "$TMPDIR/obs.list" |
| 85 | |
| 86 | sudo mv "$TMPDIR/obs.asc" /etc/apt/trusted.gpg.d/obs.asc |
| 87 | sudo mv "$TMPDIR/obs.list" /etc/apt/sources.list.d/edatools.list |
| 88 | |
Drew Macrae | 010b825 | 2022-01-25 04:34:13 -0800 | [diff] [blame] | 89 | # Install gcc-9 and set it as the default. |
| 90 | sudo 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 Swarbrick | d0ca7e9 | 2021-03-15 13:00:32 +0000 | [diff] [blame] | 98 | # Ensure apt package index is up-to-date. |
| 99 | sudo $APT_CMD update || { |
| 100 | error "Failed to run apt update" |
| 101 | } |
| 102 | |
| 103 | ci_reqs="$TMPDIR/apt-requirements-ci.txt" |
| 104 | cp apt-requirements.txt "$ci_reqs" |
| 105 | echo "verilator-${VERILATOR_VERSION}" >> "$ci_reqs" |
| 106 | echo "openocd-${OPENOCD_VERSION}" >> "$ci_reqs" |
| 107 | echo 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. |
| 111 | sed -i -e '/^$/d' -e '/^#/d' -e 's/#.*//' "$ci_reqs" |
| 112 | |
| 113 | echo "Amended apt-requirements:" |
| 114 | cat "$ci_reqs" |
| 115 | |
| 116 | xargs 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 |
| 120 | export 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. |
| 127 | python3 -m pip install --user -U pip setuptools |
| 128 | |
| 129 | pip3 install --user -r python-requirements.txt |
| 130 | |
| 131 | # Install Verible |
| 132 | lsb_sc="$(lsb_release -sc)" |
| 133 | VERIBLE_BASE_URL="https://github.com/google/verible/releases/download" |
| 134 | VERIBLE_TARBALL="verible-${VERIBLE_VERSION}-Ubuntu-${lsb_sr}-${lsb_sc}-x86_64.tar.gz" |
| 135 | VERIBLE_URL="${VERIBLE_BASE_URL}/${VERIBLE_VERSION}/${VERIBLE_TARBALL}" |
| 136 | |
| 137 | verible_tar="$TMPDIR/verible.tar.gz" |
| 138 | |
| 139 | curl -f -Ls -o "$verible_tar" "${VERIBLE_URL}" || { |
| 140 | error "Failed to download verible from ${VERIBLE_URL}" |
| 141 | } |
| 142 | |
| 143 | sudo mkdir -p /tools/verible |
| 144 | sudo chmod 777 /tools/verible |
| 145 | tar -C /tools/verible -xf "$verible_tar" --strip-components=1 |
Alphan Ulusoy | b91333a | 2021-05-13 09:45:14 -0400 | [diff] [blame] | 146 | export PATH=/tools/verible/bin:$PATH |
Alphan Ulusoy | e220589 | 2021-05-13 09:36:17 -0400 | [diff] [blame] | 147 | |
Philipp Wagner | 48fe27a | 2021-09-29 15:08:58 +0100 | [diff] [blame] | 148 | # Install Rust |
| 149 | sw/vendor/rustup/rustup-init.sh -y \ |
| 150 | --default-toolchain "${RUST_VERSION}" |
| 151 | export PATH=$HOME/.cargo/bin:$PATH |
| 152 | |
Alphan Ulusoy | b91333a | 2021-05-13 09:45:14 -0400 | [diff] [blame] | 153 | # Propagate PATH changes to all subsequent steps of the job |
| 154 | echo "##vso[task.setvariable variable=PATH]$PATH" |