Move Shake files into _build/hadrian
[hadrian.git] / build.cabal-new.sh
1 #!/usr/bin/env bash
2
3 # This wrapper scripts makes use of cabal 1.24+'s nix-store;
4 # In order to clean/reset, remove the `dist-newstyle/` folder
5
6 set -euo pipefail
7
8 # readlink on os x, doesn't support -f, to prevent the
9 # need of installing coreutils (e.g. through brew, just
10 # for readlink, we use the follownig substitute.
11 #
12 # source: http://stackoverflow.com/a/1116890
13 function rl {
14 TARGET_FILE="$1"
15
16 cd "$(dirname "$TARGET_FILE")"
17 TARGET_FILE="$(basename "$TARGET_FILE")"
18
19 # Iterate down a (possible) chain of symlinks
20 while [ -L "$TARGET_FILE" ]
21 do
22 TARGET_FILE="$(readlink "$TARGET_FILE")"
23 cd "$(dirname "$TARGET_FILE")"
24 TARGET_FILE="$(basename "$TARGET_FILE")"
25 done
26
27 # Compute the canonicalized name by finding the physical path
28 # for the directory we're in and appending the target file.
29 PHYS_DIR="$(pwd -P)"
30 RESULT="$PHYS_DIR/$TARGET_FILE"
31 echo "$RESULT"
32 }
33
34 root="$(dirname "$(rl "$0")")"
35
36 mkdir -p "$root/.shake"
37
38 # Notes/Random thoughts:
39 #
40 # - if ghc.git had a top-level `cabal.project` file, we could maybe avoid the
41 # boilerplate above, as we could simply say `cabal exec hadrian` from within
42 # any GHC folder not shadowed by a nearer shadowing `cabal.project` file.
43
44 pushd "$root/"
45
46 cabal new-build --disable-profiling --disable-documentation -j exe:hadrian
47
48 PKGVER="$(awk '/^version:/ { print $2 }' hadrian.cabal)"
49
50 cp -v "$root/dist-newstyle/build/hadrian-${PKGVER}/build/hadrian/hadrian" \
51 "$root/.shake/build"
52
53 popd
54
55 "$root/.shake/build" \
56 --lint \
57 --directory "$root/.." \
58 --colour \
59 "$@"