Skip to content

Commit

Permalink
Move to JDK_X_Y variables
Browse files Browse the repository at this point in the history
  • Loading branch information
goodwinnk authored and Space committed Sep 21, 2022
1 parent 2df9203 commit 1630386
Show file tree
Hide file tree
Showing 24 changed files with 71 additions and 52 deletions.
2 changes: 1 addition & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ This repository is using [Gradle toolchains](https://docs.gradle.org/current/use
to select and auto-provision required JDKs from [AdoptOpenJdk](https://adoptopenjdk.net) project.

Unfortunately [AdoptOpenJdk](https://adoptopenjdk.net) project does not provide required JDK 1.6 and 1.7 images,
so you could either download them manually and provide path to installation via `JDK_16` and `JDK_17` environment variables or
so you could either download them manually and provide path to installation via `JDK_1_6` and `JDK_1_7` environment variables or
use following SDK managers:
- [Asdf-vm](https://asdf-vm.com/)
- [Jabba](https://github.com/shyiko/jabba)
Expand Down
11 changes: 10 additions & 1 deletion buildSrc/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ kotlin.build.gradlePlugin.version=0.0.38

# Please keep it in sync with root gradle.properties.
# It's currently needed for proper configuration cache work, the reason will be investigated later
org.gradle.java.installations.fromEnv=JDK_16,JDK_17,JDK_18,JDK_9,JDK_10,JDK_11,JDK_15,JDK_16_0,JDK_17_0
org.gradle.java.installations.fromEnv=\
JDK_1_6,JDK_16,\
JDK_1_7,JDK_17,\
JDK_1_8,JDK_18,\
JDK_9_0,JDK_9,\
JDK_10_0,JDK_10,\
JDK_11_0,JDK_11,\
JDK_15_0,JDK_15,\
JDK_16_0,\
JDK_17_0
10 changes: 5 additions & 5 deletions buildSrc/src/main/kotlin/JvmToolchain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ enum class JdkMajorVersion(
JDK_1_6(6, targetName = "1.6", overrideMajorVersion = 8),
JDK_1_7(7, targetName = "1.7", overrideMajorVersion = 8),
JDK_1_8(8, targetName = "1.8"),
JDK_9(9, overrideMajorVersion = 11),
JDK_10(10, mandatory = false, overrideMajorVersion = 11),
JDK_11(11, mandatory = false),
JDK_16(16, mandatory = false),
JDK_17(17, mandatory = false);
JDK_9_0(9, overrideMajorVersion = 11),
JDK_10_0(10, mandatory = false, overrideMajorVersion = 11),
JDK_11_0(11, mandatory = false),
JDK_16_0(16, mandatory = false),
JDK_17_0(17, mandatory = false);

fun isMandatory(): Boolean = mandatory

Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/LibrariesCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ fun Project.configureJava9Compilation(
configurations["java9CompileClasspath"].extendsFrom(configurations["compileClasspath"])

tasks.named("compileJava9Kotlin", KotlinCompile::class.java) {
configureTaskToolchain(JdkMajorVersion.JDK_9)
configureTaskToolchain(JdkMajorVersion.JDK_9_0)
@Suppress("DEPRECATION")
kotlinOptions.jvmTarget = JdkMajorVersion.JDK_9.targetName
kotlinOptions.jvmTarget = JdkMajorVersion.JDK_9_0.targetName
}

tasks.named("compileJava9Java", JavaCompile::class.java) {
dependsOn(moduleOutputs)

targetCompatibility = JavaVersion.VERSION_1_9.toString()
sourceCompatibility = JavaVersion.VERSION_1_9.toString()
configureTaskToolchain(JdkMajorVersion.JDK_9)
configureTaskToolchain(JdkMajorVersion.JDK_9_0)

// module-info.java should be in java9 source set by convention
val java9SourceSet = sourceSets["java9"].java
Expand Down
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ private fun String.toMaybeVersionedJarRegex(): Regex {
return Regex(if (hasJarExtension) escaped else "$escaped(-\\d.*)?\\.jar") // TODO: consider more precise version part of the regex
}

fun Project.firstFromJavaHomeThatExists(vararg paths: String, jdkHome: File = File(this.property("JDK_18") as String)): File? =
fun Project.firstFromJavaHomeThatExists(
vararg paths: String,
jdkHome: File = File((this.property("JDK_1_8") ?: this.property("JDK_18") ?: error("Can't find JDK_1_8 property")) as String)
): File? =
paths.map { File(jdkHome, it) }.firstOrNull { it.exists() }.also {
if (it == null)
logger.warn("Cannot find file by paths: ${paths.toList()} in $jdkHome")
Expand Down
2 changes: 1 addition & 1 deletion compiler/incremental-compilation-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ projectTest("testJvmICWithJdk11", parallel = true) {
filter {
includeTestsMatching("org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunnerTestGenerated*")
}
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_11))
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_11_0))
}

testsJar()
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ enum class TestJdkKind(val requiresSeparateProcess: Boolean = false) {
// Also, now it contains new methods in java.lang.String introduced in JDK 11
MODIFIED_MOCK_JDK,

// JDK found at $JDK_16
// JDK found at $JDK_1_6
FULL_JDK_6(requiresSeparateProcess = true),

// JDK found at $JDK_11
// JDK found at $JDK_11_0
FULL_JDK_11(requiresSeparateProcess = true),

// JDK found at $JDK_17
// JDK found at $JDK_17_0
FULL_JDK_17(requiresSeparateProcess = true),

// JDK found at java.home
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,17 @@ private static String getStringProperty(@NotNull String propertyName) {

@NotNull
public static File getJdk6Home() {
return getJdkHome("JDK_6", "JDK_16");
return getJdkHome("JDK_1_6", "JDK_6", "JDK_16");
}

@NotNull
public static File getJdk8Home() {
return getJdkHome("JDK_8", "JDK_18");
return getJdkHome("JDK_1_8", "JDK_8", "JDK_18");
}

@NotNull
public static File getJdk11Home() {
return getJdkHome("JDK_11");
return getJdkHome("JDK_11_0", "JDK_11");
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@

package org.jetbrains.kotlin.test

import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.checkers.ENABLE_JVM_PREVIEW
import org.jetbrains.kotlin.checkers.parseLanguageVersionSettings
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.config.JvmTarget.Companion.fromString
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import org.jetbrains.kotlin.test.util.KtTestUtil
import java.io.File
import java.util.*

abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase() {
@Throws(Exception::class)
Expand All @@ -42,7 +38,7 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
}

protected open fun getTestJdkKind(files: List<F>): TestJdkKind {
if (files.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.content, "JDK_17") }) return TestJdkKind.FULL_JDK_17
if (files.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.content, "JDK_17_0") }) return TestJdkKind.FULL_JDK_17

for (file in files) {
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "FULL_JDK")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ else if (jdkKind == TestJdkKind.ANDROID_API) {
configuration.put(JVMConfigurationKeys.NO_JDK, true);
}
else if (jdkKind == TestJdkKind.FULL_JDK_6) {
String jdk6 = System.getenv("JDK_16");
assert jdk6 != null : "Environment variable JDK_16 is not set";
String jdk6 = System.getenv("JDK_1_6");
if (jdk6 == null) {
jdk6 = System.getenv("JDK_16");
}
assert jdk6 != null : "Environment variable JDK_1_6 is not set";
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(jdk6));
}
else if (jdkKind == TestJdkKind.FULL_JDK_17) {
Expand Down
8 changes: 4 additions & 4 deletions compiler/tests-different-jdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ fun Project.codegenTest(
codegenTest(target = 8, jdk = JdkMajorVersion.JDK_1_8)

//JDK 11
codegenTest(target = 8, jdk = JdkMajorVersion.JDK_11)
codegenTest(target = 8, jdk = JdkMajorVersion.JDK_11_0)

codegenTest(target = 11, jdk = JdkMajorVersion.JDK_11)
codegenTest(target = 11, jdk = JdkMajorVersion.JDK_11_0)

//JDK 17
codegenTest(target = 8, jdk = JdkMajorVersion.JDK_17)
codegenTest(target = 8, jdk = JdkMajorVersion.JDK_17_0)

codegenTest(target = 17, jdk = JdkMajorVersion.JDK_17) {
codegenTest(target = 17, jdk = JdkMajorVersion.JDK_17_0) {
systemProperty("kotlin.test.box.d8.disable", true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ abstract class JavaModulesIntegrationTest(private val jdkVersion: Int, private v
return { actual ->
KotlinTestUtils.assertEqualsToFile(
expectedFile,
getNormalizedCompilerOutput(actual, null, testDataPath).replace(System.getenv("JDK_11").replace("\\", "/"), "\$JDK11")
.replace(System.getenv("JDK_17").replace("\\", "/"), "\$JDK17")
getNormalizedCompilerOutput(actual, null, testDataPath)
.replace((System.getenv("JDK_11_0") ?: System.getenv("JDK_11")).replace("\\", "/"), "\$JDK11")
.replace((System.getenv("JDK_17_0") ?: System.getenv("JDK_17")).replace("\\", "/"), "\$JDK17")
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion generators/ide-iml-to-gradle-generator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ sourceSets {
}

val generateIdePluginGradleFiles by generator("org.jetbrains.kotlin.generators.imltogradle.MainKt") {
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_11))
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_11_0))
}
11 changes: 10 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ org.gradle.caching=true

# Please keep it in sync with buildSrc gradle.properties.
# It's currently needed for proper configuration cache work, the reason will be investigated later
org.gradle.java.installations.fromEnv=JDK_16,JDK_17,JDK_18,JDK_9,JDK_10,JDK_11,JDK_15,JDK_16_0,JDK_17_0
org.gradle.java.installations.fromEnv=\
JDK_1_6,JDK_16,\
JDK_1_7,JDK_17,\
JDK_1_8,JDK_18,\
JDK_9_0,JDK_9,\
JDK_10_0,JDK_10,\
JDK_11_0,JDK_11,\
JDK_15_0,JDK_15,\
JDK_16_0,\
JDK_17_0

systemProp.org.gradle.internal.http.connectionTimeout=90000
systemProp.org.gradle.internal.http.socketTimeout=90000
Expand Down
2 changes: 1 addition & 1 deletion kotlin-native/endorsedLibraries/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.jetbrains.kotlin.kotlinNativeDist
import org.jetbrains.kotlin.mergeManifestsByTargets

if (HostManager.host == KonanTarget.MACOS_ARM64) {
project.configureJvmToolchain(JdkMajorVersion.JDK_17)
project.configureJvmToolchain(JdkMajorVersion.JDK_17_0)
}

plugins {
Expand Down
2 changes: 1 addition & 1 deletion kotlin-native/platformLibs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fun defFileToLibName(target: String, name: String) = "$target-$name"
// endregion

if (HostManager.host == KonanTarget.MACOS_ARM64) {
project.configureJvmToolchain(JdkMajorVersion.JDK_17)
project.configureJvmToolchain(JdkMajorVersion.JDK_17_0)
}

val konanTargetList: List<KonanTarget> by project
Expand Down
5 changes: 2 additions & 3 deletions kotlin-native/runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
* that can be found in the LICENSE file.
*/
import org.jetbrains.kotlin.*
import org.jetbrains.kotlin.bitcode.CompileToBitcode
import org.jetbrains.kotlin.bitcode.CompileToBitcodeExtension
import org.jetbrains.kotlin.gradle.plugin.konan.tasks.KonanCacheTask
import org.jetbrains.kotlin.konan.properties.loadProperties
import org.jetbrains.kotlin.konan.properties.saveProperties
import org.jetbrains.kotlin.konan.target.*
import org.jetbrains.kotlin.library.KLIB_PROPERTY_NATIVE_TARGETS
import org.jetbrains.kotlin.konan.target.Architecture as TargetArchitecture
import org.jetbrains.kotlin.konan.file.File as KFile
import org.jetbrains.kotlin.konan.target.Architecture as TargetArchitecture

// These properties are used by the 'konan' plugin, thus we set them before applying it.
val distDir: File by project
Expand All @@ -25,7 +24,7 @@ plugins {
}

if (HostManager.host == KonanTarget.MACOS_ARM64) {
project.configureJvmToolchain(JdkMajorVersion.JDK_17)
project.configureJvmToolchain(JdkMajorVersion.JDK_17_0)
}

googletest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
// If the JDK that was set is not available get the JDK 11 as a default
service.launcherFor(object : Action<JavaToolchainSpec> {
override fun execute(toolchainSpec: JavaToolchainSpec) {
toolchainSpec.languageVersion.set(JavaLanguageVersion.of(JdkMajorVersion.JDK_11.majorVersion))
toolchainSpec.languageVersion.set(JavaLanguageVersion.of(JdkMajorVersion.JDK_11_0.majorVersion))
}
}).get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.gradle.kotlin.dsl.support.serviceOf

description = "Shaded Maven dependencies resolver"

val JDK_18: String by rootProject.extra
val jarBaseName = property("archivesBaseName") as String

val embedded by configurations
Expand Down
6 changes: 3 additions & 3 deletions libraries/stdlib/jdk8/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,23 @@ task testJdk6Tests(type: Test) { thisTask ->
}
}

[JdkMajorVersion.JDK_9, JdkMajorVersion.JDK_10, JdkMajorVersion.JDK_11].forEach { jvmVersion ->
[JdkMajorVersion.JDK_9_0, JdkMajorVersion.JDK_10_0, JdkMajorVersion.JDK_11_0].forEach { jvmVersion ->
check.dependsOn(tasks.register("jdk${jvmVersion.majorVersion}Test", Test) { thisTask ->
group = "verification"
thisTask.javaLauncher.set(JvmToolchain.getToolchainLauncherFor(project, jvmVersion))
})
}

compileModuleTestKotlin {
kotlinJavaToolchain.toolchain.use(JvmToolchain.getToolchainLauncherFor(project, JdkMajorVersion.JDK_9))
kotlinJavaToolchain.toolchain.use(JvmToolchain.getToolchainLauncherFor(project, JdkMajorVersion.JDK_9_0))
}

check.dependsOn(tasks.register("moduleInfoTest", Test) {test ->
test.dependsOn(moduleTestClasses)
test.group = "verification"
test.testClassesDirs = sourceSets.moduleTest.output.classesDirs
test.classpath = files(sourceSets.moduleTest.runtimeClasspath, tasks.jar)
test.javaLauncher.set(JvmToolchain.getToolchainLauncherFor(project, JdkMajorVersion.JDK_9))
test.javaLauncher.set(JvmToolchain.getToolchainLauncherFor(project, JdkMajorVersion.JDK_9_0))
doFirst {
test.systemProperty("stdlibJars", test.classpath.filter { it.name.contains('kotlin-stdlib') }.join(File.pathSeparator))
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/stdlib/jvm/src/kotlin/reflect/TypesJVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private interface TypeImpl : Type {
// This is a copy of [Type.getTypeName] which is present on JDK 8+.
@Suppress(
"VIRTUAL_MEMBER_HIDDEN", "NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT"
) // This is needed for cases when environment variable JDK_16 points to JDK 8+.
) // This is needed for cases when environment variable JDK_1_6 points to JDK 8+.
fun getTypeName(): String
}

Expand All @@ -126,7 +126,7 @@ private class TypeVariableImpl(private val typeParameter: KTypeParameter) : Type
override fun toString(): String = getTypeName()

// [TypeVariable] extends [AnnotatedElement] starting from JDK 8. The following are copies of methods from there.
// Suppression of VIRTUAL_MEMBER_HIDDEN is needed for cases when environment variable JDK_16 points to JDK 8+.
// Suppression of VIRTUAL_MEMBER_HIDDEN is needed for cases when environment variable JDK_1_6 points to JDK 8+.
@Suppress("VIRTUAL_MEMBER_HIDDEN", "UNUSED_PARAMETER")
fun <T : Annotation> getAnnotation(annotationClass: Class<T>): T? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ tasks.withType<Test> {
}

val jdk8Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_1_8).map { it.metadata.installationPath.asFile.absolutePath }
val jdk9Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_9).map { it.metadata.installationPath.asFile.absolutePath }
val jdk10Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_10).map { it.metadata.installationPath.asFile.absolutePath }
val jdk11Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_11).map { it.metadata.installationPath.asFile.absolutePath }
val jdk16Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_16).map { it.metadata.installationPath.asFile.absolutePath }
val jdk9Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_9_0).map { it.metadata.installationPath.asFile.absolutePath }
val jdk10Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_10_0).map { it.metadata.installationPath.asFile.absolutePath }
val jdk11Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_11_0).map { it.metadata.installationPath.asFile.absolutePath }
val jdk16Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_16_0).map { it.metadata.installationPath.asFile.absolutePath }
val mavenLocalRepo = project.providers.systemProperty("maven.repo.local").forUseAtConfigurationTime().orNull

// Query required JDKs paths only on execution phase to avoid triggering auto-download on project configuration phase
Expand Down
4 changes: 2 additions & 2 deletions native/native.tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
id("jps-compatible")
}

project.configureJvmToolchain(JdkMajorVersion.JDK_11)
project.configureJvmToolchain(JdkMajorVersion.JDK_11_0)

dependencies {
testImplementation(kotlinStdlib())
Expand Down Expand Up @@ -179,6 +179,6 @@ val test by nativeTest("test" /* no tags */).apply {
}

val generateTests by generator("org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt") {
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_11))
javaLauncher.set(project.getToolchainLauncherFor(JdkMajorVersion.JDK_11_0))
dependsOn(":compiler:generateTestData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ abstract class AbstractKaptToolIntegrationTest {
}

private fun getJdk8Home(): File {
val homePath = System.getenv()["JDK_18"] ?: error("Can't find JDK 1.8 home")
val homePath = System.getenv()["JDK_1_8"] ?: System.getenv()["JDK_18"] ?: error("Can't find JDK 1.8 home, please define JDK_1_8 variable")
return File(homePath)
}
}
Expand Down

0 comments on commit 1630386

Please sign in to comment.