Prepare R8-ed targets for AOSP and Studio releases.

Change-Id: Ic0cb1a1e5507722a6b875859ecdf2e52fa02ecdc
diff --git a/build.gradle b/build.gradle
index 64f09d7..759e475 100644
--- a/build.gradle
+++ b/build.gradle
@@ -602,45 +602,31 @@
         "--pg-conf", pgconf]
 }
 
-task R8R8(type: Exec) {
+task R8Lib(type: Exec) {
     def pgconf = "src/main/keep.txt"
-    def output = "build/libs/r8-r8.jar"
-    inputs.files files(pgconf, "build/libs/r8.jar")
+    def output = "build/libs/r8lib.jar"
+    inputs.files files(pgconf, R8.outputs)
     outputs.file output
-    dependsOn R8
     dependsOn downloadOpenJDKrt
     commandLine r8CfCommandLine(R8.outputs.files[0], output, pgconf)
     workingDir = projectDir
 }
 
-task D8R8(type: Exec) {
-    def pgconf = "src/main/keep.txt"
-    def output = "build/libs/d8-r8.jar"
-    inputs.files files(pgconf, "build/libs/d8.jar")
-    outputs.file output
-    dependsOn downloadOpenJDKrt
-    dependsOn D8
-    commandLine r8CfCommandLine(R8.outputs.files[0], output, pgconf)
-    workingDir = projectDir
-}
-
-task CompatDxR8(type: Exec) {
+task CompatDxLib(type: Exec) {
     def pgconf = "src/main/keep-compatdx.txt"
-    def output = "build/libs/compatdx-r8.jar"
-    inputs.files files(pgconf, "build/libs/compatdx.jar")
+    def output = "build/libs/compatdxlib.jar"
+    inputs.files files(pgconf, CompatDx.outputs, R8.outputs)
     outputs.file output
-    dependsOn CompatDx
     dependsOn downloadOpenJDKrt
     commandLine r8CfCommandLine(R8.outputs.files[0], output, pgconf)
     workingDir = projectDir
 }
 
-task CompatProguardR8(type: Exec) {
+task CompatProguardLib(type: Exec) {
     def pgconf = "src/main/keep-compatproguard.txt"
-    def output = "build/libs/compatproguard-r8.jar"
-    inputs.files files(pgconf, "build/libs/compatproguard.jar")
+    def output = "build/libs/compatproguardlib.jar"
+    inputs.files files(pgconf, CompatProguard.outputs, R8.outputs)
     outputs.file output
-    dependsOn CompatProguard
     dependsOn downloadOpenJDKrt
     commandLine r8CfCommandLine(R8.outputs.files[0], output, pgconf)
     workingDir = projectDir
diff --git a/tools/archive.py b/tools/archive.py
index 1a5de28..302b0ff 100755
--- a/tools/archive.py
+++ b/tools/archive.py
@@ -84,7 +84,8 @@
 
   # Generate an r8-ed build without dependencies.
   # Note: build_r8lib does a gradle-clean, this must be the first command.
-  build_r8lib('r8', True, True, utils.R8LIB_KEEP_RULES, utils.R8_EXCLUDE_DEPS_JAR)
+  build_r8lib('r8', True, True, utils.R8LIB_KEEP_RULES,
+    utils.R8LIB_EXCLUDE_DEPS_JAR)
 
   # Create maven release which uses a build that exclude dependencies.
   create_maven_release.main(["--out", utils.LIBS])
@@ -94,10 +95,17 @@
   shutil.copyfile(utils.R8_JAR, utils.R8_FULL_EXCLUDE_DEPS_JAR)
 
   # Ensure all archived artifacts has been built before archiving.
-  # The target tasks postfixed by 'r8' depend on the actual target task so
+  # The target tasks postfixed by 'lib' depend on the actual target task so
   # building it invokes the original task first.
-  gradle.RunGradle(map((lambda t: t + 'r8'),
-    [utils.D8, utils.R8, utils.COMPATDX, utils.COMPATPROGUARD]))
+  gradle.RunGradle([
+    utils.R8,
+    utils.D8,
+    utils.COMPATDX,
+    utils.COMPATPROGUARD,
+    utils.R8LIB,
+    utils.COMPATDXLIB,
+    utils.COMPATPROGUARDLIB,
+  ])
   version = GetVersion()
   is_master = IsMaster(version)
   if is_master:
@@ -116,15 +124,20 @@
           'releaser=go/r8bot (' + os.environ.get('BUILDBOT_SLAVENAME') + ')\n')
       version_writer.write('version-file.version.code=1\n')
 
-    for file in [utils.D8_JAR, utils.D8R8_JAR,
-                 utils.R8_JAR, utils.R8R8_JAR,
-                 utils.R8_SRC_JAR,
-                 utils.R8_FULL_EXCLUDE_DEPS_JAR,
-                 utils.R8_EXCLUDE_DEPS_JAR,
-                 utils.COMPATDX_JAR, utils.COMPATDXR8_JAR,
-                 utils.COMPATPROGUARD_JAR, utils.COMPATPROGUARDR8_JAR,
-                 utils.MAVEN_ZIP,
-                 utils.GENERATED_LICENSE]:
+    for file in [
+      utils.D8_JAR,
+      utils.R8_JAR,
+      utils.R8LIB_JAR,
+      utils.R8_SRC_JAR,
+      utils.R8_FULL_EXCLUDE_DEPS_JAR,
+      utils.R8LIB_EXCLUDE_DEPS_JAR,
+      utils.COMPATDX_JAR,
+      utils.COMPATDXLIB_JAR,
+      utils.COMPATPROGUARD_JAR,
+      utils.COMPATPROGUARDLIB_JAR,
+      utils.MAVEN_ZIP,
+      utils.GENERATED_LICENSE,
+    ]:
       file_name = os.path.basename(file)
       tagged_jar = os.path.join(temp, file_name)
       shutil.copyfile(file, tagged_jar)
diff --git a/tools/update_prebuilds_in_android.py b/tools/update_prebuilds_in_android.py
index 490a132..b19ecb0 100755
--- a/tools/update_prebuilds_in_android.py
+++ b/tools/update_prebuilds_in_android.py
@@ -15,7 +15,24 @@
 BUILD_ROOT = "http://storage.googleapis.com/r8-releases/raw/"
 MASTER_BUILD_ROOT = "%smaster/" % BUILD_ROOT
 
-JAR_TARGETS = [utils.D8, utils.R8, utils.COMPATDX, utils.COMPATPROGUARD]
+JAR_TARGETS = [
+  utils.D8,
+  utils.R8,
+  utils.COMPATDX,
+  utils.COMPATPROGUARD,
+  utils.R8LIB,
+  utils.COMPATDXLIB,
+  utils.COMPATPROGUARDLIB,
+]
+JAR_FILES = [
+  utils.D8_JAR,
+  utils.R8_JAR,
+  utils.COMPATDX_JAR,
+  utils.COMPATPROGUARD_JAR,
+  utils.R8LIB_JAR,
+  utils.COMPATDXLIB_JAR,
+  utils.COMPATPROGUARDLIB_JAR,
+]
 OTHER_TARGETS = ["LICENSE"]
 
 def parse_arguments():
@@ -28,6 +45,7 @@
   return parser.parse_args()
 
 def copy_targets(root, target_root, srcs, dests):
+  assert len(srcs) == len(dests)
   for i in range(len(srcs)):
     src = os.path.join(root, srcs[i])
     dest = os.path.join(target_root, 'prebuilts', 'r8', dests[i])
@@ -35,8 +53,16 @@
     copyfile(src, dest)
 
 def copy_jar_targets(root, target_root):
-  srcs = map((lambda t: t + '.jar'), JAR_TARGETS)
-  dests = map((lambda t: t + '-master.jar'), JAR_TARGETS)
+  srcs = JAR_FILES
+  dests = [
+    'd8-master.jar',
+    'r8-master.jar',
+    'compatdx-master.jar',
+    'compatproguard-master.jar',
+    'r8lib-master.jar',
+    'compatdxlib-master.jar',
+    'compatproguardlib-master.jar',
+  ]
   copy_targets(root, target_root, srcs, dests)
 
 def copy_other_targets(root, target_root):
@@ -61,12 +87,12 @@
   args = parse_arguments()
   target_root = args.android_root[0]
   if args.commit_hash == None and args.version == None:
-    gradle.RunGradle(map((lambda t: t), JAR_TARGETS))
+    gradle.RunGradle(JAR_TARGETS)
     copy_jar_targets(utils.LIBS, target_root)
     copy_other_targets(utils.GENERATED_LICENSE_DIR, target_root)
   else:
     assert args.commit_hash == None or args.version == None
-    targets = map((lambda t: t + '.jar'), JAR_TARGETS) + OTHER_TARGETS
+    targets = JAR_FILES + OTHER_TARGETS
     with utils.TempDir() as root:
       for target in targets:
         if args.commit_hash:
diff --git a/tools/utils.py b/tools/utils.py
index 5355ba8..83a6478 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -30,21 +30,23 @@
 
 D8 = 'd8'
 R8 = 'r8'
+R8LIB = 'r8lib'
 R8_SRC = 'sourceJar'
 COMPATDX = 'compatdx'
+COMPATDXLIB = 'compatdxlib'
 COMPATPROGUARD = 'compatproguard'
+COMPATPROGUARDLIB = 'compatproguardlib'
 
 D8_JAR = os.path.join(LIBS, 'd8.jar')
-D8R8_JAR = os.path.join(LIBS, 'd8-r8.jar')
 R8_JAR = os.path.join(LIBS, 'r8.jar')
-R8R8_JAR = os.path.join(LIBS, 'r8-r8.jar')
+R8LIB_JAR = os.path.join(LIBS, 'r8lib.jar')
 R8_SRC_JAR = os.path.join(LIBS, 'r8-src.jar')
-R8_EXCLUDE_DEPS_JAR = os.path.join(LIBS, 'r8-exclude-deps.jar')
+R8LIB_EXCLUDE_DEPS_JAR = os.path.join(LIBS, 'r8lib-exclude-deps.jar')
 R8_FULL_EXCLUDE_DEPS_JAR = os.path.join(LIBS, 'r8-full-exclude-deps.jar')
 COMPATDX_JAR = os.path.join(LIBS, 'compatdx.jar')
-COMPATDXR8_JAR = os.path.join(LIBS, 'compatdx-r8.jar')
+COMPATDXLIB_JAR = os.path.join(LIBS, 'compatdxlib.jar')
 COMPATPROGUARD_JAR = os.path.join(LIBS, 'compatproguard.jar')
-COMPATPROGUARDR8_JAR = os.path.join(LIBS, 'compatproguard-r8.jar')
+COMPATPROGUARDLIB_JAR = os.path.join(LIBS, 'compatproguardlib.jar')
 MAVEN_ZIP = os.path.join(LIBS, 'r8.zip')
 GENERATED_LICENSE = os.path.join(GENERATED_LICENSE_DIR, 'LICENSE')
 RT_JAR = os.path.join(REPO_ROOT, 'third_party/openjdk/openjdk-rt-1.8/rt.jar')