Archive script: build  r8-ed r8 without dependencies.

- Also rename current r8-exclude-deps.jar
  -> r8-full-exclude-deps.jar

Change-Id: I7c1445732bddb92f050ade0bb24a4ae3aa827e5b
diff --git a/build.gradle b/build.gradle
index 0163c2e..ec00f11 100644
--- a/build.gradle
+++ b/build.gradle
@@ -603,7 +603,7 @@
 }
 
 task R8R8(type: Exec) {
-    def pgconf = "pgconfs/r8.cfg"
+    def pgconf = "src/main/keep.txt"
     def output = "build/libs/r8-r8.jar"
     inputs.files files(pgconf, "build/libs/r8.jar")
     outputs.file output
@@ -614,7 +614,7 @@
 }
 
 task D8R8(type: Exec) {
-    def pgconf = "pgconfs/d8.cfg"
+    def pgconf = "src/main/keep.txt"
     def output = "build/libs/d8-r8.jar"
     inputs.files files(pgconf, "build/libs/d8.jar")
     outputs.file output
@@ -625,7 +625,7 @@
 }
 
 task CompatDxR8(type: Exec) {
-    def pgconf = "pgconfs/compatdx.cfg"
+    def pgconf = "src/main/keep-compatdx.txt"
     def output = "build/libs/compatdx-r8.jar"
     inputs.files files(pgconf, "build/libs/compatdx.jar")
     outputs.file output
@@ -636,7 +636,7 @@
 }
 
 task CompatProguardR8(type: Exec) {
-    def pgconf = "pgconfs/compatproguard.cfg"
+    def pgconf = "src/main/keep-compatproguard.txt"
     def output = "build/libs/compatproguard-r8.jar"
     inputs.files files(pgconf, "build/libs/compatproguard.jar")
     outputs.file output
diff --git a/pgconfs/d8.cfg b/pgconfs/d8.cfg
deleted file mode 100644
index 2d74e47..0000000
--- a/pgconfs/d8.cfg
+++ /dev/null
@@ -1,6 +0,0 @@
-# Copyright (c) 2018, 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.
-
--keep @com.android.tools.r8.Keep class * { public *; }
--keep @com.android.tools.r8.KeepForSubclassing class * { public *; protected *; }
diff --git a/pgconfs/r8.cfg b/pgconfs/r8.cfg
deleted file mode 100644
index d1ae99b..0000000
--- a/pgconfs/r8.cfg
+++ /dev/null
@@ -1,7 +0,0 @@
-# Copyright (c) 2018, 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.
-
--keep public class com.android.tools.r8.SwissArmyKnife { public static void main(java.lang.String[]); }
--keep @com.android.tools.r8.Keep class * { public *; }
--keep @com.android.tools.r8.KeepForSubclassing class * { public *; protected *; }
diff --git a/pgconfs/compatdx.cfg b/src/main/keep-compatdx.txt
similarity index 100%
rename from pgconfs/compatdx.cfg
rename to src/main/keep-compatdx.txt
diff --git a/pgconfs/compatproguard.cfg b/src/main/keep-compatproguard.txt
similarity index 100%
rename from pgconfs/compatproguard.cfg
rename to src/main/keep-compatproguard.txt
diff --git a/src/main/keep.txt b/src/main/keep.txt
index 2d74e47..0d3812c 100644
--- a/src/main/keep.txt
+++ b/src/main/keep.txt
@@ -4,3 +4,11 @@
 
 -keep @com.android.tools.r8.Keep class * { public *; }
 -keep @com.android.tools.r8.KeepForSubclassing class * { public *; protected *; }
+
+-keep public class com.android.tools.r8.D8 { public static void main(java.lang.String[]); }
+-keep public class com.android.tools.r8.R8 { public static void main(java.lang.String[]); }
+-keep public class com.android.tools.r8.ExtractMarker { public static void main(java.lang.String[]); }
+-keep public class com.android.tools.r8.compatdexbuilder.CompatDexBuilder { public static void main(java.lang.String[]); }
+-keep public class com.android.tools.r8.compatdx.CompatDx { public static void main(java.lang.String[]); }
+-keep public class com.android.tools.r8.dexfilemerger.DexFileMerger { public static void main(java.lang.String[]); }
+-keep public class com.android.tools.r8.dexsplitter.DexSplitter { public static void main(java.lang.String[]); }
diff --git a/tools/archive.py b/tools/archive.py
index 0fa811b..8b70d86 100755
--- a/tools/archive.py
+++ b/tools/archive.py
@@ -12,6 +12,7 @@
 import toolhelper
 import utils
 import zipfile
+from build_r8lib import build_r8lib
 
 ARCHIVE_BUCKET = 'r8-releases'
 
@@ -80,12 +81,17 @@
 def Main():
   if not 'BUILDBOT_BUILDERNAME' in os.environ:
     raise Exception('You are not a bot, don\'t archive builds')
-  # Create maven release first which uses a build that exclude dependencies.
+
+  # 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.R8_KEEP_RULES, utils.R8_EXCLUDE_DEPS_JAR)
+
+  # Create maven release which uses a build that exclude dependencies.
   create_maven_release.main(["--out", utils.LIBS])
 
-  # Generate and copy the build that exclude dependencies.
+  # Generate and copy a full build without dependencies.
   gradle.RunGradleExcludeDeps([utils.R8, utils.R8_SRC])
-  shutil.copyfile(utils.R8_JAR, utils.R8_EXCLUDE_DEPS_JAR)
+  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
@@ -113,6 +119,7 @@
     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,
diff --git a/tools/utils.py b/tools/utils.py
index 18f8870..d2c4935 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -40,6 +40,7 @@
 R8R8_JAR = os.path.join(LIBS, 'r8-r8.jar')
 R8_SRC_JAR = os.path.join(LIBS, 'r8-src.jar')
 R8_EXCLUDE_DEPS_JAR = os.path.join(LIBS, 'r8-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')
 COMPATPROGUARD_JAR = os.path.join(LIBS, 'compatproguard.jar')