blob: 77f73994c1cb1fd31c41500a0e003504fbeb3c31 [file] [log] [blame]
Miguel Young de la Sota94383912019-12-05 14:34:04 -06001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
5# Azure template for installing dependencies from various package managers,
6# necessary for building, testing, and packaging OpenTitan.
7#
Philipp Wagner4fbe98f2020-02-25 12:54:20 +00008# This template can be included from pipelines in other repositories.
9# In this case, set the the REPO_TOP parameter to point to the root of the
10# checked out opentitan repository.
11#
Miguel Young de la Sota94383912019-12-05 14:34:04 -060012# This template executes:
Philipp Wagner161bb0c2020-03-30 15:54:33 +010013# - apt-get (*) install for all packages listed in apt-requirements.txt
Miguel Young de la Sota94383912019-12-05 14:34:04 -060014# - pip install for all packages listed in python-requirements.txt
Philipp Wagner161bb0c2020-03-30 15:54:33 +010015#
16# * As an optimization, apt-fast is used instead of apt-get if it is available.
Miguel Young de la Sota94383912019-12-05 14:34:04 -060017
Philipp Wagner4fbe98f2020-02-25 12:54:20 +000018parameters:
19- name: REPO_TOP
20 type: string
21 default: .
22
Miguel Young de la Sota94383912019-12-05 14:34:04 -060023steps:
24 - bash: |
25 set -e
Philipp Wagner4fbe98f2020-02-25 12:54:20 +000026
Philipp Wagner161bb0c2020-03-30 15:54:33 +010027 # Use apt-fast if available for faster installation.
28 if command -v apt-fast >/dev/null; then
29 APT_CMD=apt-fast
30 else
31 APT_CMD=apt-get
32 fi
33
Philipp Wagner4fbe98f2020-02-25 12:54:20 +000034 cd "${{ parameters.REPO_TOP }}"
35
Philipp Wagner0599e762020-02-25 12:57:25 +000036 # Ensure apt package index is up-to-date.
Philipp Wagner161bb0c2020-03-30 15:54:33 +010037 sudo $APT_CMD update
Philipp Wagner0599e762020-02-25 12:57:25 +000038
Miguel Young de la Sota94383912019-12-05 14:34:04 -060039 # NOTE: We use sed to remove all comments from apt-requirements.txt,
Philipp Wagner161bb0c2020-03-30 15:54:33 +010040 # since apt-get/apt-fast doesn't actually provide such a feature.
Miguel Young de la Sota94383912019-12-05 14:34:04 -060041 sed 's/#.*//' apt-requirements.txt \
Philipp Wagner161bb0c2020-03-30 15:54:33 +010042 | xargs sudo $APT_CMD install -y
Philipp Wagner4fbe98f2020-02-25 12:54:20 +000043
Greg Chadwickfe07c7c2020-02-11 11:24:09 +000044 # Python requirements are installed to the local user directory so prepend
45 # appropriate bin directory to the PATH
46 export PATH=$HOME/.local/bin:$PATH
Philipp Wagner4fbe98f2020-02-25 12:54:20 +000047
Greg Chadwickfe07c7c2020-02-11 11:24:09 +000048 # Explicitly installing six is a workaround for pip dependency resolution:
49 # six is already installed as system package with a version below the
50 # required one. Explicitly installing six through pip gets us a supported
51 # version.
52 #
53 # Explicitly updating pip and setuptools is required to have these tools
54 # properly parse Python-version metadata, which some packages uses to
55 # specify that an older version of a package must be used for a certain
56 # Python version. If that information is not read, pip installs the latest
57 # version, which then fails to run.
58 pip3 install --user -U setuptools pip six
59 pip3 install --user -U -r python-requirements.txt
Philipp Wagner4fbe98f2020-02-25 12:54:20 +000060
Greg Chadwickfe07c7c2020-02-11 11:24:09 +000061 # Propagate PATH changes to all subsequent steps of the job
62 echo "##vso[task.setvariable variable=PATH]$PATH"
Miguel Young de la Sota94383912019-12-05 14:34:04 -060063 displayName: 'Install package dependencies'