From 905c0c3dd3b810484773bef4f649303233e111d2 Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Sat, 6 Feb 2021 06:38:20 +0100 Subject: [PATCH] [build] version of kotlin native stored in resouces --- build.gradle.kts | 4 ++++ buildSrc/build.gradle.kts | 5 ++++- .../kotlin/konan/kotlin-native-version.kt | 17 +++++++++++++++++ .../Interop/StubGenerator/build.gradle | 4 +--- kotlin-native/backend.native/build.gradle | 6 +++--- kotlin-native/build.gradle | 4 ++-- kotlin-native/gradle.properties | 3 ++- .../kotlin/gradle/plugin/konan/KonanPlugin.kt | 2 +- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index def1b58fdf9..9d45d870b79 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -115,6 +115,10 @@ extra["ideaUltimateSandboxDir"] = project.file(ideaUltimateSandboxDir) extra["ideaPluginDir"] = project.file(ideaPluginDir) extra["ideaUltimatePluginDir"] = project.file(ideaUltimatePluginDir) extra["isSonatypeRelease"] = false +val kotlinNativeVersionObject = project.kotlinNativeVersionValue() +subprojects { + extra["kotlinNativeVersion"] = kotlinNativeVersionObject +} // Work-around necessary to avoid setting null javaHome. Will be removed after support of lazy task configuration val jdkNotFoundConst = "JDK NOT FOUND" diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 45ec8970795..db2238aacb0 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -96,7 +96,10 @@ repositories { } } -val generateCompilerVersion by tasks.registering(VersionGenerator::class) {} +val generateCompilerVersion by tasks.registering(VersionGenerator::class) { + kotlinNativeVersionInResources=true + defaultVersionFileLocation() +} tasks.withType { dependsOn(generateCompilerVersion) } diff --git a/buildSrc/src/kotlin-native-binary-version/kotlin/org/jetbrains/kotlin/konan/kotlin-native-version.kt b/buildSrc/src/kotlin-native-binary-version/kotlin/org/jetbrains/kotlin/konan/kotlin-native-version.kt index e69de29bb2d..5c501be70d8 100644 --- a/buildSrc/src/kotlin-native-binary-version/kotlin/org/jetbrains/kotlin/konan/kotlin-native-version.kt +++ b/buildSrc/src/kotlin-native-binary-version/kotlin/org/jetbrains/kotlin/konan/kotlin-native-version.kt @@ -0,0 +1,17 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.konan +import java.io.* + +val VERSION_PATH = "/META-INF/kotlin-native.compiler.version" +val CompilerVersion.Companion.CURRENT: CompilerVersion + get() { + return InputStreamReader(this::class.java.getResourceAsStream(VERSION_PATH)).use { + it.readLines().single().parseCompilerVersion() + } + } + +val currentCompilerVersion = CompilerVersion.CURRENT \ No newline at end of file diff --git a/kotlin-native/Interop/StubGenerator/build.gradle b/kotlin-native/Interop/StubGenerator/build.gradle index c9427d59065..8bded182173 100644 --- a/kotlin-native/Interop/StubGenerator/build.gradle +++ b/kotlin-native/Interop/StubGenerator/build.gradle @@ -53,9 +53,7 @@ sourceSets{ kotlin { srcDir("../../shared/src/library/kotlin") srcDir("../../shared/src/main/kotlin") - use(VersionGeneratorKt) { - srcDir(project.konanVersionGeneratedSrc()) - } + srcDir(VersionGeneratorKt.kotlinNativeVersionSrc(project)) } } } \ No newline at end of file diff --git a/kotlin-native/backend.native/build.gradle b/kotlin-native/backend.native/build.gradle index d639512d533..c5a0f28793c 100644 --- a/kotlin-native/backend.native/build.gradle +++ b/kotlin-native/backend.native/build.gradle @@ -33,11 +33,11 @@ sourceSets { srcDir 'compiler/ir/backend.native/src/' srcDir '../shared/src/main/kotlin' srcDir '../shared/src/library/kotlin' - use(VersionGeneratorKt) { - srcDir(project.konanVersionGeneratedSrc()) - } + srcDir(VersionGeneratorKt.kotlinNativeVersionSrc(project)) } resources.srcDir 'compiler/ir/backend.native/resources/' + /* PATH to META-INF */ + resources.srcDir VersionGeneratorKt.kotlinNativeVersionResourceFile(project).parentFile.parent } cli_bc { java.srcDir 'cli.bc/src' diff --git a/kotlin-native/build.gradle b/kotlin-native/build.gradle index 975fffaf2f5..09dd27e0f99 100644 --- a/kotlin-native/build.gradle +++ b/kotlin-native/build.gradle @@ -95,7 +95,7 @@ ext { kotlinScriptRuntimeModule= project(":kotlin-script-runtime") kotlinUtilKliMetadatabModule= project(":kotlin-util-klib-metadata") - konanVersionFull = CompilerVersionGeneratedKt.getCurrentCompilerVersion() + konanVersionFull = ext.kotlinNativeVersion gradlePluginVersion = konanVersionFull } @@ -765,7 +765,7 @@ task clean(type: Delete) { task pusher(type: KotlinBuildPusher){ kotlinVersion = project.kotlinVersion - konanVersion = CompilerVersionGeneratedKt.getCurrentCompilerVersion() + konanVersion = project.ext.kotlinNativeVersion buildServer = "buildserver.labs.intellij.net" compilerConfigurationId = System.getenv("TEAMCITY_COMPILER_ID") ?: "Kotlin_KotlinDev_Compiler" overrideConfigurationId = System.getenv("TEAMCITY_OVERRIDE_NATIVE_ID") ?: "Kotlin_KotlinDev_DeployMavenArtifacts_OverrideNative" diff --git a/kotlin-native/gradle.properties b/kotlin-native/gradle.properties index 8e482cff1ff..e3b14d9942b 100644 --- a/kotlin-native/gradle.properties +++ b/kotlin-native/gradle.properties @@ -43,4 +43,5 @@ shadowVersion=5.1.0 metadataVersion=0.0.1-dev-10 # Uncomment to compile Kotlin/Native backend modules with JVM IR backend. -# kotlin.build.useIR=true \ No newline at end of file +# kotlin.build.useIR=true +kotlinNativeVersionInResources=true \ No newline at end of file diff --git a/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/KonanPlugin.kt b/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/KonanPlugin.kt index 9a6ac4e9208..66bb2bc4420 100644 --- a/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/KonanPlugin.kt +++ b/kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/konan/KonanPlugin.kt @@ -94,7 +94,7 @@ internal val Project.konanHome: String internal val Project.konanVersion: CompilerVersion get() = project.findProperty(KonanPlugin.ProjectProperty.KONAN_VERSION) ?.toString()?.let { CompilerVersion.fromString(it) } - ?: CompilerVersion.CURRENT + ?: project.findProperty("kotlinNativeVersion") as? CompilerVersion ?: CompilerVersion.CURRENT internal val Project.konanBuildRoot get() = buildDir.resolve("konan") internal val Project.konanBinBaseDir get() = konanBuildRoot.resolve("bin")