Update AOSP reference

This updates the pinned AOSP to a version where USE_D8 is used for building
with d8.

Updates the related scripts.

Bug: 65865951
Change-Id: I9a7251855ad1079752dfa5f63bd9b8e2df221d01
diff --git a/tools/build_aosp.py b/tools/build_aosp.py
index 0079554..b62ec02 100755
--- a/tools/build_aosp.py
+++ b/tools/build_aosp.py
@@ -26,7 +26,7 @@
       description = 'Checkout the AOSP source tree.')
   utils_aosp.add_common_arguments(parser)
   parser.add_argument('--tool',
-      choices = ['jack', 'd8', 'r8', 'default'],
+      choices = ['d8', 'r8', 'default'],
       default = 'd8',
       help='Compiler tool to use. Defaults to d8.')
   parser.add_argument('--mmm',
@@ -35,130 +35,51 @@
   parser.add_argument('--mmma',
       action = 'store_true',
       help='Use mmma instead of make')
-  parser.add_argument('--rebuild-system-image-after-mmm',
+  parser.add_argument('--show-commands',
       action = 'store_true',
-      help='Build the system image after building a package with mmm or mmma')
-  parser.add_argument('--clean-dex',
-      action = 'store_true',
-      help = 'Remove all dex files before the build. By default they'
-      " are removed only if '--tool=d8' and if they are older than the D8 tool")
+      help='Show commands executed during build.')
   parser.add_argument('-j',
       help='Projects to fetch simultaneously. ' +
       'Defaults to ' + str(J_DEFAULT) + '.',
       type=int,
-      default=J_DEFAULT)
+      default=-1)
   parser.add_argument('target', nargs='?')
   return parser.parse_args()
 
-def setup_and_clean_dex(aosp_root, tool, clean_dex):
-  print "Running AOSP build in " + aosp_root
+def build_aosp(aosp_root, lunch, make, tool,
+               concurrency, target, show_commands):
+  d8_option = 'USE_D8=false'
+  if tool == 'd8' or tool == 'r8' :
+    d8_option = 'USE_D8=true'
 
-  out = join(aosp_root, 'out')
-  utils.makedirs_if_needed(out)
-
-  # remove dex files older than the current d8 tool
-  counter = 0
-  if tool == 'd8' or clean_dex:
-    if not clean_dex:
-      d8jar_mtime = os.path.getmtime(utils.D8_JAR)
-    dex_files = (chain.from_iterable(glob(join(x[0], '*.dex'))
-      for x in os.walk(out)))
-    for f in dex_files:
-      if clean_dex or os.path.getmtime(f) <= d8jar_mtime:
-        os.remove(f)
-        counter += 1
-  if counter > 0:
-    print('Removed {} dex files.'.format(counter))
-
-PROGUARD_SCRIPT = """#!/bin/sh
-#
-# Start-up script for ProGuard -- free class file shrinker, optimizer,
-# obfuscator, and preverifier for Java bytecode.
-#
-# Note: when passing file names containing spaces to this script,
-#       you\'ll have to add escaped quotes around them, e.g.
-#       "\"/My Directory/My File.txt\""
-
-# Account for possibly missing/basic readlink.
-# POSIX conformant (dash/ksh/zsh/bash).
-PROGUARD=`readlink -f "$0" 2>/dev/null`
-if test "$PROGUARD" = \'\'
-then
-  PROGUARD=`readlink "$0" 2>/dev/null`
-  if test "$PROGUARD" = \'\'
-  then
-    PROGUARD="$0"
-  fi
-fi
-
-PROGUARD_HOME=`dirname "$PROGUARD"`/..
-
-# BEGIN android-changed Added -Xmx2G for Mac builds
-java -Xmx2G -jar "$PROGUARD_HOME/lib/proguard.jar" "$@"
-# END android-changed
-"""
-
-def prepare_for_proguard(aosp_root):
-  # Write the default proguard.sh script.
-  proguard_script = join(aosp_root, 'external', 'proguard', 'bin', 'proguard.sh')
-  with open(proguard_script, 'w') as f:
-    f.write(PROGUARD_SCRIPT)
-
-  os.chmod(proguard_script, S_IRWXU)
-
-def prepare_for_r8(aosp_root):
-  # Write the proguard.sh script invoking R8.
-  compat_proguard_jar = join(
-      utils.REPO_ROOT, 'build', 'libs', 'compatproguard.jar')
-  proguard_script = join(aosp_root, 'external', 'proguard', 'bin', 'proguard.sh')
-  with open(proguard_script, 'w') as f:
-    f.write('java -jar ' + compat_proguard_jar + ' "$@" --min-api 10000')
-  os.chmod(proguard_script, S_IRWXU)
-
-def build_aosp(aosp_root, lunch, make, tool, concurrency, target):
-  jack_option = 'ANDROID_COMPILE_WITH_JACK=' \
-      + ('true' if tool == 'jack' else 'false')
-
-  # DX_ALT_JAR need to be cleared if not set, for 'make' to work properly
-  alt_jar_option = 'DX_ALT_JAR='
-  if tool == 'd8':
-    alt_jar_option += utils.COMPATDX_JAR
-
+  r8_option = 'USE_R8=false'
   if tool == 'r8':
