Fix build scripts (#668)
authorAndrey Mokhov <andrey.mokhov@gmail.com>
Sat, 1 Sep 2018 18:50:38 +0000 (19:50 +0100)
committerGitHub <noreply@github.com>
Sat, 1 Sep 2018 18:50:38 +0000 (19:50 +0100)
* Delete scripts relying on global package database

* Simplify Cabal build script

* Simplify the default build script

* Fix path

* Invoke the build script from GHC root

* Switch to newer Cabal

* Don't disable Cabal output

* Add build.cabal.bat

.travis.yml
build.cabal.bat [new file with mode: 0644]
build.cabal.sh
build.global-db.bat [deleted file]
build.global-db.sh [deleted file]
build.sh
circle.yml

index f80bca6..dd83ae0 100644 (file)
@@ -8,13 +8,13 @@ matrix:
               apt:
                   packages:
                       - ghc-8.2.2
-                      - cabal-install-2.0
+                      - cabal-install-2.2
                       - zlib1g-dev
                   sources: hvr-ghc
 
           before_install:
               - PATH="/opt/ghc/8.2.2/bin:$PATH"
-              - PATH="/opt/cabal/2.0/bin:$PATH"
+              - PATH="/opt/cabal/2.2/bin:$PATH"
 
           script:
               # Run internal Hadrian tests, after boot and configure.
@@ -27,13 +27,13 @@ matrix:
               apt:
                   packages:
                       - ghc-8.2.2
-                      - cabal-install-2.0
+                      - cabal-install-2.2
                       - zlib1g-dev
                   sources: hvr-ghc
 
           before_install:
               - PATH="/opt/ghc/8.2.2/bin:$PATH"
-              - PATH="/opt/cabal/2.0/bin:$PATH"
+              - PATH="/opt/cabal/2.2/bin:$PATH"
 
           script:
               # Build GHC, letting hadrian boot & configure the ghc source tree
diff --git a/build.cabal.bat b/build.cabal.bat
new file mode 100644 (file)
index 0000000..b47c0bf
--- /dev/null
@@ -0,0 +1,41 @@
+@echo off
+set CABAL=cabal
+set CABFLAGS=--disable-documentation --disable-profiling
+
+rem It is currently more robust to pass Cabal an absolute path to the project file.
+set PROJ="%CD%/hadrian/cabal.project"
+
+if not exist %PROJ% (
+    echo Current working directory must be GHC's top-level folder
+    exit /B 2
+)
+
+"%CABAL%" 2> NUL
+if not %ERRORLEVEL% equ 1 (
+    echo Please make sure 'cabal' is in your PATH
+    exit /B 2
+)
+
+for /F "tokens=*" %%a in ('%CABAL% --numeric-version') do set CABVERSTR=%%a
+for /F "delims=. tokens=1,2,3,4" %%a in ("%CABVERSTR%") do (
+    set CABMAJOR=%%a
+    set CABMINOR=%%b
+    set CABREV=%%c
+    set CABPATCH=%%d
+)
+
+set "_cabal_ok=0"
+if %CABMAJOR% gtr 2 set _cabal_ok=1
+if %CABMAJOR% equ 2 (
+    if %CABMINOR% geq 2 set _cabal_ok=1
+)
+if %_cabal_ok% equ 1 (
+    "%CABAL%" --project-file=%PROJ% new-build %CABFLAGS% -j exe:hadrian
+    "%CABAL%" --project-file=%PROJ% new-run   %CABFLAGS%    exe:hadrian -- ^
+        --lint ^
+        --directory "%CD%" ^
+        %*
+) else (
+    echo Cabal version is too old; you need at least cabal-install 2.2
+    exit /B 2
+)
index fe390af..9fddd61 100755 (executable)
@@ -1,37 +1,17 @@
 #!/usr/bin/env bash
 
 CABAL=cabal
+CABFLAGS="--disable-documentation --disable-profiling"
 
-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
+# It is currently more robust to pass Cabal an absolute path to the project file.
+PROJ="$PWD/hadrian/cabal.project"
 
-    # 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"
-}
+set -euo pipefail
 
