From 581dea70d15483b56e174d8debd13a5af701692e Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Fri, 14 Jun 2013 10:31:01 +0200 Subject: [PATCH 1/2] Generalise determination of hacking directory path Bash needs a special case to determine the dirname of the sourced path (the hacking dir), but in all other cases, using $0 allows the script to be sourced also from within the hacking directory, not only from its parent. Signed-off-by: martin f. krafft --- hacking/env-setup | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hacking/env-setup b/hacking/env-setup index 338e768686b..8eb45370ab1 100755 --- a/hacking/env-setup +++ b/hacking/env-setup @@ -3,11 +3,12 @@ # modifies environment for running Ansible from checkout # When run using source as directed, $0 gets set to bash, so we must use $BASH_SOURCE -if [ -n "$BASH_SOURCE" ] ; then - HACKING_DIR=`dirname $BASH_SOURCE` -else - HACKING_DIR="$PWD/hacking" -fi +case "$0" in + (bash) + HACKING_DIR=${BASH_SOURCE%/*};; + (*) + HACKING_DIR=${0%/*};; +esac # The below is an alternative to readlink -fn which doesn't exist on OS X # Source: http://stackoverflow.com/a/1678636 FULL_PATH=`python -c "import os; print(os.path.realpath('$HACKING_DIR'))"` From 3b008d6fa6f8d29262b846276cd68a1c4621d94b Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Fri, 14 Jun 2013 10:34:07 +0200 Subject: [PATCH 2/2] Expand usage synopsis 'source' is actually a "bashism" and the POSIX-way of sourcing a file uses the single dot (which is arguably less readable). Both yield the same result, and since the script may now also be sourced from within the hacking directory, this commit expands the usage synopsis accordingly. Signed-off-by: martin f. krafft Conflicts: hacking/env-setup --- hacking/env-setup | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hacking/env-setup b/hacking/env-setup index 8eb45370ab1..83f57e9cee5 100755 --- a/hacking/env-setup +++ b/hacking/env-setup @@ -1,5 +1,8 @@ #!/bin/bash -# usage: source ./hacking/env-setup [-q] +# usage: source env-setup [-q] +# source hacking/env-setup [-q] +# . ./env-setup [-q] +# . ./hacking/env-setup [q] # modifies environment for running Ansible from checkout # When run using source as directed, $0 gets set to bash, so we must use $BASH_SOURCE