-    prepare_for_r8(aosp_root)
-    # Use D8 compatdx dexer with hack for forwarding the R8 dex file.
-    alt_jar_option += utils.COMPATDX_JAR
-  else:
-    prepare_for_proguard(aosp_root)
+    r8_option = 'USE_R8=true'
 
-  j_option = '-j' + str(concurrency);
-  print("-- Building Android image with '{} {} {} {}'." \
-    .format(make, j_option, jack_option, alt_jar_option))
+  j_option = '-j'
+  if concurrency > 0:
+    j_option += str(concurrency)
 
-  command = [make, j_option, jack_option, alt_jar_option]
+  command = [make, j_option]
+  if show_commands:
+    command.append('showcommands')
+  command.extend([d8_option, r8_option])
   if target:
     command.append(target)
 
+  print 'Building using: ' + ' '.join(command)
   utils_aosp.run_through_aosp_helper(lunch, command, aosp_root)
 
 def Main():
   args = parse_arguments()
 
-  # Build the required tools.
-  if args.tool == 'd8' or args.tool == 'r8':
-    gradle.RunGradle(['d8', 'r8', 'compatdx', 'compatproguard'])
-
-  setup_and_clean_dex(args.aosp_root, args.tool, args.clean_dex)
-
-  make = 'make'
+  make = 'm'
   if args.mmm:
     make = 'mmm'
   if args.mmma:
     make = 'mmma'
-  build_aosp(args.aosp_root, args.lunch, make, args.tool, args.j, args.target)
-  # Call make to re-build the system image if requested.
-  if args.rebuild_system_image_after_mmm and (args.mmm or args.mmma):
-    build_aosp(args.aosp_root, args.lunch, 'make', 'd8', args.j, None)
+  build_aosp(args.aosp_root, args.lunch, make, args.tool,
+             args.j, args.target, args.show_commands)
 
 if __name__ == '__main__':
   sys.exit(Main())
diff --git a/tools/checkout_aosp.py b/tools/checkout_aosp.py
index 842ae3b..268b1b3 100755
--- a/tools/checkout_aosp.py
+++ b/tools/checkout_aosp.py
@@ -17,13 +17,14 @@
 AOSP_MANIFEST_XML = join(utils.REPO_ROOT, 'third_party',
   'aosp_manifest.xml')
 AOSP_MANIFEST_URL = 'https://android.googlesource.com/platform/manifest'
-
 J_DEFAULT = multiprocessing.cpu_count() - 2
 
 # Checkout AOSP source to the specified direcotry using the speficied manifest.
-def checkout_aosp(aosp_root, url, branch, manifest_xml, concurrency):
+def checkout_aosp(aosp_root, url, branch, manifest_xml, concurrency, shallow):
   utils.makedirs_if_needed(aosp_root)
-  command = ['repo', 'init', '-u', url, '--depth=1']
+  command = ['repo', 'init', '-u', url]
+  if (shallow):
+    command.extend(['--depth=1'])
   if (branch):
     command.extend(['-b', branch])
   else:
@@ -50,6 +51,9 @@
   parser.add_argument('--branch',
                       help='Branch to checkout. This overrides ' +
                            'passing --manifest')
+  parser.add_argument('--shallow',
+                      action = 'store_true',
+                      help='Shallow checkout.')
   parser.add_argument('-j',
                       help='Projects to fetch simultaneously. ' +
                            'Defaults to ' + str(J_DEFAULT) + '.',
@@ -58,7 +62,8 @@
 
 def Main():
   args = parse_arguments()
-  checkout_aosp(args.aosp_root, args.url, args.branch, args.manifest, args.j)
+  checkout_aosp(args.aosp_root, args.url, args.branch, args.manifest,
+                args.j, args.shallow)
 
 if __name__ == '__main__':
   sys.exit(Main())
diff --git a/tools/test_android_cts.py b/tools/test_android_cts.py
index ccb762b..c07a4a0 100755
--- a/tools/test_android_cts.py
+++ b/tools/test_android_cts.py
@@ -40,8 +40,6 @@
   'aosp_manifest.xml')
 AOSP_HELPER_SH = join(utils.REPO_ROOT, 'scripts', 'aosp_helper.sh')
 
