diff options
author | Andrey Mokhov <andrey.mokhov@gmail.com> | 2017-11-06 22:59:38 +0000 |
---|---|---|
committer | Andrey Mokhov <andrey.mokhov@gmail.com> | 2017-11-06 22:59:38 +0000 |
commit | 5cee48036ed69ae298a599d43cf72e0fe73e3b4e (patch) | |
tree | 5fe732c738a769d02e732469f4ffecd4ac9e191a /hadrian/build.cabal.sh | |
parent | 275ac8ef0a0081f16abbfb8934e10cf271573768 (diff) | |
parent | 7b0b9f603bb1215e2b7af23c2404d637b95a4988 (diff) | |
download | haskell-5cee48036ed69ae298a599d43cf72e0fe73e3b4e.tar.gz |
Merge commit '7b0b9f603bb1215e2b7af23c2404d637b95a4988' as 'hadrian'
Diffstat (limited to 'hadrian/build.cabal.sh')
-rw-r--r-- | hadrian/build.cabal.sh | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/hadrian/build.cabal.sh b/hadrian/build.cabal.sh new file mode 100644 index 0000000000..d2bdb857e1 --- /dev/null +++ b/hadrian/build.cabal.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +CABAL=cabal + +set -euo pipefail + +# readlink on os x, doesn't support -f, to prevent the +# need of installing coreutils (e.g. through brew, just +# for readlink, we use the follownig substitute. +# +# source: http://stackoverflow.com/a/1116890 +function rl { + TARGET_FILE="$1" + + cd "$(dirname "$TARGET_FILE")" + TARGET_FILE="$(basename "$TARGET_FILE")" + + # Iterate down a (possible) chain of symlinks + while [ -L "$TARGET_FILE" ] + do + TARGET_FILE="$(readlink "$TARGET_FILE")" + cd "$(dirname "$TARGET_FILE")" + TARGET_FILE="$(basename "$TARGET_FILE")" + done + + # Compute the canonicalized name by finding the physical path + # for the directory we're in and appending the target file. + PHYS_DIR="$(pwd -P)" + RESULT="$PHYS_DIR/$TARGET_FILE" + echo "$RESULT" +} + +absoluteRoot="$(dirname "$(rl "$0")")" +cd "$absoluteRoot" + +if ! type "$CABAL" > /dev/null; then + echo "Please make sure 'cabal' is in your PATH" + exit 2 +fi + +CABVERSTR=$("$CABAL" --numeric-version) + +CABVER=( ${CABVERSTR//./ } ) + +if [ "${CABVER[0]}" -gt 2 -o "${CABVER[0]}" -eq 2 -a "${CABVER[1]}" -ge 1 ]; then + # New enough Cabal version detected, so let's use the superior new-build + new-run + # modes. Note that pre-2.1 Cabal does not support passing additional parameters + # to the executable (hadrian) after the separator '--', see #438. + + "$CABAL" new-build --disable-profiling --disable-documentation -j exe:hadrian + "$CABAL" new-run hadrian -- \ + --lint \ + --directory "$absoluteRoot/.." \ + "$@" + +else + # The logic below is quite fragile, but it's better than nothing for pre-2.1 Cabal. + echo "Old pre cabal 2.1 version detected. Falling back to legacy 'cabal sandbox' mode." + + # Initialize sandbox if necessary + if ! ( "$CABAL" sandbox hc-pkg list > /dev/null 2>&1); then + "$CABAL" sandbox init + "$CABAL" sandbox add-source ../libraries/Cabal/Cabal + "$CABAL" install \ + --dependencies-only \ + --disable-library-profiling \ + --disable-shared + fi + + "$CABAL" run hadrian -- \ + --lint \ + --directory "$absoluteRoot/.." \ + "$@" +fi |