Improvements to build_command_buffer.py

Allows a shortcut, -t, for --chrome-build-type and clarifies meaning of the value in help.

Removes --fetch. This used to work with gyp builds but since it doesn't run gn it currently fails to build after fetching the src. Also, it wasn't being used.

Adds --no-hooks. Like --no-sync it but also doesn't run gclient runhooks.

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2236953002

Review-Url: https://codereview.chromium.org/2236953002
diff --git a/tools/build_command_buffer.py b/tools/build_command_buffer.py
index c107986..7dabafe 100755
--- a/tools/build_command_buffer.py
+++ b/tools/build_command_buffer.py
@@ -28,11 +28,10 @@
       help='path to copy the command buffer shared library to')
   parser.add_argument('--make-output-dir', default=False, action='store_true',
       help='Makes the output directory if it does not already exist.')
-  parser.add_argument('-f', '--fetch', action='store_true', default=False,
-      help=('Create Chromium src directory and fetch chromium checkout (if '
-            'directory does not already exist)'))
-  parser.add_argument('--chrome-build-type', default='Release',
-      help='Type of build for the command buffer (e.g. Debug or Release)')
+  parser.add_argument('-t', '--chrome-build-type', default='Release',
+      help='Type of build for the command buffer (e.g. Debug or Release). The '
+            'output dir to build will be <chrome-dir>/out/<chrome-build-type> '
+            'and must already be initialized by gn.')
   parser.add_argument('--extra-ninja-args', default='',
       help=('Extra arguments to pass to ninja when building the command '
             'buffer shared library'))
@@ -40,11 +39,17 @@
       help='Revision (hash, branch, tag) of Chromium to use.')
   parser.add_argument('--no-sync', action='store_true', default=False,
       help='Don\'t run git fetch or gclient sync in the Chromium tree')
+  parser.add_argument('--no-hooks', action='store_true', default=False,
+      help='Don\'t run gclient runhooks in the Chromium tree. Implies '
+           '--no-sync')
   args = parser.parse_args()
 
   args.chrome_dir = os.path.abspath(args.chrome_dir)
   args.output_dir = os.path.abspath(args.output_dir)
 
+  if args.no_hooks:
+     args.no_sync = True
+
   if os.path.isfile(args.chrome_dir):
     sys.exit(args.chrome_dir + ' exists but is a file.')
 
@@ -53,26 +58,6 @@
 
   chrome_src_dir = os.path.join(args.chrome_dir, 'src')
 
-  if os.path.isfile(chrome_src_dir):
-    sys.exit(chrome_src_dir + ' exists but is a file.')
-  elif not os.path.isdir(chrome_src_dir):
-    if args.fetch:
-      if os.path.isdir(args.chrome_dir):
-        # If chrome_dir is a dir but chrome_src_dir does not exist we will only
-        # fetch into chrome_dir if it is empty.
-        if os.listdir(args.chrome_dir):
-          sys.exit(args.chrome_dir + ' is not a chromium checkout and is not '
-              'empty.')
-      else:
-        os.makedirs(args.chrome_dir)
-      if not os.path.isdir(args.chrome_dir):
-        sys.exit('Could not create ' + args.chrome_dir)
-      try:
-        subprocess.check_call(['fetch', 'chromium'], cwd=args.chrome_dir)
-      except subprocess.CalledProcessError as error:
-        sys.exit('Error (ret code: %s) calling "%s" in %s' % error.returncode,
-            error.cmd, args.chrome_dir)
-
   if not os.path.isdir(chrome_src_dir):
     sys.exit(chrome_src_dir + ' is not a directory.')
 
@@ -123,17 +108,19 @@
 
     try:
       os.environ['GYP_GENERATORS'] = 'ninja'
-      subprocess.check_call([gclient, 'sync', '--reset', '--force'],
+      subprocess.check_call([gclient, 'sync', '--reset', '--force',
+                             '--nohooks'],
           cwd=chrome_src_dir)
     except subprocess.CalledProcessError as error:
       sys.exit('Error (ret code: %s) calling "%s" in %s' % (error.returncode,
           error.cmd, chrome_src_dir))
 
-  try:
-    subprocess.check_call([gclient, 'runhooks'], cwd=chrome_src_dir)
-  except subprocess.CalledProcessError as error:
-    sys.exit('Error (ret code: %s) calling "%s" in %s' % (
-        error.returncode, error.cmd, chrome_src_dir))
+  if not args.no_hooks:
+    try:
+      subprocess.check_call([gclient, 'runhooks'], cwd=chrome_src_dir)
+    except subprocess.CalledProcessError as error:
+      sys.exit('Error (ret code: %s) calling "%s" in %s' % (
+          error.returncode, error.cmd, chrome_src_dir))
 
   gn = 'gn'
   platform = 'linux64'