-D8LOGGER_JAR = join(utils.REPO_ROOT, 'build/libs/d8logger.jar')
-
 AOSP_ROOT = join(utils.REPO_ROOT, 'build/aosp')
 
 AOSP_MANIFEST_URL = 'https://android.googlesource.com/platform/manifest'
@@ -54,8 +52,8 @@
 CTS_TRADEFED = join(OUT_CTS,
   'host/linux-x86/cts/android-cts/tools/cts-tradefed')
 
-J_DEFAULT = '8'
-J_OPTION = '-j' + J_DEFAULT
+J_DEFAULT = 8
+J_OPTION = '-j' + str(J_DEFAULT)
 
 EXIT_FAILURE = 1
 
@@ -64,13 +62,9 @@
       description = 'Download the AOSP source tree, build an Android image'
       ' and the CTS targets and run CTS with the emulator on the image.')
   parser.add_argument('--tool',
-      choices = ['jack', 'dx', 'd8'],
+      choices = ['dx', 'd8'],
       default = 'd8',
       help='compiler tool to use')
-  parser.add_argument('--d8log',
-      metavar = 'FILE',
-      help = 'Enable logging d8 (compatdx) calls to the specified file. Works'
-          ' only with --tool=d8')
   parser.add_argument('--save-result',
       metavar = 'FILE',
       help = 'Save final test_result.xml to the specified file.')
@@ -147,30 +141,18 @@
 def Main():
   args = parse_arguments()
 
-  if args.d8log and args.tool != 'd8':
-    print("The '--d8log' option works only with '--tool=d8'.",
-        file = sys.stderr)
-    return EXIT_FAILURE
+  assert args.tool in ['dx', 'd8']
 
-  assert args.tool in ['jack', 'dx', 'd8']
-
-  jack_option = 'ANDROID_COMPILE_WITH_JACK=' \
-      + ('true' if args.tool == 'jack' else 'false')
-
-  # DX_ALT_JAR need to be cleared if not set, for 'make' to work properly
-  alt_jar_option = 'DX_ALT_JAR='
+  use_d8 = 'USE_D8=false'
   if args.tool == 'd8':
-    if args.d8log:
-      alt_jar_option += D8LOGGER_JAR
-      os.environ['D8LOGGER_OUTPUT'] = args.d8log
-    else:
-      alt_jar_option += utils.COMPATDX_JAR
+    use_d8 = 'USE_D8=true'
 
-  gradle.RunGradle(['d8','d8logger', 'compatdx'])
+  gradle.RunGradle(['d8', 'compatdx'])
 
   setup_and_clean(args.tool == 'd8', args.clean_dex)
 
-  checkout_aosp.checkout_aosp(AOSP_ROOT, AOSP_MANIFEST_XML, J_DEFAULT)
+  checkout_aosp.checkout_aosp("test", AOSP_MANIFEST_URL, None,
+                              AOSP_MANIFEST_XML, str(J_DEFAULT), True)
 
   # activate OUT_CTS and build Android CTS
   # AOSP has no clean way to set the output directory.
@@ -189,11 +171,11 @@
   # activate OUT_IMG and build the Android image
   if not remove_aosp_out():
     return EXIT_FAILURE
-  print("-- Building Android image with 'make {} {} {}'." \
-    .format(J_OPTION, jack_option, alt_jar_option))
+  print("-- Building Android image with 'make {} {}'." \
+    .format(J_OPTION, use_d8))
   os.symlink(OUT_IMG, AOSP_OUT)
-  check_call([AOSP_HELPER_SH, AOSP_PRESET, 'make', J_OPTION, jack_option,
-      alt_jar_option], cwd = AOSP_ROOT)
+  check_call([AOSP_HELPER_SH, AOSP_PRESET, 'make', J_OPTION,
+      use_d8_option], cwd = AOSP_ROOT)
 
   emulator_proc = Popen([AOSP_HELPER_SH, AOSP_PRESET,
       'emulator', '-partition-size', '4096', '-wipe-data'], cwd = AOSP_ROOT)