3 # Copyright (c) 2017, Facebook, Inc.
6 # This source code is licensed under the MIT license found in the
7 # LICENSE file in the "hack" directory of this source tree.
12 OCAML_PREFIX
=$
(dirname "$1")
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"
20 OPAMROOT
="${BUILD_ROOT}/opam"
22 export OPAMROOT
="$OPAMROOT"
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
() {
37 local switch_exists
=no
38 for installed_switch
in $
(opam switch list
--short); do
39 if [ "$installed_switch" == "$name" ]; then
44 if [ "$switch_exists" = "no" ]; then
45 opam switch create
"$name" "$switch"
50 opam_require_version_2
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" ]
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
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"
95 dune_version
=$
(dune
--version)
97 echo "opam switch correctly installed at $OPAMROOT"
98 echo "dune version is $dune_version"