Browse files

Use realpath to locate relative files, add sh impl

because Mac OSX doesn't have a realpath binary.

This solves the issue where if you symlink to sbt, it
won't be able to locate the bash library and launcher anymore.

You'd want to do that so you can symlink just sbt to /usr/local/bin
without having to put a bash library file there as well.
In particular, this is what we'd like for Mac homebrew.
  • Loading branch information...
1 parent 6fa1b52 commit 40f2105070a8cec11b480357aa1332e540066987 @bartschuller bartschuller committed Sep 6, 2012
Showing with 21 additions and 1 deletion.
  1. +1 −1 project/packaging.scala
  2. +20 −0 src/scripts/sbt
View
2 project/packaging.scala
@@ -49,7 +49,7 @@ object Packaging {
fixedLinuxScriptDir <<= target / "linux-scripts",
fixedUniversalScriptDir <<= target / "universal-scripts",
linuxFixedScripts <<= (fixedScriptDir, fixedLinuxScriptDir) map fixScripts("/usr/lib/sbt/sbt-launch.jar", "/usr/share/sbt/sbt-launch-lib.bash"),
- universalFixedScripts <<= (fixedScriptDir, fixedUniversalScriptDir) map fixScripts("\\$(dirname \\$0)/sbt-launch.jar", "\\$(dirname \\$0)/sbt-launch-lib.bash"),
+ universalFixedScripts <<= (fixedScriptDir, fixedUniversalScriptDir) map fixScripts("\\$(dirname \\$(realpath \\$0))/sbt-launch.jar", "\\$(dirname \\$(realpath \\$0))/sbt-launch-lib.bash"),
sbtLaunchJarUrl <<= sbtVersion apply downloadUrlForVersion,
sbtLaunchJarLocation <<= target apply (_ / "sbt-launch.jar"),
sbtLaunchJar <<= (sbtLaunchJarUrl, sbtLaunchJarLocation) map { (uri, file) =>
View
20 src/scripts/sbt
@@ -1,5 +1,25 @@
#!/usr/bin/env bash
+realpath () {
+(
+ TARGET_FILE=$1
+
+ cd $(dirname $TARGET_FILE)
+ TARGET_FILE=$(basename $TARGET_FILE)
+
+ COUNT=0
+ while [ -L "$TARGET_FILE" -a $COUNT -lt 100 ]
+ do
+ TARGET_FILE=$(readlink $TARGET_FILE)
+ cd $(dirname $TARGET_FILE)
+ TARGET_FILE=$(basename $TARGET_FILE)
+ COUNT=$(($COUNT + 1))
+ done
+
+ echo $(pwd -P)/$TARGET_FILE
+)
+}
+
. @@BASH-LIB-LOCATION@@

0 comments on commit 40f2105

Please sign in to comment.