Rearrange unix build scripts. (#430)
authorDoug Wilson <douglas.wilson@gmail.com>
Wed, 11 Oct 2017 01:32:35 +0000 (14:32 +1300)
committerAndrey Mokhov <andrey.mokhov@gmail.com>
Wed, 11 Oct 2017 01:32:35 +0000 (02:32 +0100)
Addresses Issue #428

.travis.yml
build.global-db.sh [moved from build.cabal.sh with 100% similarity]
build.sh
build.stack.nix.sh [new file with mode: 0755]
build.stack.sh
circle.yml
stack.yaml

index e14f962..e2455b2 100644 (file)
@@ -18,10 +18,10 @@ matrix:
 
           script:
               # Run internal Hadrian tests
-              - ./build.cabal.sh selftest
+              - ./build.sh selftest
 
               # Build GHC
-              - ./build.cabal.sh -j $MODE --no-progress --progress-colour=never --profile=-
+              - ./build.sh -j $MODE --no-progress --progress-colour=never --profile=-
 
         - os: linux
           env: MODE="--flavour=quickest --integer-simple"
@@ -40,7 +40,7 @@ matrix:
 
           script:
               # Build GHC
-              - ./build.cabal.sh -j $MODE --no-progress --progress-colour=never --profile=-
+              - ./build.sh -j $MODE --no-progress --progress-colour=never --profile=-
 
               # Test GHC binary
               - cd ..
@@ -56,7 +56,7 @@ matrix:
           script:
               # Due to timeout limit of OS X build on Travis CI,
               # we will ignore selftest and build only stage1
-              - ./build.cabal.sh -j $MODE --no-progress --progress-colour=never --profile=-
+              - ./build.sh -j $MODE --no-progress --progress-colour=never --profile=-
 
 install:
     # Add Cabal to PATH
similarity index 100%
rename from build.cabal.sh
rename to build.global-db.sh
index 0f957cf..2a0e8a7 100755 (executable)
--- a/build.sh
+++ b/build.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
@@ -28,34 +30,45 @@ function rl {
     echo "$RESULT"
 }
 
-root="$(dirname "$(rl "$0")")"
+absoluteRoot="$(dirname "$(rl "$0")")"
+cd "$absoluteRoot"
 
-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
+if ! type "$CABAL" > /dev/null; then
+    echo "Please make sure 'cabal' is in your PATH"
+    exit 2
 fi
 
-mkdir -p "$root/bin"
-
-ghc                                      \
-    "$root/src/Main.hs"                  \
-    -Wall                                \
-    -fno-warn-name-shadowing             \
-    -XRecordWildCards                    \
-    -i"$root/src"                        \
-    -i"$root/../libraries/Cabal/Cabal"   \
-    -rtsopts                             \
-    -with-rtsopts=-I0                    \
-    -threaded                            \
-    -outputdir="$root/bin" \
-    -j -O                                \
-    -o "$root/bin/hadrian"
-
-"$root/bin/hadrian"        \
-    --lint                 \
-    --directory "$root/.." \
-    "$@"
+CABVERSTR=$("$CABAL" --numeric-version)
+
+CABVER=( ${CABVERSTR//./ } )
+
+if [ "${CABVER[0]}" -eq 2 -o "${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
+    $(find ./dist-newstyle -type f -name hadrian | head -n 1) \
+        --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" sandbox add-source ../libraries/Cabal/Cabal
+        "$CABAL" install                \
+            --dependencies-only         \
+            --disable-library-profiling \
+            --disable-shared
+    fi
+
+    "$CABAL" run hadrian --            \
+        --lint                         \
+        --directory "$absoluteRoot/.." \
+        "$@"
+fi
diff --git a/build.stack.nix.sh b/build.stack.nix.sh
new file mode 100755 (executable)
index 0000000..59ac061
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+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")")"
+
+HADRIAN_NIX=YES ${absoluteRoot}/build.stack.sh
index 23f4833..2b1ff1d 100755 (executable)
@@ -31,7 +31,7 @@ function rl {
 absoluteRoot="$(dirname "$(rl "$0")")"
 cd "$absoluteRoot"
 
-stack build --no-library-profiling
+stack build --no-library-profiling ${HADRIAN_NIX:+--nix}
 
 stack exec hadrian --              \
     --lint                         \
index 48653e8..a386d72 100644 (file)
@@ -30,10 +30,10 @@ compile:
 
     # XXX: export PATH doesn't work well either, so we use inline env
     # Self test
-    - PATH=$HOME/.cabal/bin:$PATH ghc/hadrian/build.cabal.sh selftest
+    - PATH=$HOME/.cabal/bin:$PATH ghc/hadrian/build.sh selftest
 
     # Build GHC
-    - PATH=$HOME/.cabal/bin:$PATH ghc/hadrian/build.cabal.sh -j $MODE --no-progress --progress-colour=never --profile=-
+    - PATH=$HOME/.cabal/bin:$PATH ghc/hadrian/build.sh -j $MODE --no-progress --progress-colour=never --profile=-
 
 test:
   override:
index 2a92f26..da03763 100644 (file)
@@ -12,6 +12,7 @@ extra-deps:
 - shake-0.16
 
 nix:
+   enable: false
    packages:
    - autoconf
    - automake