[commit: ghc] master: Make sure build scripts can be run from outside Hadrian directory (c41d1ed)

git at git.haskell.org git at git.haskell.org
Tue Oct 23 20:11:03 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/c41d1ed7c0e989273a359c653890796957972e8e/ghc

>---------------------------------------------------------------

commit c41d1ed7c0e989273a359c653890796957972e8e
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Fri Nov 3 23:24:53 2017 +0000

    Make sure build scripts can be run from outside Hadrian directory
    
    See #440


>---------------------------------------------------------------

c41d1ed7c0e989273a359c653890796957972e8e
 build.bat |  2 ++
 build.sh  | 34 ++++++++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/build.bat b/build.bat
index 18cf6cb..01a869f 100644
--- a/build.bat
+++ b/build.bat
@@ -1,4 +1,6 @@
 @echo off
+setlocal
+cd %~dp0
 
 rem By default on Windows we build Hadrian using Stack
 ./build.stack.bat %*
diff --git a/build.sh b/build.sh
index 8e58b66..ad502b3 100755
--- a/build.sh
+++ b/build.sh
@@ -1,5 +1,35 @@
 #!/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
-chmod a+x ./build.cabal.sh
-(. ./build.cabal.sh "$@")
+chmod a+x "$root/build.cabal.sh"
+(. "$root/build.cabal.sh" "$@")



More information about the ghc-commits mailing list