[commit: ghc] wip/nfs-locking: Fix readlink for os x. (0b0e1d6)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:24:48 UTC 2017


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

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/0b0e1d68b1e58b23c2dff0edd0c4135e0cb3a583/ghc

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

commit 0b0e1d68b1e58b23c2dff0edd0c4135e0cb3a583
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date:   Tue Jan 5 20:43:29 2016 +0800

    Fix readlink for os x.
    
    This should fix #104.


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

0b0e1d68b1e58b23c2dff0edd0c4135e0cb3a583
 build.sh | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/build.sh b/build.sh
index 82cbb93..de9b9d7 100755
--- a/build.sh
+++ b/build.sh
@@ -1,8 +1,34 @@
 #!/usr/bin/env bash
 
+# 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
+}
+
 set -euo pipefail
 
-root="$(dirname "$(readlink -f "$0")")"
+root="$(dirname "$(rl "$0")")"
 
 mkdir -p "$root/.shake"
 



More information about the ghc-commits mailing list