[dev-util] Clean up stale workdirs when using cros_workon_make

If the user has previously used FEATURES=noclean or keepwork in emerging his package,
then cros_workon_make will happily use this stale checkout unless --reconf is passed.
We should detect such a stale work dir and for a reconf.

BUG=chromium-os:15770
TEST=clear the work dir, FEATURES=noclean emerge-BOARD <package>, cros_workon_make <package>, and then ls -l the work dir to see that there's a symlink in there pointing to the user's source checkout

Change-Id: I6312daa609ae11ab183b1fc4ab66016919c9f518
Reviewed-on: http://gerrit.chromium.org/gerrit/1590
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
diff --git a/host/cros_workon_make b/host/cros_workon_make
index 3564d57..0a86a75 100755
--- a/host/cros_workon_make
+++ b/host/cros_workon_make
@@ -86,6 +86,12 @@
   rm -f "/build/${BOARD_STR}/tmp/portage/${workpath}/.tested"
 fi
 
+workdir="/build/${BOARD_STR}/tmp/portage/${workpath}/work/${workon_name}"
+if [ ! -h "${workdir}" ]; then
+  warn "Cleaning up stale workdir: ${workdir}"
+  FLAGS_reconf="${FLAGS_TRUE}"  # To force symlinking in the user's src dir.
+fi
+
 if [ "${FLAGS_install}" = "${FLAGS_TRUE}" ]; then
   SANDBOX_WRITE=~/trunk CROS_WORKON_INPLACE=1 \
     FEATURES="${emerge_features} ${FEATURES}" "${EMERGECMD}" "${1}"