Add `cabal new-build` based wrapper script
authorHerbert Valerio Riedel <hvr@gnu.org>
Sun, 24 Jan 2016 09:43:43 +0000 (10:43 +0100)
committerHerbert Valerio Riedel <hvr@gnu.org>
Sun, 24 Jan 2016 09:43:43 +0000 (10:43 +0100)
This makes use of the new nix-store cache for the shake library and other
pre-requisities, rather than using the reinstall-breakage-prone old-style
global pkg-db

.gitignore
build.cabal-new.sh [new file with mode: 0755]

index 6cc5501..967be07 100644 (file)
@@ -1,7 +1,14 @@
-.shake/
-.db/
+/.shake/
+/.db/
 cfg/system.config
+
+# build.cabal.sh specific
+/dist/
+/.cabal-sandbox/
 cabal.sandbox.config
-dist/
-.cabal-sandbox/
-.stack-work/
+
+# build.cabal-new.sh specific
+/dist-newstyle/
+
+# build.stack.sh specific
+/.stack-work/
diff --git a/build.cabal-new.sh b/build.cabal-new.sh
new file mode 100755 (executable)
index 0000000..96c194e
--- /dev/null
@@ -0,0 +1,59 @@
+#!/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 ghc-shake` 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:ghc-shake
+
+PKGVER="$(awk '/^version:/ { print $2 }' shaking-up-ghc.cabal)"
+
+cp -v "$root/dist-newstyle/build/shaking-up-ghc-${PKGVER}/build/ghc-shake/ghc-shake" \
+      "$root/.shake/build"
+
+popd
+
+"$root/.shake/build"       \
+    --lint                 \
+    --directory "$root/.." \
+    --colour               \
+    "$@"