Skip to content

Commit

Permalink
feat(setup/rebuild): use OPAMs prefix if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
W95Psp committed Apr 24, 2024
1 parent c38739d commit a771ecd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .utils/rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ ocaml () {
CURRENT="ocaml"
dune build $([ -z $DUNEJOBS ] || echo "-j $DUNEJOBS")
CURRENT="ocaml/install"

# Small hack for those that are not using [opam] at all: by
# default install OCaml binaries in `~/.cargo` (which is supposed
# to be in PATH anyway).
DUNE_INSTALL_PREFIX="${DUNE_INSTALL_PREFIX:-$HOME/.cargo}"
dune install --profile dev --prefix $DUNE_INSTALL_PREFIX
INSTALL_PREFIX="${OPAM_SWITCH_PREFIX:-${DUNE_INSTALL_PREFIX:-$HOME/.cargo}}"
dune install --profile dev --prefix $INSTALL_PREFIX

if ( command -v "which" && command -v "sort" && command -v "wc" ) >/dev/null; then
case $(which -a hax-engine | sort -u | wc -l) in
Expand Down
17 changes: 16 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

set -eu

opam_jobs=2
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"

opam_jobs=4

# Parse command line arguments.
all_args=("$@")
Expand All @@ -16,6 +18,17 @@ while [ $# -gt 0 ]; do
shift
done

# Warns if we're building in a dirty checkout of hax: while hacking on
# hax, we should really be using the `./.utils/rebuild.sh`
warn_if_dirty() {
(
cd "$SCRIPTPATH"
if ! git diff-index --quiet HEAD -- >& /dev/null; then
printf '\e[33mWarning: This is a dirty checkout of hax!\n If you are hacking on hax, please use the \e[1m`./.utils/rebuild.sh`\e[0m\e[33m script.\e[0m\n\n'
fi
)
}

# Ensures a given binary is available in PATH
ensure_binary_available() {
command -v "$1" >/dev/null 2>&1 || {
Expand Down Expand Up @@ -73,6 +86,8 @@ install_ocaml_engine() {
)
}

warn_if_dirty

for binary in opam node rustup jq; do
ensure_binary_available $binary
done
Expand Down

0 comments on commit a771ecd

Please sign in to comment.