Add proguard helper scripts, also:

- new option --print-runtimeraw for run_on_app.py

Bug:
Change-Id: I4f315b8503aa3b88874e78d3f8a9f1af7a3d982c
diff --git a/tools/proguard.py b/tools/proguard.py
new file mode 100755
index 0000000..58c049f
--- /dev/null
+++ b/tools/proguard.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+# Run ProGuard, Google's internal version
+
+from __future__ import print_function
+import os
+import subprocess
+import sys
+
+import utils
+
+PROGUARD_JAR = os.path.join(utils.REPO_ROOT, 'third_party', 'proguard',
+    'proguard_internal_159423826', 'ProGuard_deploy.jar')
+
+def run(args):
+  cmd = ['java', '-jar', PROGUARD_JAR]
+  cmd.extend(args)
+  print('-- ' + ' '.join(cmd))
+  subprocess.check_call(cmd)
+
+def Main():
+  run(sys.argv[1:])
+
+if __name__ == '__main__':
+  sys.exit(Main())
diff --git a/tools/run_on_app.py b/tools/run_on_app.py
index 9b4cb4d..133f852 100755
--- a/tools/run_on_app.py
+++ b/tools/run_on_app.py
@@ -9,6 +9,7 @@
 import d8
 import sys
 import utils
+import time
 
 import gmscore_data
 import youtube_data
@@ -67,6 +68,11 @@
                     help='Dump a file with the arguments for the specified ' +
                     'configuration. For use as a @<file> argument to perform ' +
                     'the run.')
+  result.add_option('--print-runtimeraw',
+                    metavar='BENCHMARKNAME',
+                    help='Prints the line \'<BENCHMARKNAME>(RunTimeRaw):' +
+                         ' <elapsed> ms\' at the end where <elapsed> is' +
+                         ' the elapsed time in milliseconds.')
   return result.parse_args()
 
 # Most apps have the -printmapping and -printseeds in the Proguard
@@ -147,6 +153,8 @@
   if inputs:
     args.extend(inputs)
 
+  t0 = time.time()
+
   if options.dump_args_file:
     with open(options.dump_args_file, 'w') as args_file:
       args_file.writelines([arg + os.linesep for arg in args])
@@ -166,5 +174,9 @@
         r8.run(args, not options.no_build, not options.no_debug, options.profile,
                options.track_memory_to_file)
 
+  if options.print_runtimeraw:
+    print('{}(RunTimeRaw): {} ms'
+        .format(options.print_runtimeraw, 1000.0 * (time.time() - t0)))
+
 if __name__ == '__main__':
   sys.exit(main())
diff --git a/tools/run_proguard_dx_on_gmscore.py b/tools/run_proguard_dx_on_gmscore.py
new file mode 100755
index 0000000..a67868b
--- /dev/null
+++ b/tools/run_proguard_dx_on_gmscore.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+
+# Run ProGuard and the DX tool on GmsCore V10.
+
+from __future__ import print_function
+from os import makedirs
+from os.path import exists, join
+from subprocess import check_call
+import argparse
+import gmscore_data
+import os
+import stat
+import sys
+import time
+
+import proguard
+import utils
+
+BLAZE_BUILD_DIR = join(gmscore_data.V10_BASE,
+    'blaze-out/intel-linux-android-4.8-libcxx-x86-opt/bin/java/com/google/'
+    'android/gmscore/integ')
+PROGUARDED_OUTPUT = join(BLAZE_BUILD_DIR,
+    'GmsCore_prod_alldpi_release_all_locales_proguard.jar')
+GMSCORE_SEEDS_FILE = join(BLAZE_BUILD_DIR,
+    'GmsCore_prod_alldpi_release_all_locales_proguard.seeds')
+DX_EXECUTABLE = join(utils.REPO_ROOT, 'tools/linux/dx/bin/dx')
+
+def parse_arguments():
+  parser = argparse.ArgumentParser(
+      description = 'Run ProGuard and the DX tool on GmsCore V10.')
+  parser.add_argument('--out',
+      help = 'Output directory for the DX tool.',
+      default = os.getcwd())
+  parser.add_argument('--print-runtimeraw',
+      metavar = 'BENCHMARKNAME',
+      help = 'Prints the line \'<BENCHMARKNAME>(RunTimeRaw): <elapsed>' +
+             ' ms\' at the end where <elapsed> is the elapsed time in' +
+             ' milliseconds.')
+  return parser.parse_args()
+
+def Main():
+  options = parse_arguments()
+
+  outdir = options.out
+
+  args = ['-forceprocessing']
+
+  if not outdir.endswith('.zip') and not outdir.endswith('.jar') \
+      and not exists(outdir):
+    makedirs(outdir)
+
+  version = gmscore_data.VERSIONS['v10']
+  values = version['deploy']
+  assert 'pgconf' in values
+
+  for pgconf in values['pgconf']:
+    args.extend(['@' + pgconf])
+
+  # Remove write-protection from seeds file. The seeds file is an output of
+  # ProGuard so it aborts if this is not writeable.
+  st = os.stat(GMSCORE_SEEDS_FILE)
+  os.chmod(GMSCORE_SEEDS_FILE,
+      st.st_mode | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
+
+  t0 = time.time()
+
+  proguard.run(args)
+
+  # run dex on the result
+  check_call([DX_EXECUTABLE, '-JXmx5256M', '--multi-dex', '--output=' + outdir,
+      '--dex', PROGUARDED_OUTPUT])
+
+  if options.print_runtimeraw:
+    print('{}(RunTimeRaw): {} ms'
+        .format(options.print_runtimeraw, 1000.0 * (time.time() - t0)))
+
+if __name__ == '__main__':
+  sys.exit(Main())