Check type well formedness for top level function where constraints
[hiphop-php.git] / hphp / hack / opam_setup.sh
blob145cbd30380665a90fed6d4e67afc40870c9a925
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
13 if [ -z "$1" ]; then
14 echo "Usage: $0 /path/to/bin/opam [/path/to/build/dir]"
15 exit 1
18 SOURCE_ROOT="$(dirname "$0")"
19 OPAM_EXECUTABLE="$1"
20 BUILD_ROOT="${2:-"${SOURCE_ROOT}/_build"}"
22 OPAM_EXECUTABLE_DIR="$(dirname "$OPAM_EXECUTABLE")"
24 export PATH="$OPAM_EXECUTABLE_DIR:$PATH"
25 # detect if we are building inside FB by checking a specific dune file
26 if [ -e "$SOURCE_ROOT/src/facebook/dune" ]; then
27 # FB script must have already set OPAMROOT, and we reuse it
28 echo "FB build"
29 if [ -z ${OPAMROOT+x} ]; then
30 echo "OPAMROOT must be set by dune.sh"
31 exit 1
33 echo "OPAMROOT = $OPAMROOT"
34 else
35 echo "Non-FB build"
36 OPAMROOT="${BUILD_ROOT}/opam"
38 export OPAMROOT="$OPAMROOT"
39 mkdir -p "$OPAMROOT"
40 export OPAMYES="1"
42 # shellcheck disable=SC1090
43 source "$SOURCE_ROOT/opam_helpers.sh"
44 # shellcheck disable=SC1090
45 source "$SOURCE_ROOT/ocaml_deps_data.sh"
47 # Shamelessly copied from
48 # https://github.com/facebook/infer/blob/master/scripts/opam_utils.sh
49 # Many thanks to the infer team :D
51 # assumes opam is available and initialized
52 opam_switch_create_if_needed () {
53 local name=$1
54 local switch=$2
55 local switch_exists=no
56 for installed_switch in $(opam switch list --short); do
57 if [ "$installed_switch" == "$name" ]; then
58 switch_exists=yes
59 break
61 done
62 if [ "$switch_exists" = "no" ]; then
63 opam switch create "$name" "$switch"
64 eval "$(opam env)"
68 opam_require_version_2
70 # End of shame
73 HACK_OPAM_SWITCH="${HACK_OCAML_VERSION}"
74 HACK_OPAM_DEFAULT_NAME="hack-switch"
75 HACK_OPAM_NAME=${HACK_OPAM_NAME:-$HACK_OPAM_DEFAULT_NAME}
76 SKIP_MINI_REPO=${SKIP_MINI_REPO:-0}
77 OCAML_PATCH=${OCAML_PATCH:-""}
79 if [[ "${SKIP_MINI_REPO}" -eq 1 ]]; then
80 echo "SKIP_MINI_REPO is set."
81 echo "This setup will fetch from the internet."
82 echo "Make sure you know what you are doing."
83 export http_proxy=http://fwdproxy:8080
84 export https_proxy=http://fwdproxy:8080
87 MINI_REPO_FETCH_SCRIPT="${SOURCE_ROOT}/facebook/fetch_opam2_repo_hack.sh"
89 # OSS does not provide bubblewrap yet so we disable it
90 if [[ -f "${MINI_REPO_FETCH_SCRIPT}" && "${SKIP_MINI_REPO}" -eq 0 ]]; then
91 MINI_REPO_DIR="$("${MINI_REPO_FETCH_SCRIPT}")"
92 MINI_REPO_TARBALL="${MINI_REPO_DIR}.tar.gz"
93 rm -rf "$MINI_REPO_DIR" ||:
94 TARGET_OPAM_DIR="$SOURCE_ROOT/facebook/$(basename "$MINI_REPO_DIR")"
95 mkdir "$TARGET_OPAM_DIR"
96 tar xzf "$MINI_REPO_TARBALL" -C "$TARGET_OPAM_DIR"
97 opam init --disable-sandboxing --reinit offline_clone "$MINI_REPO_DIR" --no-setup --bare
98 else
99 opam init --disable-sandboxing --reinit --no-setup --bare
102 opam_switch_create_if_needed "$HACK_OPAM_NAME" "$HACK_OPAM_SWITCH"
103 opam switch "$HACK_OPAM_NAME"
104 eval "$(opam env)"
106 opam install "${HACK_OPAM_DEPS[@]}"
108 dune_version=$(dune --version)
109 echo ""
110 echo "opam switch correctly installed at $OPAMROOT"
111 echo "dune version is $dune_version"