prepare-opam.sh 3.34 KB
Newer Older
1
2
3
4
5
6
7
## This script installs the build dependencies for CI builds.

# Prepare OPAM configuration
export OPAMROOT="$(pwd)/opamroot"
export OPAMJOBS="$((2*$CPU_CORES))"
export OPAM_EDITOR="$(which false)"

Ralf Jung's avatar
Ralf Jung committed
8
# Delete OPAM 1.2 root, if that's what we got
Ralf Jung's avatar
Ralf Jung committed
9
if test -d "$OPAMROOT" && fgrep 'opam-version: "1.2"' "$OPAMROOT/config" > /dev/null; then
Ralf Jung's avatar
Ralf Jung committed
10
11
12
13
    echo_color "$BOLDYELLOW" "[prepare-opam] Deleting opam 1.2 root"
    rm -rf "$OPAMROOT"
fi

14
# Make sure we got a good OPAM.
Ralf Jung's avatar
Ralf Jung committed
15
if test -d "$OPAMROOT"; then
Ralf Jung's avatar
Ralf Jung committed
16
    echo_color "$BOLDGREEN" "[prepare-opam] Re-using cached opam root"
Ralf Jung's avatar
Ralf Jung committed
17
else
Ralf Jung's avatar
Ralf Jung committed
18
    echo_color "$BOLDYELLOW" "[prepare-opam] Creating new opam root"
Ralf Jung's avatar
Ralf Jung committed
19
    mkdir "$OPAMROOT"
20
21
22
23
24
    if [[ -z "${OPAM_SWITCH}" ]]; then
        INITIAL_SWITCH="";
    else
        INITIAL_SWITCH="-c ${OPAM_SWITCH}";
    fi;
25
    opam init --no-setup --disable-sandboxing -y ${INITIAL_SWITCH}
26
    FRESH_OPAM=yes
Ralf Jung's avatar
Ralf Jung committed
27
fi
28
29
eval `opam conf env`

30
31
32
33
if [[ -z "$FRESH_OPAM" ]]; then # skip if this is a fresh opam root
    # Make sure the pin for the builddep package exists and is up-to-date.
    # This avoids opam complaining about pins pointing to a non-existing file.
    make build-dep/opam
34

35
36
37
    # Update repositories
    opam update
fi
38
39

# Make sure we got the right set of repositories registered
40
if echo "$@" | egrep "(dev|beta)" > /dev/null; then
41
    # We are compiling against a dev version of something.  Get ourselves the dev repositories.
Ralf Jung's avatar
Ralf Jung committed
42
43
    test -d "$OPAMROOT/repo/coq-extra-dev" || opam repo add coq-extra-dev https://coq.inria.fr/opam/extra-dev --rank 0
    test -d "$OPAMROOT/repo/coq-core-dev" || opam repo add coq-core-dev https://coq.inria.fr/opam/core-dev --rank 5
44
45
46
47
48
else
    # No dev version, make sure we do not have the dev repositories.
    test -d "$OPAMROOT/repo/coq-extra-dev" && opam repo remove coq-extra-dev
    test -d "$OPAMROOT/repo/coq-core-dev" && opam repo remove coq-core-dev
fi
Ralf Jung's avatar
Ralf Jung committed
49
50
test -d "$OPAMROOT/repo/coq-released" || opam repo add coq-released https://coq.inria.fr/opam/released --rank 10
test -d "$OPAMROOT/repo/iris-dev" || opam repo add iris-dev https://gitlab.mpi-sws.org/FP/opam-dev.git --rank 20
51
52
53
echo

# We really want to run all of the following in one opam transaction, but due to opam limitations,
Ralf Jung's avatar
Ralf Jung committed
54
55
# that is not currently possible.  Once we use opam 2 for CI, we can first do all the pinning (with `-n`)
# followed by `opam upgrade --all build-dep/` (and hope this will also --fixup).
56
57

# Install fixed versions of some dependencies.
Ralf Jung's avatar
Ralf Jung committed
58
echo_color "$BOLDGREEN" "[prepare-opam] Processing pins"
59
60
61
62
63
64
65
66
while (( "$#" )); do # while there are arguments left
    PACKAGE="$1" ; shift
    KIND="$1" ; shift
    VERSION="$1" ; shift

    # Check if the pin is already set
    read -a PIN <<< $(opam pin list | (egrep "^$PACKAGE[. ]"))
    if [[ "${PIN[1]}" == "$KIND" && "${PIN[2]}" == "$VERSION" ]]; then
Ralf Jung's avatar
Ralf Jung committed
67
        echo_color "$BOLDGREEN" "[prepare-opam] $PACKAGE already $KIND-pinned to $VERSION"
68
    else
Ralf Jung's avatar
Ralf Jung committed
69
        echo_color "$BOLDYELLOW" "[prepare-opam] $KIND-pinning $PACKAGE to $VERSION"
70
71
72
        opam pin add -y -k "$KIND" "$PACKAGE" "$VERSION"
    fi
done
Ralf Jung's avatar
Ralf Jung committed
73
echo
74

75
76
77
if [[ -z "$FRESH_OPAM" ]]; then # skip if this is a fresh opam root
    # Upgrade cached things
    echo_color "$BOLDGREEN" "[prepare-opam] Upgrading packages"
78
    opam upgrade -y --fixup && opam upgrade -y
79
80
    echo
fi
81
82

# Install build-dependencies.
Ralf Jung's avatar
Ralf Jung committed
83
echo_color "$BOLDGREEN" "[prepare-opam] Installing build-dependencies"
Ralf Jung's avatar
Ralf Jung committed
84
make build-dep OPAMFLAGS="-y"
Ralf Jung's avatar
Ralf Jung committed
85
echo
86
87
88
89

# done
echo
coqc -v