opam-ci.sh 2.63 KB
Newer Older
Ralf Jung's avatar
Ralf Jung committed
1
2
#!/bin/bash
set -e
3
4
5
6
7
## This script installs the build dependencies for CI builds.
function run_and_print() {
    echo "$ $@"
    "$@"
}
Ralf Jung's avatar
Ralf Jung committed
8
9
10

# Prepare OPAM configuration
export OPAMROOT="$(pwd)/opamroot"
Ralf Jung's avatar
Ralf Jung committed
11
export OPAMJOBS="$((2*$CPU_CORES))"
Ralf Jung's avatar
Ralf Jung committed
12
13
export OPAM_EDITOR="$(which false)"

14
15
# Make sure we got a good OPAM.
test -d "$OPAMROOT" || (mkdir "$OPAMROOT" && run_and_print opam init --no-setup -y)
Ralf Jung's avatar
Ralf Jung committed
16
eval `opam conf env`
Ralf Jung's avatar
Ralf Jung committed
17

18
19
20
# Make sure the pin for the builddep package is not stale.
run_and_print make build-dep/opam

Ralf Jung's avatar
Ralf Jung committed
21
# Update repositories
Ralf Jung's avatar
Ralf Jung committed
22
23
if test $(find "$OPAMROOT/repo/package-index" -mtime +0); then
    # last update was more than a day ago
24
    run_and_print opam update
Ralf Jung's avatar
Ralf Jung committed
25
else
Ralf Jung's avatar
Ralf Jung committed
26
    # only update iris-dev, and only if it already exists
27
    if test -d "$OPAMROOT/repo/iris-dev"; then run_and_print opam update iris-dev; fi
Ralf Jung's avatar
Ralf Jung committed
28
fi
Ralf Jung's avatar
Ralf Jung committed
29
30
31
32
33
34
35
36
37
38
# Make sure we got the right set of repositories registered
if echo "$@" | fgrep "dev"; then
    # We are compiling against a dev version of something.  Get ourselves the dev repositories.
    test -d "$OPAMROOT/repo/coq-extra-dev" || run_and_print opam repo add coq-extra-dev https://coq.inria.fr/opam/extra-dev -p 0
    test -d "$OPAMROOT/repo/coq-core-dev" || run_and_print opam repo add coq-core-dev https://coq.inria.fr/opam/core-dev -p 5
else
    # No dev version, make sure we do not have the dev repositories.
    test -d "$OPAMROOT/repo/coq-extra-dev" && run_and_print opam repo remove coq-extra-dev
    test -d "$OPAMROOT/repo/coq-core-dev" && run_and_print opam repo remove coq-core-dev
fi
39
40
41
42
43
44
test -d "$OPAMROOT/repo/coq-released" || run_and_print opam repo add coq-released https://coq.inria.fr/opam/released -p 10
test -d "$OPAMROOT/repo/iris-dev" || run_and_print opam repo add iris-dev https://gitlab.mpi-sws.org/FP/opam-dev.git -p 20
echo

# We really want to run all of the following in one opam transaction, but due to opam limitations,
# that is not currently possible.
Ralf Jung's avatar
Ralf Jung committed
45

46
# Install fixed versions of some dependencies.
Ralf Jung's avatar
Ralf Jung committed
47
echo
Ralf Jung's avatar
Ralf Jung committed
48
49
while (( "$#" )); do # while there are arguments left
    PACKAGE="$1" ; shift
50
    KIND="$1" ; shift
Ralf Jung's avatar
Ralf Jung committed
51
    VERSION="$1" ; shift
52

Ralf Jung's avatar
Ralf Jung committed
53
    # Check if the pin is already set
Ralf Jung's avatar
Ralf Jung committed
54
55
    read -a PIN <<< $(opam pin list | (egrep "^$PACKAGE[. ]"))
    if [[ "${PIN[1]}" == "$KIND" && "${PIN[2]}" == "$VERSION" ]]; then
56
        echo "[opam-ci] $PACKAGE already $KIND-pinned to $VERSION"
Ralf Jung's avatar
Ralf Jung committed
57
    else
58
        echo "[opam-ci] $KIND-pinning $PACKAGE to $VERSION"
59
        run_and_print opam pin add -y -k "$KIND" "$PACKAGE" "$VERSION"
Ralf Jung's avatar
Ralf Jung committed
60
    fi
Ralf Jung's avatar
Ralf Jung committed
61
62
done

63
64
65
66
67
68
# Upgrade cached things.
echo
echo "[opam-ci] Upgrading opam"
run_and_print opam upgrade -y

# Install build-dependencies.
Ralf Jung's avatar
Ralf Jung committed
69
echo
70
71
echo "[opam-ci] Installing build-dependencies"
make build-dep OPAMFLAGS=-y
Ralf Jung's avatar
Ralf Jung committed
72
73
74
75

# done
echo
coqc -v