#!/usr/bin/env bash # Compile the daemon and copy its code into $1 beside a launcher, then print the # launcher's path for ALBEDO_DAEMON. Test daemons boot from the copy instead of # `gleam run`: none of them takes the build lock, so they boot side by side and # beside a running `gleam test`, and a rebuild during the run cannot change the # code under a daemon that is still loading modules. set -euo pipefail root="$(cd "$(dirname "$0")/.." && pwd)" out="$1" # A git dependency fetch must not walk up into the checkout's shared .git (see # nix/devShells.nix). export GIT_CEILING_DIRECTORIES="$root/build${GIT_CEILING_DIRECTORIES:+:$GIT_CEILING_DIRECTORIES}" # A reused directory would keep the previous beams, and `ln -s` would follow its # old priv link into the checkout. rm -rf "$out" (cd "$root" && gleam build) >&2 mkdir -p "$out" for ebin in "$root"/build/dev/erlang/*/ebin; do package="$(dirname "$ebin")" name="$(basename "$package")" mkdir -p "$out/$name" cp -R "$ebin" "$out/$name/ebin" # A priv that links to a source tree keeps pointing at it, as under # `gleam run`. One the build itself holds (a dependency's NIF) is copied: # a rebuild by another toolchain deletes it under a running daemon. if [ -L "$package/priv" ]; then ln -s "$(cd "$package/priv" && pwd -P)" "$out/$name/priv" elif [ -d "$package/priv" ]; then cp -R "$package/priv" "$out/$name/priv" fi done cat >"$out/albedo-daemon" <