mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
2edd4c00f4
* Add --ghc-repo-override flag to override GHC used in daml-sdk-head build CHANGELOG_BEGIN CHANGELOG_END * Add BAZEL_MODE_FLAGS to third `bazel build` call
234 lines
7.6 KiB
Bash
Executable File
234 lines
7.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eu
|
|
|
|
# Make sure they are in the right repo
|
|
readonly REPO_ROOT="$(bazel info workspace)"
|
|
if [[ "${REPO_ROOT}/dev-env/bin/daml-sdk-head" != "${BASH_SOURCE[0]}" ]]; then
|
|
echo "Repo root does not match the script being run."
|
|
echo "Make sure you run this script from a directory within the 'daml' repository "
|
|
exit 1
|
|
fi
|
|
|
|
# get rid of old .daml-head installation
|
|
if [[ -d "${HOME}/.daml-head" ]]; then
|
|
chmod -R u+w "${HOME}/.daml-head"
|
|
rm -rf "${HOME}/.daml-head"
|
|
fi
|
|
|
|
BAZEL_MODE_FLAGS=()
|
|
|
|
NUKE=0
|
|
PROFILING=0
|
|
SKIP_JARS=0
|
|
SKIP_JAR_DOCS=0
|
|
SKIP_SDK=0
|
|
JUST_DAMLC=0
|
|
SCALA_VERSIONS=()
|
|
SHA=0
|
|
EE=0
|
|
for opt in "$@"; do
|
|
case "$opt" in
|
|
"--nuke")
|
|
NUKE=1
|
|
;;
|
|
"--profiling")
|
|
PROFILING=1
|
|
;;
|
|
"--skip-jars")
|
|
SKIP_JARS=1
|
|
;;
|
|
"--skip-jar-docs")
|
|
SKIP_JAR_DOCS=1
|
|
;;
|
|
"--scala-version="*)
|
|
VERSION="${opt#*=}"
|
|
SCALA_VERSIONS+=($VERSION)
|
|
;;
|
|
"--skip-sdk")
|
|
SKIP_SDK=1
|
|
;;
|
|
"--damlc")
|
|
JUST_DAMLC=1
|
|
;;
|
|
"--sha")
|
|
SHA=1
|
|
;;
|
|
"--ee")
|
|
EE=1
|
|
;;
|
|
"--ghc-repo-override="*)
|
|
GHC_REPO_OVERRIDE="${opt#*=}"
|
|
BAZEL_MODE_FLAGS+=(--override_repository=da-ghc="$GHC_REPO_OVERRIDE")
|
|
;;
|
|
*)
|
|
echo "Unknown option: $opt"
|
|
echo "Available options:"
|
|
echo " --nuke Remove existing daml installation before installing daml-head."
|
|
echo " --profiling Build Haskell executables with profiling enabled."
|
|
echo " --skip-jars Skip building and installing the JARs."
|
|
echo " --skip-jar-docs Skips docs builds & installation for jars."
|
|
echo " --skip-sdk Skip building and installing the SDK."
|
|
echo " --scala-version=<version> Only build for Scala version <version>. Can be specified multiple times. Note that you need an equal sign, not a space."
|
|
echo " --damlc Update damlc only, if daml-head is already installed."
|
|
echo " --sha Include SHA information in version number."
|
|
echo " --ee Build the EE edition."
|
|
echo " --ghc-repo-override=<path> Override GHC dependency for bazel build."
|
|
|
|
exit 1
|
|
esac
|
|
done
|
|
|
|
if [[ "$PROFILING" -ne 0 ]]; then
|
|
BAZEL_MODE_FLAGS+=(-c dbg)
|
|
fi
|
|
|
|
readonly DAML_HOME="$HOME/.daml"
|
|
if [[ -d "$DAML_HOME" && "$NUKE" -ne 0 ]]; then
|
|
echo "$(tput setaf 3)Removing existing daml installation.$(tput sgr 0)"
|
|
chmod -R u+w "$DAML_HOME"
|
|
rm -rf "$DAML_HOME"
|
|
fi
|
|
|
|
sha_version() {
|
|
local dirty date nr sha8 index_file old_trap
|
|
if [[ -z $(git status -s) ]]; then
|
|
dirty=""
|
|
else
|
|
old_trap=$(trap -p EXIT)
|
|
index_file=$(mktemp)
|
|
trap "$old_trap; rm -f $index_file" EXIT
|
|
cp -f $(git rev-parse --show-toplevel)/.git/index $index_file
|
|
GIT_INDEX_FILE=$index_file git add --all
|
|
dirty=".dirty.$(GIT_INDEX_FILE=$index_file git write-tree)"
|
|
rm -f $index_file
|
|
trap "$old_trap" EXIT
|
|
fi
|
|
date=$(git log -n1 --format=%cd --date=format:%Y%m%d HEAD)
|
|
nr=$(git rev-list --count HEAD)
|
|
sha8=$(git log -n1 --format=%h --abbrev=8 HEAD)
|
|
echo "0.0.0-head.${date}.${nr}.${sha8}${dirty}"
|
|
}
|
|
if [ $SHA = 0 ]; then
|
|
export DAML_SDK_RELEASE_VERSION=0.0.0
|
|
else
|
|
export DAML_SDK_RELEASE_VERSION=$(sha_version)
|
|
fi
|
|
|
|
if [[ "$SKIP_SDK" -eq 0 ]]; then
|
|
readonly DAML_HEAD_SDK="$DAML_HOME/sdk/$DAML_SDK_RELEASE_VERSION"
|
|
if [[ -d "$DAML_HEAD_SDK" && "$JUST_DAMLC" -eq 0 ]]; then
|
|
echo "$(tput setaf 3)Removing existing daml-head installation.$(tput sgr 0)"
|
|
rm -f "${DAML_HOME}/bin/daml-head"
|
|
chmod -R u+w "$DAML_HEAD_SDK"
|
|
rm -rf "$DAML_HEAD_SDK"
|
|
fi
|
|
|
|
if [[ -d "$DAML_HEAD_SDK" && "$JUST_DAMLC" -ne 0 ]]; then
|
|
# daml-head is installed, so just replace damlc
|
|
echo "$(tput setaf 3)Existing daml-head installation found."
|
|
echo "Building damlc version $DAML_SDK_RELEASE_VERSION, this may take a while ...$(tput sgr 0)"
|
|
echo ""
|
|
|
|
function cleanup() {
|
|
echo "damlc $DAML_SDK_RELEASE_VERSION failed to build/install; if you need help ask on https://discuss.daml.com"
|
|
echo "$(tput setaf 3)FAILED TO INSTALL! $(tput sgr 0)"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
bazel build ${BAZEL_MODE_FLAGS[@]:-} //compiler/damlc:damlc-dist.tar.gz
|
|
|
|
readonly TARBALL="$(bazel info bazel-bin ${BAZEL_MODE_FLAGS[@]:-})/compiler/damlc/damlc-dist.tar.gz"
|
|
chmod -R u+w "$DAML_HEAD_SDK"
|
|
rm -rf "${DAML_HEAD_SDK}/damlc"
|
|
mkdir -p "${DAML_HEAD_SDK}/damlc"
|
|
tar xzf "$TARBALL" -C "${DAML_HEAD_SDK}/damlc" --strip-components 1
|
|
|
|
trap - EXIT
|
|
echo "$(tput setaf 3)Done installing damlc $DAML_SDK_RELEASE_VERSION$(tput sgr 0)"
|
|
exit 0
|
|
fi
|
|
|
|
echo "$(tput setaf 3)Building version $DAML_SDK_RELEASE_VERSION - this may take a while ...$(tput sgr 0)"
|
|
echo ""
|
|
|
|
function cleanup() {
|
|
echo "SDK $DAML_SDK_RELEASE_VERSION failed to build/install - if you need help ask on"
|
|
echo "https://discuss.daml.com"
|
|
echo "$(tput setaf 3)FAILED TO INSTALL! $(tput sgr 0)"
|
|
|
|
if [[ -n "${SDK_TEMP_DIR+x}" && -d "$SDK_TEMP_DIR" ]]; then
|
|
rm -rf "$SDK_TEMP_DIR"
|
|
fi
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
SDK_RELEASE_TARBALL="sdk-release-tarball-ce.tar.gz"
|
|
if [ $EE = 1 ]; then
|
|
SDK_RELEASE_TARBALL="sdk-release-tarball-ee.tar.gz"
|
|
fi
|
|
|
|
# Building here separately so the user can see the build process which could take a while
|
|
bazel build ${BAZEL_MODE_FLAGS[@]:-} //release:$SDK_RELEASE_TARBALL
|
|
|
|
readonly TARBALL="$(bazel info bazel-bin ${BAZEL_MODE_FLAGS[@]:-})/release/$SDK_RELEASE_TARBALL"
|
|
readonly SDK_TEMP_DIR="$(mktemp -d)"
|
|
readonly SDK_DIR="${SDK_TEMP_DIR}/sdk-head"
|
|
mkdir -p "$SDK_DIR"
|
|
|
|
tar xzf "$TARBALL" -C "$SDK_DIR" --strip-components 1
|
|
|
|
readonly DAML_CMD="$(command -v daml)"
|
|
if [[ -x "$DAML_CMD" && "$DAML_CMD" == "$DAML_HOME/bin/daml" ]]; then
|
|
# A Daml installation already exists, so just install SDK version $DAML_SDK_RELEASE_VERSION.
|
|
"${DAML_HOME}/bin/daml" install "$SDK_DIR" --force --set-path=no
|
|
else
|
|
# No daml installation detected, so install the tarball normally but disable auto-install.
|
|
"${SDK_DIR}/install.sh" --force --set-path=no
|
|
echo "auto-install: false" > "${DAML_HOME}/daml-config.yaml"
|
|
fi
|
|
|
|
if [[ -d "$SDK_TEMP_DIR" ]]; then
|
|
rm -rf "$SDK_TEMP_DIR"
|
|
fi
|
|
|
|
cat > "${DAML_HOME}/bin/daml-head" << EOF
|
|
#!/bin/sh
|
|
exec env DAML_SDK_VERSION=$DAML_SDK_RELEASE_VERSION "${DAML_HEAD_SDK}/daml/daml" "\$@"
|
|
EOF
|
|
chmod +x "${DAML_HOME}/bin/daml-head"
|
|
|
|
trap - EXIT
|
|
echo "$(tput setaf 3)Successfully installed daml-head command pointing to $DAML_SDK_RELEASE_VERSION.$(tput sgr 0)"
|
|
|
|
fi
|
|
|
|
if [[ "$SKIP_JARS" -eq 0 ]]; then
|
|
echo "$(tput setaf 3)Installing JARs as $DAML_SDK_RELEASE_VERSION...$(tput sgr 0)"
|
|
|
|
function cleanup() {
|
|
echo "$(tput setaf 3)FAILED TO INSTALL JARS! $(tput sgr 0)"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
bazel build ${BAZEL_MODE_FLAGS[@]:-} //release:release
|
|
tmp="$(mktemp -d)"
|
|
RELEASE_ARGS=(--release-dir "$tmp" --install-head-jars --no-ts)
|
|
if [[ "$SKIP_JAR_DOCS" -eq 1 ]]; then
|
|
RELEASE_ARGS+=(--no-docs)
|
|
fi
|
|
# Note (MK) You might be wondering what this horrendous
|
|
# expansion is doing here. This is to guard against set -u
|
|
# behavior on bash < 4.4 which treat empty arrays as unbound variables.
|
|
# This expansion is shamelessly stolen from
|
|
# https://stackoverflow.com/questions/7577052/bash-empty-array-expansion-with-set-u
|
|
for version in ${SCALA_VERSIONS[@]+"${SCALA_VERSIONS[@]}"}; do
|
|
RELEASE_ARGS+=("--scala-version=$version")
|
|
done
|
|
|
|
"${REPO_ROOT}/bazel-bin/release/release" ${RELEASE_ARGS[@]}
|
|
|
|
trap - EXIT
|
|
|
|
echo "$(tput setaf 3)Done installing JARs as $DAML_SDK_RELEASE_VERSION.$(tput sgr 0)"
|
|
fi
|