Revert "Really don't pass default cache directory to subprocesses."

It does not make sense for subprocesses to inherit the default cache-dir.
Consider the following case:
  - cbuildbot is executed from /b/build/slave/x86-generic-paladin/build
  - cbuildbot re-executes inside /b/cbuild/external_master
Currently, in this case, the re-executed cbuildbot uses
/b/build/slave/x86-generic-paladin/build/.cache, which is just plain wrong.
cbuildbot should use its local cache dir and not inherit it from parents.
BUG=chromium-os:37908, chromium-os:36324
TEST=Run cbuildbot and really verify right cache-dir is used now.
Original-Change-Id: I015d4a7ac8d1a2821634fae6e4d390dcf1c44950
Reviewed-on: https://gerrit.chromium.org/gerrit/43250
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: David James <davidjames@chromium.org>
Change-Id: I015d4a7ac8d1a2821634fae6e4d390dcf1c44950
Reviewed-on: https://gerrit.chromium.org/gerrit/43252
Reviewed-by: David James <davidjames@chromium.org>
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index 28e034e..41a5bd6 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -241,10 +241,6 @@
       vp_file = sync_instance.SaveValidationPool()
       args += ['--validation_pool', vp_file]
 
-    # Reset cache dir to None so that the child will calculate it automatically.
-    if not self.options.cache_dir_specified:
-      commandline.BaseParser.ConfigureCacheDir(None)
-
     # Re-run the command in the buildroot.
     # Finally, be generous and give the invoked cbuildbot 30s to shutdown
     # when something occurs.  It should exit quicker, but the sigterm may
@@ -684,7 +680,9 @@
   parser.values.chrome_rev = value
 
 
-def FindCacheDir(_parser, _options):
+def FindCacheDir(parser, options):
+  if constants.SHARED_CACHE_ENVVAR in os.environ:
+    return commandline.OptionParser.FindCacheDir(parser, options)
   return None
 
 
@@ -1043,9 +1041,7 @@
       raise Exception('Could not find repo checkout at %s!'
                       % options.sourceroot)
 
-  # Because the default cache dir depends on other options, we don't set
-  # the normal default value for options.cache_dir upstairs and instead set
-  # it here.
+  # Ensure we have a workable cachedir from this point forward.
   if options.cache_dir is None:
     # Note, options.sourceroot is set regardless of the path
     # actually existing.