Add --gerrit-chrome option.

Enables cbuildbot to build Chrome from GERRIT_SOURCE.

Contains safety checks so this is not used on remote trybots, since
chrome_set_ver can potentially put the repository in a bad state.

BUG=chromium-os:32456
TEST=Ran local trybot

Change-Id: I6521d5b66df3aa022fa0e51744a9bf5285cf1882
Reviewed-on: https://gerrit.chromium.org/gerrit/27083
Commit-Ready: Ryan Cui <rcui@chromium.org>
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: Ryan Cui <rcui@chromium.org>
diff --git a/scripts/cbuildbot.py b/scripts/cbuildbot.py
index 65fdb2a..913702e 100644
--- a/scripts/cbuildbot.py
+++ b/scripts/cbuildbot.py
@@ -654,6 +654,14 @@
   parser.values.chrome_rev = value
 
 
+def _CheckGerritChromeOption(_option, _opt_str, value, parser):
+  """Validate the chrome_rev option."""
+  if parser.values.chrome_rev is None:
+    parser.values.chrome_rev = constants.CHROME_REV_TOT
+
+  parser.values.gerrit_chrome = True
+
+
 class CustomParser(optparse.OptionParser):
   def add_remote_option(self, *args, **kwargs):
     """For arguments that are passed-through to remote trybot."""
@@ -879,6 +887,11 @@
   # direcly to the bootstrap re-execution.
   parser.add_remote_option('--bootstrap-args', action='append',
                           default=[], help=optparse.SUPPRESS_HELP)
+  # Specify to use Gerrit Source for building Chrome.  Implies
+  # --chrome_rev=CHROME_REV_TOT.
+  parser.add_option('--gerrit-chrome', action='callback', default=False,
+                    callback=_CheckGerritChromeOption, dest='gerrit_chrome',
+                    help=optparse.SUPPRESS_HELP)
   parser.add_option('--pass-through', dest='pass_through_args', action='append',
                    type='string', default=[], help=optparse.SUPPRESS_HELP)
   # Used for handling forwards/backwards compatibility for --resume and
@@ -954,6 +967,13 @@
           'Chrome rev must not be %s if chrome_version is not set.'
           % constants.CHROME_REV_SPEC)
 
+  if options.gerrit_chrome:
+    if options.remote_trybot or options.remote:
+      cros_build_lib.Die('Cannot use --gerrit-chrome with remote trybots!')
+    elif options.chrome_rev != constants.CHROME_REV_TOT:
+      cros_build_lib.Die('Chrome rev must be %s if chrome_root is set.' %
+                          constants.CHROME_REV_TOT)
+
   patches = bool(options.gerrit_patches or options.local_patches)
   if options.remote:
     if options.local: