Add library_desugar source set to new gradle setup

Bug: b/270105162
Change-Id: I687230d5dbcabe5e5a5d377b5813a931a0dd91e1
diff --git a/d8_r8/library_desugar/build.gradle.kts b/d8_r8/library_desugar/build.gradle.kts
new file mode 100644
index 0000000..7483d80
--- /dev/null
+++ b/d8_r8/library_desugar/build.gradle.kts
@@ -0,0 +1,34 @@
+// Copyright (c) 2023, 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.
+
+// import java.nio.file.Paths
+// import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+  `kotlin-dsl`
+  id("dependencies-plugin")
+}
+
+java {
+  sourceSets.main.configure {
+    java.srcDir(getRoot().resolveAll("src", "library_desugar", "java"))
+    output.resourcesDir = getRoot().resolveAll("build", "classes", "library_desugar_conversions")
+  }
+  sourceCompatibility = JavaVersion.VERSION_1_8
+  targetCompatibility = JavaVersion.VERSION_1_8
+}
+
+dependencies {
+}
+
+tasks {
+  withType<JavaCompile> {
+    options.setFork(true)
+    options.forkOptions.memoryMaximumSize = "3g"
+    options.forkOptions.jvmArgs = listOf(
+      "-Xss256m",
+      // Set the bootclass path so compilation is consistent with 1.8 target compatibility.
+      "-Xbootclasspath/a:third_party/openjdk/openjdk-rt-1.8/rt.jar")
+  }
+}
\ No newline at end of file
diff --git a/d8_r8/library_desugar/gradle.properties b/d8_r8/library_desugar/gradle.properties
new file mode 100644
index 0000000..1de43f9
--- /dev/null
+++ b/d8_r8/library_desugar/gradle.properties
@@ -0,0 +1,17 @@
+# Copyright (c) 2023, 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.
+
+org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8
+kotlin.daemon.jvmargs=-Xmx3g -Dkotlin.js.compiler.legacy.force_enabled=true
+systemProp.file.encoding=UTF-8
+
+# Enable new incremental compilation
+kotlin.incremental.useClasspathSnapshot=true
+
+org.gradle.parallel=true
+org.gradle.caching=true
+
+# Do not download any jdks or detect them. We provide them.
+org.gradle.java.installations.auto-detect=false
+org.gradle.java.installations.auto-download=false
diff --git a/d8_r8/library_desugar/settings.gradle.kts b/d8_r8/library_desugar/settings.gradle.kts
new file mode 100644
index 0000000..e60eee4
--- /dev/null
+++ b/d8_r8/library_desugar/settings.gradle.kts
@@ -0,0 +1,5 @@
+// Copyright (c) 2023, 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.
+
+rootProject.name = "library_desugar"
diff --git a/d8_r8/settings.gradle.kts b/d8_r8/settings.gradle.kts
index 9907334..77ad2e0 100644
--- a/d8_r8/settings.gradle.kts
+++ b/d8_r8/settings.gradle.kts
@@ -54,6 +54,7 @@
 // We need to include src/main as a composite-build otherwise our test-modules
 // will compete with the test to compile the source files.
 includeBuild(root.resolve("main"))
+includeBuild(root.resolve("library_desugar"))
 includeBuild(root.resolve("test"))
 
 // Include r8lib as standalone to have a nice separation between source artifacts and r8 compiled
diff --git a/src/test/java/com/android/tools/r8/ToolHelper.java b/src/test/java/com/android/tools/r8/ToolHelper.java
index 8ffd594..45c6a95 100644
--- a/src/test/java/com/android/tools/r8/ToolHelper.java
+++ b/src/test/java/com/android/tools/r8/ToolHelper.java
@@ -112,6 +112,7 @@
   }
 
   public static final String SOURCE_DIR = "src/main/java/";
+  public static final String LIBRARY_DESUGAR_SOURCE_DIR = getProjectRoot() + "src/library_desugar/";
   public static final String RESOURCES_DIR = "src/main/resources/";
   public static final String BUILD_DIR = getProjectRoot() + "build/";
   public static final String TEST_MODULE_DIR = getProjectRoot() + "d8_r8/test_modules/";
diff --git a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/LibraryDesugaringSpecification.java b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/LibraryDesugaringSpecification.java
index 7f89255..b82ba3e 100644
--- a/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/LibraryDesugaringSpecification.java
+++ b/src/test/java/com/android/tools/r8/desugar/desugaredlibrary/test/LibraryDesugaringSpecification.java
@@ -181,7 +181,7 @@
     this(
         name,
         ImmutableSet.of(desugarJdkLibs, ToolHelper.getDesugarLibConversions(legacy)),
-        Paths.get("src/library_desugar/" + specificationPath),
+        Paths.get(ToolHelper.LIBRARY_DESUGAR_SOURCE_DIR + specificationPath),
         ImmutableSet.of(ToolHelper.getAndroidJar(androidJarLevel)),
         descriptor,
         "");