fix opam_setup.sh
[hiphop-php.git] / hphp / hack / opam_setup.sh
blob2b0575ed6630e83114d471e038180be6b79da031
1 #!/bin/bash
3 # Copyright (c) 2017, Facebook, Inc.
4 # All rights reserved.
6 # This source code is licensed under the MIT license found in the
7 # LICENSE file in the "hack" directory of this source tree.
9 set -euf
11 unset DUNE_BUILD_DIR
12 OCAML_PREFIX=$(dirname "$1")
13 SOURCE_ROOT="$2"
14 BUILD_ROOT="${3:-"${SOURCE_ROOT}/_build"}"
15 export PATH="$OCAML_PREFIX:$PATH"
16 # detect if we are building inside FB by checking a specific dune file
17 if [ -e "$SOURCE_ROOT/src/facebook/dune" ]; then
18 OPAMROOT="$SOURCE_ROOT/facebook/opam"
19 else
20 OPAMROOT="${BUILD_ROOT}/opam"
22 export OPAMROOT="$OPAMROOT"
23 mkdir -p "$OPAMROOT"
24 export OPAMYES="1"
26 # shellcheck disable=SC1090
27 source "$SOURCE_ROOT/opam_helpers.sh"
29 # Shamelessly copied from
30 # https://github.com/facebook/infer/blob/master/scripts/opam_utils.sh
31 # Many thanks to the infer team :D
33 # assumes opam is available and initialized
34 opam_switch_create_if_needed () {
35 local name=$1
36 local switch=$2
37 local switch_exists=no
38 for installed_switch in $(opam switch list --short); do
39 if [ "$installed_switch" == "$name" ]; then
40 switch_exists=yes
41 break
43 done
44 if [ "$switch_exists" = "no" ]; then
45 opam switch create "$name" "$switch"
46 eval "$(opam env)"
50 opam_require_version_2
52 # End of shame
54 HACK_OPAM_SWITCH="ocaml-base-compiler.4.07.1"
55 HACK_OPAM_DEFAULT_NAME="hack-switch"
56 HACK_OPAM_NAME=${HACK_OPAM_NAME:-$HACK_OPAM_DEFAULT_NAME}
58 MINI_TARBALL="$SOURCE_ROOT/facebook/opam2-mini-repository.tar.gz"
59 MINI_REPO="$SOURCE_ROOT/facebook/opam2-mini-repository"
61 # OSS does not provide bubblewrap yet so we disable it
62 if [ -f "$MINI_TARBALL" ]
63 then
64 rm -rf "$MINI_REPO" ||:
65 tar xzf "$MINI_TARBALL" -C "$SOURCE_ROOT/facebook"
66 opam init --disable-sandboxing --reinit offline_clone "$MINI_REPO" --no-setup --bare
67 else
68 opam init --disable-sandboxing --reinit --no-setup --bare
71 opam_switch_create_if_needed "$HACK_OPAM_NAME" "$HACK_OPAM_SWITCH"
72 opam switch set "$HACK_OPAM_NAME"
73 eval "$(opam env)"
75 opam install \
76 core_kernel.v0.11.1 \
77 dtoa.0.3.1 \
78 dune.1.10.0 \
79 fileutils.0.5.3 \
80 lwt.4.2.1 \
81 lwt_log.1.1.0 \
82 lwt_ppx.1.2.2 \
83 merlin.3.3.2 \
84 ocp-indent.1.7.0 \
85 pcre.7.3.5 \
86 ppx_deriving.4.2.1 \
87 ppx_gen_rec.1.1.0 \
88 sedlex.1.99.4 \
89 sexplib.v0.11.0 \
90 sqlite3.4.4.1 \
91 uchar.0.0.2 \
92 visitors.20180513 \
93 wtf8.1.0.1
95 dune_version=$(dune --version)
96 echo ""
97 echo "opam switch correctly installed at $OPAMROOT"
98 echo "dune version is $dune_version"