Added BitBake shared state cache directory variable

Was using default ${HOME}, changed it so you can specify the directory.
Set the default to be ${HOME} so it should work the same as before with
older setups. To satisfy this change added a check to see if the sscdir
or ocache are located under ${HOME}. If they are, it will skip the part
that would have mounted them to the container. It will still be expected
that the sscdir and ocache be seperate directories if not under ${HOME}.
The Kubernetes implementation will expect to use three mounted PVCs that
correspond to the ocache,sscdir, and WORKSPACE.

Change-Id: I6b4ca34f2138633291f80795be2794c496647ffb
Signed-off-by: Alanny Lopez <alanny.lopez@ibm.com>
diff --git a/build-setup.sh b/build-setup.sh
index fc2b1a0..c6251c9 100755
--- a/build-setup.sh
+++ b/build-setup.sh
@@ -7,6 +7,7 @@
 #   distro = fedora|ubuntu
 #   imgtag = tag of the Ubuntu or Fedora image to use (default latest)
 #   obmcdir = <name of OpenBMC src dir> (default /tmp/openbmc)
+#   sscdir = directory that will be used for shared state cache
 #   WORKSPACE = <location of base OpenBMC/OpenBMC repo>
 #   BITBAKE_OPTS = <optional, set to "-c populate_sdk" or whatever other
 #                   BitBake options you'd like to pass into the build>
@@ -27,6 +28,7 @@
 imgtag=${imgtag:-latest}
 ocache=${ocache:-/home/openbmc}
 obmcdir=${obmcdir:-/tmp/openbmc}
+sscdir=${sscdir:-${HOME}}
 WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
 launch=${launch:-}
 http_proxy=${http_proxy:-}
@@ -247,8 +249,8 @@
 PARALLEL_MAKE = "-j$(nproc)"
 INHERIT += "rm_work"
 BB_GENERATE_MIRROR_TARBALLS = "1"
-DL_DIR="${HOME}/bitbake_downloads"
-SSTATE_DIR="${HOME}/bitbake_sharedstatecache"
+DL_DIR="${sscdir}/bitbake_downloads"
+SSTATE_DIR="${sscdir}/bitbake_sharedstatecache"
 USER_CLASSES += "buildstats"
 INHERIT_remove = "uninative"
 EOF_CONF
@@ -272,6 +274,16 @@
   # Build the Docker image
   docker build -t ${imgname} - <<< "${Dockerfile}"
 
+  # If ocache or sscdir are ${HOME} or a subdirectory they will not be mounted
+  mountocache="-v ""${ocache}"":""${ocache}"" "
+  mountsscdir="-v ""${sscdir}"":""${sscdir}"" "
+  if [[ "${ocache}" = "${HOME}/"* || "${ocache}" = "${HOME}" ]];then
+    mountocache=""
+  fi
+  if [[ "${sscdir}" = "${HOME}/"* || "${sscdir}" = "${HOME}" ]];then
+    mountsscdir=""
+  fi
+
   # Run the Docker container, execute the build.sh script
   docker run \
   --cap-add=sys_admin \
@@ -280,7 +292,8 @@
   -e WORKSPACE=${WORKSPACE} \
   -w "${HOME}" \
   -v "${HOME}":"${HOME}" \
-  -v "${ocache}":"${ocache}" \
+  ${mountocache} \
+  ${mountsscdir} \
   -t ${imgname} \
   ${WORKSPACE}/build.sh