Add more dependencies for running our main tests

Bug: b/270105162
Change-Id: I15d6280f747d0115059c1c3bd5b19f1f0d682753
diff --git a/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt b/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
index 5ecf7f6..ccf5246 100644
--- a/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
+++ b/d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt
@@ -2,6 +2,7 @@
 // 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.
 
+import DependenciesPlugin.Companion.computeRoot
 import java.io.File
 import java.lang.Thread.sleep
 import java.net.URI
@@ -31,6 +32,16 @@
     repositories.maven { name = "LOCAL_MAVEN_REPO";  url = URI(dependenciesPath) }
     repositories.maven { name = "LOCAL_MAVEN_REPO_NEW";  url = URI(dependenciesNewPath) }
   }
+
+  companion object {
+    fun computeRoot(file: File) : File {
+      var parent = file
+      while (!parent.getName().equals("d8_r8")) {
+        parent = parent.getParentFile()
+      }
+      return parent.getParentFile()
+    }
+  }
 }
 
 enum class Jdk(val folder : String) {
@@ -66,11 +77,7 @@
 }
 
 fun Project.getRoot() : File {
-  var parent = this.projectDir
-  while (!parent.getName().equals("d8_r8")) {
-    parent = parent.getParentFile()
-  }
-  return parent.getParentFile()
+  return computeRoot(this.projectDir)
 }
 
 fun Project.header(title : String) : String {
@@ -83,7 +90,8 @@
     val projectAndTaskName = "${project.name}-$name"
     val downloadTaskName = "download-third-party-$projectAndTaskName-${tpd.packageName}"
     val downloadTask = tasks.register<DownloadDependencyTask>(downloadTaskName) {
-      setDependency(getRoot().resolve(tpd.sha1File), getRoot().resolve(tpd.path), tpd.type)
+      setDependency(
+        getRoot(), getRoot().resolve(tpd.sha1File), getRoot().resolve(tpd.path), tpd.type)
     }.get()
     outputFiles.add(tpd.path)
     downloadTask
@@ -95,7 +103,7 @@
 }
 
 /**
- * Builds a jar for each subfolder in an test source set.
+ * Builds a jar for each sub folder in a test source set.
  *
  * <p> As an example, src/test/examplesJava9 contains subfolders: backport, collectionof, ..., .
  * These are compiled to individual jars and placed in <repo-root>/build/test/examplesJava9/ as:
@@ -159,7 +167,8 @@
   return "build-example-jars-$name"
 }
 
-fun Project.resolve(thirdPartyDependency: ThirdPartyDependency, vararg paths: String) : ConfigurableFileCollection {
+fun Project.resolve(
+    thirdPartyDependency: ThirdPartyDependency, vararg paths: String) : ConfigurableFileCollection {
   return files(project.getRoot().resolve(thirdPartyDependency.path).resolveAll(*paths))
 }
 
@@ -309,6 +318,10 @@
       "third_party",
       "binary_compatibility_tests",
       "compiler_api_tests.tar.gz.sha1").toFile())
+  val coreLambdaStubs = ThirdPartyDependency(
+    "coreLambdaStubs",
+    Paths.get("third_party", "core-lambda-stubs").toFile(),
+    Paths.get("third_party", "core-lambda-stubs.tar.gz.sha1").toFile())
   val dagger = ThirdPartyDependency(
     "dagger",
     Paths.get("third_party", "dagger", "2.41").toFile(),
@@ -341,6 +354,10 @@
     "jasmin",
     Paths.get("third_party", "jasmin").toFile(),
     Paths.get("third_party", "jasmin.tar.gz.sha1").toFile())
+  val jsr223 = ThirdPartyDependency(
+    "jsr223",
+    Paths.get("third_party", "jsr223-api-1.0").toFile(),
+    Paths.get("third_party", "jsr223-api-1.0.tar.gz.sha1").toFile())
   val java8Runtime = ThirdPartyDependency(
     "openjdk-rt-1.8",
     Paths.get("third_party", "openjdk", "openjdk-rt-1.8").toFile(),
@@ -357,7 +374,32 @@
     Paths.get("third_party", "jdwp-tests").toFile(),
     Paths.get("third_party", "jdwp-tests.tar.gz.sha1").toFile())
   val kotlinCompilers = getThirdPartyKotlinCompilers()
+  val multidex = ThirdPartyDependency(
+    "multidex",
+    Paths.get("third_party", "multidex").toFile(),
+    Paths.get("third_party", "multidex.tar.gz.sha1").toFile())
   val proguards = getThirdPartyProguards()
+  val protobufLite = ThirdPartyDependency(
+    "protobuf-lite",
+    Paths.get("third_party", "protobuf-lite").toFile(),
+    Paths.get("third_party", "protobuf-lite.tar.gz.sha1").toFile(),
+    DependencyType.X20)
+  val r8 = ThirdPartyDependency(
+    "r8",
+    Paths.get("third_party", "r8").toFile(),
+    Paths.get("third_party", "r8.tar.gz.sha1").toFile())
+  val rhino = ThirdPartyDependency(
+    "rhino",
+    Paths.get("third_party", "rhino-1.7.10").toFile(),
+    Paths.get("third_party", "rhino-1.7.10.tar.gz.sha1").toFile())
+  val rhinoAndroid = ThirdPartyDependency(
+    "rhino-android",
+    Paths.get("third_party", "rhino-android-1.1.1").toFile(),
+    Paths.get("third_party", "rhino-android-1.1.1.tar.gz.sha1").toFile())
+  val smali = ThirdPartyDependency(
+    "smali",
+    Paths.get("third_party", "smali").toFile(),
+    Paths.get("third_party", "smali.tar.gz.sha1").toFile())
 }
 
 fun getThirdPartyAndroidJars() : List<ThirdPartyDependency> {
@@ -409,7 +451,6 @@
 }
 
 fun getThirdPartyAndroidVm(version : List<String>) : ThirdPartyDependency {
-  val output = Paths.get("tools", "linux", *version.toTypedArray(), "bin", "art").toFile()
   return ThirdPartyDependency(
     version.last(),
     Paths.get(
diff --git a/d8_r8/commonBuildSrc/src/main/kotlin/DownloadDependencyTask.kt b/d8_r8/commonBuildSrc/src/main/kotlin/DownloadDependencyTask.kt
index c40d857..1f49973 100644
--- a/d8_r8/commonBuildSrc/src/main/kotlin/DownloadDependencyTask.kt
+++ b/d8_r8/commonBuildSrc/src/main/kotlin/DownloadDependencyTask.kt
@@ -2,6 +2,7 @@
 // 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.
 
+import DependenciesPlugin.Companion.computeRoot
 import java.io.BufferedReader
 import java.io.File
 import java.io.IOException
@@ -18,6 +19,7 @@
 import org.gradle.api.DefaultTask
 import org.gradle.api.file.RegularFileProperty
 import org.gradle.api.provider.Property
+import org.gradle.api.tasks.InputFile
 import org.gradle.api.tasks.OutputDirectory
 import org.gradle.api.tasks.TaskAction
 import org.gradle.api.tasks.options.Option
@@ -33,6 +35,11 @@
   private var _tarGzFile: File? = null
   private var _sha1File: File? = null
 
+  @InputFile
+  fun getInputFile(): File? {
+    return _sha1File
+  }
+
   @OutputDirectory
   fun getOutputDir(): File? {
     return _outputDir
@@ -75,6 +82,7 @@
         this.outputDir.set(outputDir)
         this.tarGzFile.set(tarGzFile)
         this.lockFile.set(lockFile)
+        this.root.set(computeRoot(project.projectDir))
       }
   }
 
@@ -84,6 +92,7 @@
     val outputDir : RegularFileProperty
     val tarGzFile : RegularFileProperty
     val lockFile : RegularFileProperty
+    val root : RegularFileProperty
   }
 
   abstract class RunDownload : WorkAction<RunDownloadParameters> {
@@ -159,6 +168,7 @@
 
     @Throws(IOException::class, InterruptedException::class)
     private fun runProcess(parameters: RunDownloadParameters, builder: ProcessBuilder) {
+      builder.directory(parameters.root.asFile.get())
       val command = java.lang.String.join(" ", builder.command())
       val p = builder.start()
       val exit = p.waitFor()
diff --git a/d8_r8/test_modules/tests_java_8/build.gradle.kts b/d8_r8/test_modules/tests_java_8/build.gradle.kts
index 953098f..4ceb3e6 100644
--- a/d8_r8/test_modules/tests_java_8/build.gradle.kts
+++ b/d8_r8/test_modules/tests_java_8/build.gradle.kts
@@ -57,19 +57,33 @@
   "runtimeDeps",
   listOf(
     ThirdPartyDeps.compilerApi,
+    ThirdPartyDeps.coreLambdaStubs,
     ThirdPartyDeps.dagger,
     ThirdPartyDeps.desugarJdkLibs,
     ThirdPartyDeps.desugarJdkLibs11,
     ThirdPartyDeps.iosched2019,
     ThirdPartyDeps.jacoco,
     ThirdPartyDeps.java8Runtime,
-    ThirdPartyDeps.jdk11Test)
+    ThirdPartyDeps.jdk11Test,
+    ThirdPartyDeps.jsr223,
+    ThirdPartyDeps.multidex,
+    ThirdPartyDeps.r8,
+    ThirdPartyDeps.rhino,
+    ThirdPartyDeps.rhinoAndroid,
+    ThirdPartyDeps.smali)
     + ThirdPartyDeps.androidJars
     + ThirdPartyDeps.androidVMs
     + ThirdPartyDeps.jdks
     + ThirdPartyDeps.kotlinCompilers
     + ThirdPartyDeps.proguards)
 
+val thirdPartyRuntimeInternalDependenciesTask = ensureThirdPartyDependencies(
+  "runtimeInternalDeps",
+  listOf(
+    ThirdPartyDeps.protobufLite,
+  )
+)
+
 val sourceSetDependenciesTasks = arrayOf(
   projectTask("tests_java_examples", getExampleJarsTaskName("examples")),
   projectTask("tests_java_9", getExampleJarsTaskName("examplesJava9")),
@@ -125,6 +139,7 @@
   withType<Test> {
     environment.put("USE_NEW_GRADLE_SETUP", "true")
     dependsOn(thirdPartyRuntimeDependenciesTask)
+    dependsOn(thirdPartyRuntimeInternalDependenciesTask)
     dependsOn(*sourceSetDependenciesTasks)
     println("NOTE: Number of processors " + Runtime.getRuntime().availableProcessors())
     val userDefinedCoresPerFork = System.getenv("R8_GRADLE_CORES_PER_FORK")
diff --git a/src/test/java/com/android/tools/r8/internal/proto/ProtoShrinkingTestBase.java b/src/test/java/com/android/tools/r8/internal/proto/ProtoShrinkingTestBase.java
index 23d7007..81a54bc 100644
--- a/src/test/java/com/android/tools/r8/internal/proto/ProtoShrinkingTestBase.java
+++ b/src/test/java/com/android/tools/r8/internal/proto/ProtoShrinkingTestBase.java
@@ -37,10 +37,10 @@
 public abstract class ProtoShrinkingTestBase extends TestBase {
 
   public static final Path PROTOBUF_LITE_JAR =
-      Paths.get("third_party/protobuf-lite/libprotobuf_lite.jar");
+      Paths.get(ToolHelper.THIRD_PARTY_DIR, "protobuf-lite/libprotobuf_lite.jar");
 
   public static final Path PROTOBUF_LITE_PROGUARD_RULES =
-      Paths.get("third_party/protobuf-lite/lite_proguard.pgcfg");
+      Paths.get(ToolHelper.THIRD_PARTY_DIR, "protobuf-lite/lite_proguard.pgcfg");
 
   // Test classes for proto2.
   public static final Path PROTO2_EXAMPLES_JAR =