Fix testR8LibCompatibility by renaming dependency jar

Change-Id: Ie5bbb67e5a4da1945732c822762d9b0fb6497515
diff --git a/build.gradle b/build.gradle
index 496dc65..00b8a46 100644
--- a/build.gradle
+++ b/build.gradle
@@ -533,7 +533,7 @@
     mergeServiceFiles(it)
     exclude { it.getRelativePath().getPathString() == "module-info.class" }
     exclude { it.getRelativePath().getPathString().startsWith("META-INF/maven/") }
-    baseName 'deps_not_relocated'
+    baseName 'deps-not-relocated'
 }
 
 task repackageDeps(type: ShadowJar) {
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index 1a17a62..c9fe628 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -118,8 +118,9 @@
   public static final Path R8_JAR = Paths.get(LIBS_DIR, "r8.jar");
   public static final Path R8_WITH_RELOCATED_DEPS_JAR =
       Paths.get(LIBS_DIR, "r8_with_relocated_deps.jar");
-  public static final Path DEPS_NOT_RELOCATED =
-      Paths.get(LIBS_DIR, "deps_not_relocated.jar");
+  public static final Path R8LIB_JAR = Paths.get(LIBS_DIR, "r8lib.jar");
+  public static final Path R8LIB_EXCLUDE_DEPS_JAR = Paths.get(LIBS_DIR, "r8lib-exclude-deps.jar");
+  public static final Path DEPS_NOT_RELOCATED = Paths.get(LIBS_DIR, "deps-not-relocated.jar");
 
   public enum DexVm {
     ART_4_0_4_TARGET(Version.V4_0_4, Kind.TARGET),
@@ -782,6 +783,10 @@
     return System.getProperty("java.specification.version").equals("9");
   }
 
+  public static boolean isTestingR8Lib() {
+    return System.getProperty("java.class.path").contains("r8lib.jar");
+  }
+
   public static boolean artSupported() {
     if (!isLinux() && !isMac() && !isWindows()) {
       System.err.println("Testing on your platform is not fully supported. " +
diff --git a/src/test/java/com/android/tools/r8/cf/BootstrapCurrentEqualityTest.java b/src/test/java/com/android/tools/r8/cf/BootstrapCurrentEqualityTest.java
index 092d06e..03eaa28 100644
--- a/src/test/java/com/android/tools/r8/cf/BootstrapCurrentEqualityTest.java
+++ b/src/test/java/com/android/tools/r8/cf/BootstrapCurrentEqualityTest.java
@@ -9,6 +9,7 @@
 import static org.junit.Assert.assertEquals;
 
 import com.android.tools.r8.ArchiveClassFileProvider;
+import com.android.tools.r8.CompilationFailedException;
 import com.android.tools.r8.CompilationMode;
 import com.android.tools.r8.ExternalR8TestCompileResult;
 import com.android.tools.r8.OutputMode;
@@ -96,6 +97,34 @@
   }
 
   @Test
+  public void testR8LibCompatibility() throws IOException, CompilationFailedException {
+    // Produce r81 = R8Lib(R8WithDeps) and r82 = R8LibNoDeps + Deps(R8WithDeps) and test that r81 is
+    // equal to r82. This test should only run if we are testing r8lib and we expect both R8libs to
+    // be built by gradle. If we are not testing with R8Lib, do not run this test.
+    if (!ToolHelper.isTestingR8Lib()) {
+      return;
+    }
+    Path runR81 =
+        testForExternalR8(Backend.CF)
+            .useProvidedR8(ToolHelper.R8LIB_JAR)
+            .addProgramFiles(ToolHelper.R8_WITH_RELOCATED_DEPS_JAR)
+            .addKeepRuleFiles(MAIN_KEEP)
+            .setMode(CompilationMode.RELEASE)
+            .compile()
+            .outputJar();
+    Path runR82 =
+        testForExternalR8(Backend.CF)
+            .useProvidedR8(ToolHelper.R8LIB_EXCLUDE_DEPS_JAR)
+            .addR8ExternalDepsToClasspath()
+            .addProgramFiles(ToolHelper.R8_WITH_RELOCATED_DEPS_JAR)
+            .addKeepRuleFiles(MAIN_KEEP)
+            .setMode(CompilationMode.RELEASE)
+            .compile()
+            .outputJar();
+    assert filesAreEqual(runR81, runR82);
+  }
+
+  @Test
   public void test() throws Exception {
     Path helloJar = Paths.get(ToolHelper.EXAMPLES_BUILD_DIR, "hello" + JAR_EXTENSION);
     ProcessResult runResult = ToolHelper.runJava(helloJar, "hello.Hello");
diff --git a/tools/test.py b/tools/test.py
index 257e88c..f4cee88 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -123,9 +123,6 @@
   if utils.is_bot():
     gradle.RunGradle(['clean'])
 
-  # Build an R8 with dependencies for bootstrapping tests before adding test sources
-  gradle.RunGradle(['r8WithRelocatedDeps'])
-
   gradle_args = ['--stacktrace']
   # Set all necessary Gradle properties and options first.
   if options.verbose:
@@ -182,9 +179,15 @@
     exit(1)
   if not options.no_r8lib:
     gradle_args.append('-Pr8lib')
+    # Force gradle to build a version of r8lib without dependencies for
+    # BootstrapCurrentEqualityTest.
+    gradle_args.append('R8LibNoDeps')
   if options.r8lib_no_deps:
     gradle_args.append('-Pr8lib_no_deps')
 
+  # Build an R8 with dependencies for bootstrapping tests before adding test sources.
+  gradle_args.append('r8WithRelocatedDeps')
+
   # Add Gradle tasks
   gradle_args.append('cleanTest')
   gradle_args.append('test')