Tools: Switch from JAR-per-tool to a single swiss army knife

Introduce SwissArmyKnife entrypoint that defers to the different
entrypoints based on the first argument, defaulting to R8.main()
if the first argument is not recognized as the name of a tool.

In build.gradle, change tasks for D8, CompatDx and CompatProguard
to simply repackaging the R8 JAR but with a different Main-Class.
Remove gradle tasks for DexFileMerger, DexSplitter, D8Logger, disasm,
bisect, DexSegments, maindex, ExtractMarker, jardiff.

Introduce toolhelper.py with a run() method that runs the swiss army
knife. Change r8.py, d8.py, compatdx.py nad bisect.py to use
toolhelper.run(), and add Python scripts compatproguard, d8logger,
dexfilemerger, dexsegments, dexsplitter, disasm, extractmarker, jardiff,
maindex that use toolhelper.run().

Make archive.py use subprocess.check_output() directly instead of going
through r8.run() and d8.run() to get the versions.

Simplify run_on_app.py a bit by using toolhelper.run().

Change-Id: I752705188e728d2c4f7bfdc61b90448298eaa5bd
diff --git a/tools/d8.py b/tools/d8.py
index bf97845..18a4a67 100755
--- a/tools/d8.py
+++ b/tools/d8.py
@@ -3,46 +3,8 @@
 # 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.
 
-import gradle
-import os
-import subprocess
 import sys
-import utils
-
-def run(args, build=True, debug=True, profile=False,
-        track_memory_file=None):
-  if build:
-    gradle.RunGradle(['D8'])
-  cmd = []
-  if track_memory_file:
-    cmd.extend(['tools/track_memory.sh', track_memory_file])
-  cmd.append('java')
-  if debug:
-    cmd.append('-ea')
-  if profile:
-    cmd.append('-agentlib:hprof=cpu=samples,interval=1,depth=8')
-  cmd.extend(['-jar', utils.D8_JAR])
-  cmd.extend(args)
-  utils.PrintCmd(cmd)
-  result = subprocess.check_output(cmd)
-  print(result)
-  return result
-
-def main():
-  build = True
-  args = []
-  for arg in sys.argv[1:]:
-    if arg in ("--build", "--no-build"):
-      build = arg == "--build"
-    else:
-      args.append(arg)
-  try:
-    run(args, build)
-  except subprocess.CalledProcessError as e:
-    # In case anything relevant was printed to stdout, normally this is already
-    # on stderr.
-    print(e.output)
-    return e.returncode
+import toolhelper
 
 if __name__ == '__main__':
-  sys.exit(main())
+  sys.exit(toolhelper.run('d8', sys.argv[1:]))