blob: 9040c8e1b331196082d3cf033646d7d83ab33f18 [file] [log] [blame]
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +01001// Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +02005import java.nio.file.Paths
Morten Krogh-Jespersen774701f2023-08-09 08:22:09 +02006import org.gradle.api.logging.LogLevel.ERROR
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +02007import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Morten Krogh-Jespersen774701f2023-08-09 08:22:09 +02008import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +02009
10
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010011plugins {
12 `kotlin-dsl`
13 id("dependencies-plugin")
14}
15
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010016java {
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +020017 sourceCompatibility = JavaVersion.VERSION_17
18 targetCompatibility = JavaVersion.VERSION_17
19}
20
21dependencies { }
22
23val r8WithRelocatedDepsTask = projectTask("main", "r8WithRelocatedDeps")
24val java8TestJarTask = projectTask("tests_java_8", "testJar")
25val java8DepsJarTask = projectTask("tests_java_8", "depsJar")
26
27tasks {
28 withType<JavaCompile> {
29 options.setFork(true)
30 options.forkOptions.executable = getCompilerPath(Jdk.JDK_17)
31 options.forkOptions.javaHome = getJavaHome(Jdk.JDK_17)
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010032 }
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010033
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +020034 withType<KotlinCompile> {
35 kotlinOptions {
36 jvmTarget = "17"
37 }
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010038 }
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010039
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +020040 val allTestsJar by registering(Jar::class) {
41 dependsOn(java8TestJarTask)
42 from(java8TestJarTask.outputs.getFiles().map(::zipTree))
43 exclude("META-INF/*.kotlin_module")
44 exclude("**/*.kotlin_metadata")
45 archiveFileName.set("all-tests.jar")
46 }
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010047
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +020048 val allDepsJar by registering(Jar::class) {
49 dependsOn(java8DepsJarTask)
50 from(java8DepsJarTask.outputs.getFiles().map(::zipTree))
51 exclude("META-INF/*.kotlin_module")
52 exclude("**/*.kotlin_metadata")
53 archiveFileName.set("all-deps.jar")
54 }
Morten Krogh-Jespersen5a37de82023-03-02 01:42:28 +010055
Morten Krogh-Jespersend1a11852023-06-14 14:48:44 +020056 val allTestsJarRelocated by registering(Exec::class) {
57 dependsOn(r8WithRelocatedDepsTask)
58 dependsOn(allTestsJar)
59 val r8 = r8WithRelocatedDepsTask.outputs.getFiles().getSingleFile()
60 val allTests = allTestsJar.get().outputs.files.getSingleFile()
61 inputs.files(listOf(r8, allTests))
62 val output = file(Paths.get("build", "libs", "all-tests-relocated.jar"))
63 outputs.file(output)
64 commandLine = baseCompilerCommandLine(
65 r8,
66 "relocator",
67 listOf("--input",
68 "$allTests",
69 "--output",
70 "$output",
71 "--map",
72 "kotlinx.metadata->com.android.tools.r8.jetbrains.kotlinx.metadata"))
73 }
Morten Krogh-Jespersenb823d0b2023-08-07 14:06:49 +020074
75 withType<Test> {
Morten Krogh-Jespersen568c0f52023-08-09 15:25:07 +020076 println("NOTE: Number of processors " + Runtime.getRuntime().availableProcessors())
77 println("NOTE: Max parallel forks " + maxParallelForks)
Morten Krogh-Jespersen774701f2023-08-09 08:22:09 +020078 val os = DefaultNativePlatform.getCurrentOperatingSystem()
79 if (os.isMacOsX) {
80 logger.lifecycle(
81 "WARNING: Testing in only partially supported on Mac OS. \n" +
Morten Krogh-Jespersen568c0f52023-08-09 15:25:07 +020082 "Art only runs on Linux and tests requiring Art runs in a Docker container, which must " +
Morten Krogh-Jespersen774701f2023-08-09 08:22:09 +020083 "be present. See tools/docker/README.md for details.")
84 } else if (os.isWindows) {
85 logger.lifecycle(
86 "WARNING: Testing in only partially supported on Windows. Art only runs on Linux and " +
87 "tests requiring Art will be skipped")
88 } else if (!os.isLinux) {
89 logger.log(
Morten Krogh-Jespersen568c0f52023-08-09 15:25:07 +020090 LogLevel.ERROR,
Morten Krogh-Jespersen774701f2023-08-09 08:22:09 +020091 "Testing in not supported on your platform. Testing is only fully supported on " +
92 "Linux and partially supported on Mac OS and Windows. Art does not run on other " +
93 "platforms.")
94 }
Morten Krogh-Jespersen568c0f52023-08-09 15:25:07 +020095 dependsOn(gradle.includedBuild("tests_java_8").task(":test"))
Morten Krogh-Jespersenb823d0b2023-08-07 14:06:49 +020096 }
97}