cbuildbot: tie the cache for chrome src per branch

Separate the cache used by chrome src per branch to avoid
cache collision.

BUG=chromium:635702
TEST=cbuildbot --local --gerrit-patches='398480' <buildbot_config>
CQ-DEPEND=CL:403368

Change-Id: Ic4301aab1601f615affe482c61c9d965c6473437
Reviewed-on: https://chromium-review.googlesource.com/403369
Commit-Ready: YH Lin <yueherngl@chromium.org>
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Reviewed-by: YH Lin <yueherngl@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index b1fb21a..ec3cb8d 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -205,8 +205,14 @@
     # Tell Chrome to fetch the source locally.
     internal = constants.USE_CHROME_INTERNAL in build_config['useflags']
     chrome_src = 'chrome-src-internal' if internal else 'chrome-src'
-    options.chrome_root = os.path.join(options.cache_dir, 'distfiles', 'target',
-                                       chrome_src)
+    target_name = 'target'
+    if options.branch:
+      # Tie the cache per branch
+      target_name = 'target-%s' % options.branch
+    options.chrome_root = os.path.join(options.cache_dir, 'distfiles',
+                                       target_name, chrome_src)
+    # Create directory if in need
+    osutils.SafeMakedirsNonRoot(options.chrome_root)
   elif options.rietveld_patches:
     cros_build_lib.Die('This builder does not support Rietveld patches.')