-absoluteRoot="$(dirname "$(rl "$0")")"
-cd "$absoluteRoot"
+if ! [ -f "$PROJ" ]; then
+    echo "Current working directory must be GHC's top-level folder"
+    exit 2
+fi
 
 if ! type "$CABAL" > /dev/null; then
     echo "Please make sure 'cabal' is in your PATH"
@@ -39,37 +19,16 @@ if ! type "$CABAL" > /dev/null; then
 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/.." \
+if [ "${CABVER[0]}" -gt 2 -o "${CABVER[0]}" -eq 2 -a "${CABVER[1]}" -ge 2 ];
+then
+    "$CABAL" --project-file="$PROJ" new-build $CABFLAGS -j exe:hadrian
+    "$CABAL" --project-file="$PROJ" new-run   $CABFLAGS    exe:hadrian -- \
+        --lint             \
+        --directory "$PWD" \
         "$@"
-
 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
-    fi
-
-    "$CABAL" install                \
-       --dependencies-only         \
-       --disable-library-profiling \
-       --disable-shared
-
-    "$CABAL" run hadrian --            \
-        --lint                         \
-        --directory "$absoluteRoot/.." \
-        "$@"
+    echo "Cabal version is too old; you need at least cabal-install 2.2"
+    exit 2
 fi
diff --git a/build.global-db.bat b/build.global-db.bat
deleted file mode 100644 (file)
index da3e1ae..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-@echo off
-setlocal
-cd %~dp0
-mkdir bin 2> nul
-
-set ghcArgs=--make                       ^
-            -Wall                        ^
-            -fno-warn-name-shadowing     ^
-            -XDeriveGeneric              ^
-            -XFlexibleInstances          ^
-            -XGeneralizedNewtypeDeriving ^
-            -XLambdaCase                 ^
-            -XRecordWildCards            ^
-            -XScopedTypeVariables        ^
-            -XTupleSections              ^
-            src\Main.hs                  ^
-            -threaded                    ^
-            -isrc                        ^
-            -i..\libraries\Cabal\Cabal   ^
-            -rtsopts                     ^
-            -with-rtsopts=-I0            ^
-            -outputdir=bin               ^
-            -j                           ^
-            -O                           ^
-            -o bin\hadrian
-
-set hadrianArgs=--lint      ^
-                --directory ^
-                ".."        ^
-                %*
-
-ghc %ghcArgs%
-
-if %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
-
-rem Unset GHC_PACKAGE_PATH variable, as otherwise Cabal complains
-set GHC_PACKAGE_PATH=
-bin\hadrian %hadrianArgs%
diff --git a/build.global-db.sh b/build.global-db.sh
deleted file mode 100755 (executable)
index 5f1579b..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/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"
-}
-
-root="$(dirname "$(rl "$0")")"
-
-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/.." \
-    "$@"
\ No newline at end of file
index 13daebe..1fde2d6 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,34 +1,4 @@
 #!/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"
-}
-
-root="$(dirname "$(rl "$0")")"
-
 # By default on Linux/MacOS we build Hadrian using Cabal
-(. "$root/build.cabal.sh" "$@")
+(. "hadrian/build.cabal.sh" "$@")
index 10b9094..cfdca70 100644 (file)
@@ -35,10 +35,10 @@ compile:
 
     # XXX: export PATH doesn't work well either, so we use inline env
     # Self test
-    - PATH=~/.cabal/bin:$PATH ghc/hadrian/build.sh selftest
+    - cd ghc; PATH=~/.cabal/bin:$PATH hadrian/build.sh selftest
 
     # Build GHC
-    - PATH=~/.cabal/bin:$PATH ghc/hadrian/build.sh -j $MODE --no-progress --progress-colour=never --profile=-
+    - cd ghc; PATH=~/.cabal/bin:$PATH hadrian/build.sh -j $MODE --no-progress --progress-colour=never --profile=-
 
 test:
   override: