utils.bbclass: add dirs/pushd/popd
authorChris Larson <chris_larson@mentor.com>
Sun, 21 Nov 2010 17:39:24 +0000 (10:39 -0700)
committerChris Larson <chris_larson@mentor.com>
Sun, 21 Nov 2010 17:40:28 +0000 (10:40 -0700)
These can be useful, and even necessary in some tasks, yet are bash, so let's
ensure they're available so we can avoid the /bin/sh is bash requirement in
the future.

Signed-off-by: Chris Larson <chris_larson@mentor.com>
classes/utils.bbclass

index 4cc6896..2fa6204 100644 (file)
@@ -434,3 +434,23 @@ def base_set_filespath(path, d):
                for o in overrides.split(":"):
                        filespath.append(os.path.join(p, o))
        return ":".join(filespath)
+
+# These directory stack functions are based upon the versions in the Korn
+# Shell documentation - http://docstore.mik.ua/orelly/unix3/korn/ch04_07.htm.
+dirs() {
+    echo "$_DIRSTACK"
+}
+
+pushd() {
+    dirname=$1
+    cd ${dirname:?"missing directory name."} || return 1
+    _DIRSTACK="$PWD $_DIRSTACK"
+    echo "$_DIRSTACK"
+}
+
+popd() {
+    _DIRSTACK=${_DIRSTACK#* }
+    top=${_DIRSTACK%% *}
+    cd $top || return 1
+    echo "$PWD"
+}