[KeepAnno] Add keep annotation to classpath for external runners

Change-Id: Ic2a549fbc6bd7bf47c8de398fa6f0af78943619f
diff --git a/src/test/java/com/android/tools/r8/ExternalR8TestBuilder.java b/src/test/java/com/android/tools/r8/ExternalR8TestBuilder.java
index 030ae56..52d8b52 100644
--- a/src/test/java/com/android/tools/r8/ExternalR8TestBuilder.java
+++ b/src/test/java/com/android/tools/r8/ExternalR8TestBuilder.java
@@ -16,6 +16,7 @@
 import com.android.tools.r8.utils.DescriptorUtils;
 import com.android.tools.r8.utils.FileUtils;
 import com.android.tools.r8.utils.InternalOptions;
+import com.android.tools.r8.utils.ListUtils;
 import com.google.common.base.Charsets;
 import java.io.IOException;
 import java.nio.file.Path;
@@ -37,7 +38,7 @@
         ExternalR8TestBuilder> {
 
   // The r8.jar to run.
-  private Path r8jar = ToolHelper.getR8MainPath();
+  private List<Path> r8Classpath = ToolHelper.getClasspathForR8();
 
   // Ordered list of program jar entries.
   private final List<Path> programJars = new ArrayList<>();
@@ -127,11 +128,15 @@
       Path outputJar = outputFolder.resolve("output.jar");
       Path proguardMapFile = outputFolder.resolve("output.jar.map");
 
-      String classPath =
-          addR8ExternalDeps
-              ? r8jar.toAbsolutePath() + CLASSPATH_SEPARATOR + ToolHelper.getDeps()
-              : r8jar.toAbsolutePath().toString();
+      List<Path> classpathList = new ArrayList<>(r8Classpath);
+      if (addR8ExternalDeps) {
+        classpathList.add(ToolHelper.getDeps());
+      }
 
+      String classPath =
+          String.join(
+              CLASSPATH_SEPARATOR,
+              ListUtils.map(classpathList, p -> p.toAbsolutePath().toString()));
       List<String> command = new ArrayList<>();
       if (runtime.isDex()) {
         throw new Unimplemented();
@@ -296,7 +301,7 @@
   }
 
   public ExternalR8TestBuilder useProvidedR8(Path r8jar) {
-    this.r8jar = r8jar;
+    this.r8Classpath = Collections.singletonList(r8jar);
     return self();
   }
 
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index 0831935..395f2ce 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -190,6 +190,10 @@
     return Paths.get(System.getProperty("KEEP_ANNO_JAVAC_BUILD_DIR").split(File.pathSeparator)[0]);
   }
 
+  public static List<Path> getClasspathForR8() {
+    return ImmutableList.of(getKeepAnnoPath(), getR8MainPath());
+  }
+
   public static final Path CHECKED_IN_R8_17_WITH_DEPS =
       Paths.get(THIRD_PARTY_DIR).resolve("r8").resolve("r8_with_deps_17.jar");
 
diff --git a/src/test/java/com/android/tools/r8/compilerapi/BinaryCompatibilityTestCollection.java b/src/test/java/com/android/tools/r8/compilerapi/BinaryCompatibilityTestCollection.java
index f39b8ba..dfa1e8d 100644
--- a/src/test/java/com/android/tools/r8/compilerapi/BinaryCompatibilityTestCollection.java
+++ b/src/test/java/com/android/tools/r8/compilerapi/BinaryCompatibilityTestCollection.java
@@ -44,8 +44,8 @@
  */
 public abstract class BinaryCompatibilityTestCollection<T> {
 
-  /** Jar to run tests against. */
-  public abstract Path getTargetJar();
+  /** Classpath to run tests against. */
+  public abstract List<Path> getTargetClasspath();
 
   /** Jar with tests. */
   public abstract Path getCheckedInTestJar();
@@ -103,7 +103,12 @@
     verifyConsistency();
     IntBox numberOfTestMethods = new IntBox(0);
     List<Path> classPaths =
-        ImmutableList.of(getJunitDependency(), getHamcrest(), getTargetJar(), testJar);
+        ImmutableList.<Path>builder()
+            .add(getJunitDependency())
+            .add(getHamcrest())
+            .addAll(getTargetClasspath())
+            .add(testJar)
+            .build();
     List<String> args = new ArrayList<>();
     args.add("org.junit.runner.JUnitCore");
     tests.forEach(
diff --git a/src/test/java/com/android/tools/r8/compilerapi/CompilerApiTestCollection.java b/src/test/java/com/android/tools/r8/compilerapi/CompilerApiTestCollection.java
index b1e473f..fb86105 100644
--- a/src/test/java/com/android/tools/r8/compilerapi/CompilerApiTestCollection.java
+++ b/src/test/java/com/android/tools/r8/compilerapi/CompilerApiTestCollection.java
@@ -111,10 +111,10 @@
     return BINARY_COMPATIBILITY_JAR;
   }
 
-  // The API tests always link against the jar that the test runner is using.
+  // The API tests always link against the classpath that the test runner is using.
   @Override
-  public Path getTargetJar() {
-    return ToolHelper.getR8MainPath();
+  public List<Path> getTargetClasspath() {
+    return ToolHelper.getClasspathForR8();
   }
 
   // Some tests expectations can depend on the lib/nonlib and internal/external behavior.
diff --git a/src/test/java/com/android/tools/r8/retrace/api/RetraceApiTestCollection.java b/src/test/java/com/android/tools/r8/retrace/api/RetraceApiTestCollection.java
index 97fc50e..36aa7ce 100644
--- a/src/test/java/com/android/tools/r8/retrace/api/RetraceApiTestCollection.java
+++ b/src/test/java/com/android/tools/r8/retrace/api/RetraceApiTestCollection.java
@@ -62,8 +62,8 @@
   }
 
   @Override
-  public Path getTargetJar() {
-    return ToolHelper.getRetracePath();
+  public List<Path> getTargetClasspath() {
+    return ImmutableList.of(ToolHelper.getRetracePath());
   }
 
   @Override