Add tools to build AOSP and to run the emulator

This makes it easier to work with an AOSP checkout inside a R8 checkout
without having to do all the AOSP setup and build magic manually.

Based on the code already in tools/test_android_cts.py.

Change-Id: I65f43e178afe1ca2db4d407a777107b785229c80
diff --git a/tools/emulator_aosp.py b/tools/emulator_aosp.py
new file mode 100755
index 0000000..90a6000
--- /dev/null
+++ b/tools/emulator_aosp.py
@@ -0,0 +1,41 @@
+#!/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.
+
+from os.path import join
+from subprocess import check_call
+import argparse
+import os
+import sys
+
+import utils
+
+AOSP_HELPER_SH = join(utils.REPO_ROOT, 'scripts', 'aosp_helper.sh')
+
+DEFAULT_LUNCH = 'aosp_x86-eng'
+
+def parse_arguments():
+  parser = argparse.ArgumentParser(
+      description = 'Checkout the AOSP source tree.')
+  parser.add_argument('--aosp-root',
+                      help='Root of the AOSP checkout. ' +
+                           'Defaults to current working directory.',
+                      default=os.getcwd())
+  parser.add_argument('--lunch',
+                      help='Build menu. ' +
+                           'Defaults to ' + DEFAULT_LUNCH + '.',
+                      default=DEFAULT_LUNCH)
+  return parser.parse_args()
+
+def emulator_aosp(aosp_root, lunch):
+  check_call([AOSP_HELPER_SH, lunch,
+      'emulator_fg', '-partition-size', '4096', '-wipe-data'], cwd = aosp_root)
+
+def Main():
+  args = parse_arguments()
+
+  emulator_aosp(args.aosp_root, args.lunch)
+
+if __name__ == '__main__':
+  sys.exit(Main())