[commit: ghc] wip/nfs-locking: Merge build.cabal-new.sh into build.cabal.sh (af6a040)
git at git.haskell.org
git at git.haskell.org
Fri Oct 27 01:04:06 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/nfs-locking
Link : http://ghc.haskell.org/trac/ghc/changeset/af6a040742b654d018bfd2fe4dc839a94aa083db/ghc
>---------------------------------------------------------------
commit af6a040742b654d018bfd2fe4dc839a94aa083db
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Fri Jun 3 22:19:36 2016 +0200
Merge build.cabal-new.sh into build.cabal.sh
The script now detect the cabal version and uses either the robust and
fast 'new-build'-logic (for version 1.24 or later), or falls back to the
fragile sandbox-based legacy logic.
>---------------------------------------------------------------
af6a040742b654d018bfd2fe4dc839a94aa083db
build.cabal-new.sh | 58 ------------------------------------------------------
build.cabal.sh | 50 +++++++++++++++++++++++++++++++++++-----------
build.sh | 9 +++++++++
3 files changed, 48 insertions(+), 69 deletions(-)
diff --git a/build.cabal-new.sh b/build.cabal-new.sh
deleted file mode 100755
index 65e222a..0000000
--- a/build.cabal-new.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env bash
-
-# This wrapper scripts makes use of cabal 1.24+'s nix-store;
-# In order to clean/reset, remove the `dist-newstyle/` folder
-
-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"
-}
-
-root="$(dirname "$(rl "$0")")"
-
-mkdir -p "$root/.shake"
-
-# Notes/Random thoughts:
-#
-# - if ghc.git had a top-level `cabal.project` file, we could maybe avoid the
-# boilerplate above, as we could simply say `cabal exec hadrian` from within
-# any GHC folder not shadowed by a nearer shadowing `cabal.project` file.
-
-pushd "$root/"
-
-cabal new-build --disable-profiling --disable-documentation -j exe:hadrian
-
-PKGVER="$(awk '/^version:/ { print $2 }' hadrian.cabal)"
-
-cp -v "$root/dist-newstyle/build/hadrian-${PKGVER}/build/hadrian/hadrian" \
- "$root/.shake/build"
-
-popd
-
-"$root/.shake/build" \
- --lint \
- --directory "$root/.." \
- "$@"
diff --git a/build.cabal.sh b/build.cabal.sh
index 08ff972..4a24dac 100755
--- a/build.cabal.sh
+++ b/build.cabal.sh
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
+CABAL=cabal
+
set -euo pipefail
# readlink on os x, doesn't support -f, to prevent the
@@ -31,16 +33,42 @@ function rl {
absoluteRoot="$(dirname "$(rl "$0")")"
cd "$absoluteRoot"
-# Initialize sandbox if necessary
-if ! ( cabal sandbox hc-pkg list 2>&1 > /dev/null ); then
- cabal sandbox init
- cabal install \
- --dependencies-only \
- --disable-library-profiling \
- --disable-shared
+if ! type "$CABAL" > /dev/null; then
+ echo "Please make sure 'cabal' is in your PATH"
+ exit 2
fi
-cabal run hadrian -- \
- --lint \
- --directory "$absoluteRoot/.." \
- "$@"
+CABVERSTR=$("$CABAL" --numeric-version)
+
+CABVER=( ${CABVERSTR//./ } )
+
+if [ "${CABVER[0]}" -eq 1 -a "${CABVER[1]}" -ge 24 ]; then
+ # New enough cabal version detected, so
+ # let's use the superior 'cabal new-build' mode
+
+ # there's no 'cabal new-run' yet, but it's easy to emulate
+ "$CABAL" new-build --disable-profiling --disable-documentation -j exe:hadrian
+ PKGVER="$(awk '/^version:/ { print $2 }' hadrian.cabal)"
+ "./dist-newstyle/build/hadrian-${PKGVER}/build/hadrian/hadrian" \
+ --lint \
+ --directory "$absoluteRoot/.." \
+ "$@"
+
+else
+ # The logic below is quite fragile, but it's better than nothing for pre-1.24 cabals
+ echo "Old pre cabal 1.24 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" install \
+ --dependencies-only \
+ --disable-library-profiling \
+ --disable-shared
+ fi
+
+ "$CABAL" run hadrian -- \
+ --lint \
+ --directory "$absoluteRoot/.." \
+ "$@"
+fi
diff --git a/build.sh b/build.sh
index 24fdc2f..d627c58 100755
--- a/build.sh
+++ b/build.sh
@@ -30,6 +30,15 @@ function rl {
root="$(dirname "$(rl "$0")")"
+if type cabal > /dev/null 2>&1; then
+ CABVERSTR=$(cabal --numeric-version)
+ CABVER=( ${CABVERSTR//./ } )
+ if [ "${CABVER[0]}" -eq 1 -a "${CABVER[1]}" -ge 24 ]; then
+ echo "** Cabal 1.24 or later detected. Please consider using the 'build.cabal.sh' script **"
+ echo ""
+ fi
+fi
+
mkdir -p "$root/../_build/hadrian"
ghc \
More information about the ghc-commits
mailing list