Update AOSP tools

* Share common code
* Make the --aosp-root default to build/aosp in the R8 checkout

Change-Id: Ia76aad590f079b852bfa8f581f73082da571de68
diff --git a/tools/utils_aosp.py b/tools/utils_aosp.py
new file mode 100644
index 0000000..8f20c2f
--- /dev/null
+++ b/tools/utils_aosp.py
@@ -0,0 +1,32 @@
+#!/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 os
+
+import utils
+
+AOSP_HELPER_SH = join(utils.REPO_ROOT, 'scripts', 'aosp_helper.sh')
+
+DEFAULT_LUNCH = 'aosp_x86-eng'
+
+DEFAULT_ROOT = join(utils.REPO_ROOT, 'build', 'aosp')
+
+def add_common_arguments(parser):
+  parser.add_argument('--aosp-root',
+      help='Root of the AOSP checkout. ' +
+           'Defaults to ' +  DEFAULT_ROOT +'.',
+      default=DEFAULT_ROOT)
+  parser.add_argument('--lunch',
+      help='Build menu. ' +
+           'Defaults to ' + DEFAULT_LUNCH + '.',
+      default=DEFAULT_LUNCH)
+
+def run_through_aosp_helper(lunch, args, cwd):
+  args[0:0] = [AOSP_HELPER_SH, lunch]
+  check_call(args, cwd = cwd)