forked from facebook/infer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopam_utils.sh
72 lines (66 loc) · 1.92 KB
/
opam_utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# source this script to import its utility functions
opam_retry () {
"$@" || {
echo >&2;
printf '*** `%s` failed\n' "$*" >&2;
echo '*** Updating opam then retrying' >&2;
opam update &&
"$@" || {
echo >&2;
printf '*** ERROR: `%s` failed\n' "$*" >&2;
exit 1
}
}
}
opam_failed () {
local command=$1
echo
printf '*** ERROR: %s failed\n' "$command" >&2
printf "*** ERROR: Try running \$(opam update) then running this script again\n" >&2
exit 1
}
opam_require_version_2 () {
local status=0
local version=0
{ version=$(opam --version 2>/dev/null); status=$?; }
if [ "$status" != 0 ]; then
printf '*** ERROR: `opam --version` failed, please install opam version 2\n' >&2
env >&2
exit 1
fi
case $version in
2*) ;;
*)
printf '*** ERROR: opam version "%s" is not supported, please install opam version 2\n' "$version" >&2
printf '*** NOTE: opam is "%s"\n' "$(which opam)" >&2
env >&2
exit 1
esac
}
# assumes opam is available and initialized
opam_switch_create_if_needed () {
local switch=$1
local options=$2
local switch_exists=no
printf "looking if switch %s exists in this list:\n" "$switch";
opam switch list --short
for installed_switch in $(opam switch list --short); do
if [ "$installed_switch" == "$switch" ]; then
switch_exists=yes
break
fi
done
printf "verdict: %s\n" $switch_exists;
if [ "$switch_exists" = "no" ]; then
if [ -e "$(opam var root)/$switch" ] ; then
rm -rf "$(opam var root)/$switch" || true
fi
opam switch create "$switch" $options
fi
}
opam_require_version_2