Store Kotlin/Native version in properties

Previously the Kotlin/Native version was hardcoded in sources of the
Gradle plugin. Such an approach is inconvenient when we want to
build Kotlin with a custom K/N version but without changes in sources
(e.g. during CI daily runs).

This patch adds a project property `versions.kotlin-native` which can
be set during build to override Kotlin/Native version. Also this
patch gets rid of hardcoding this version in sources and stores it in
a properties file packed with the Gradle plugin in a jar.
This commit is contained in:
Ilya Matveev
2019-03-22 19:44:24 +07:00
parent a0b8140278
commit acf8a0454f
7 changed files with 40 additions and 18 deletions
@@ -101,12 +101,15 @@ tasks {
}
named<ProcessResources>("processResources") {
val propertiesToExpand = mapOf("projectVersion" to project.version)
val propertiesToExpand = mapOf(
"projectVersion" to project.version,
"kotlinNativeVersion" to project.kotlinNativeVersion
)
for ((name, value) in propertiesToExpand) {
inputs.property(name, value)
}
filesMatching("project.properties") {
expand("projectVersion" to project.version)
expand(propertiesToExpand)
}
}
@@ -33,8 +33,7 @@ import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlugin
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_COMPILER_EMBEDDABLE
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_MODULE_GROUP
import org.jetbrains.kotlin.gradle.utils.checkGradleCompatibility
import java.io.FileNotFoundException
import java.util.*
import org.jetbrains.kotlin.gradle.utils.loadPropertyFromResources
import javax.inject.Inject
import kotlin.reflect.KClass
@@ -168,14 +167,7 @@ fun Project.getKotlinPluginVersion(): String? =
fun Plugin<*>.loadKotlinVersionFromResource(log: Logger): String {
log.kotlinDebug("Loading version information")
val props = Properties()
val propFileName = "project.properties"
val inputStream = javaClass.classLoader!!.getResourceAsStream(propFileName)
?: throw FileNotFoundException("property file '$propFileName' not found in the classpath")
props.load(inputStream)
val projectVersion = props["project.version"] as String
val projectVersion = loadPropertyFromResources("project.properties", "project.version")
log.kotlinDebug("Found project version [$projectVersion]")
return projectVersion
}
@@ -12,8 +12,8 @@ import org.gradle.api.file.FileTree
import org.gradle.api.logging.Logger
import org.jetbrains.kotlin.compilerRunner.KonanCompilerRunner
import org.jetbrains.kotlin.compilerRunner.konanVersion
import org.jetbrains.kotlin.gradle.logging.kotlinInfo
import org.jetbrains.kotlin.konan.KonanVersion
import org.jetbrains.kotlin.konan.KonanVersionImpl
import org.jetbrains.kotlin.konan.MetaVersion
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.util.DependencyDirectories
@@ -25,7 +25,9 @@ class NativeCompilerDownloader(
) {
internal companion object {
val DEFAULT_KONAN_VERSION = KonanVersionImpl(MetaVersion.EAP, 1, 2, 0, 8879)
val DEFAULT_KONAN_VERSION: KonanVersion by lazy {
KonanVersion.fromString(loadPropertyFromResources("project.properties", "kotlin.native.version"))
}
const val BASE_DOWNLOAD_URL = "https://download.jetbrains.com/kotlin/native/builds"
}
@@ -92,8 +94,8 @@ class NativeCompilerDownloader(
val configuration = project.configurations.detachedConfiguration(compilerDependency)
val archive = configuration.files.single()
logger.info("Use Kotlin/Native compiler archive: ${archive.absolutePath}")
logger.lifecycle("Unpack Kotlin/Native compiler (version $versionString)...")
logger.kotlinInfo("Using Kotlin/Native compiler archive: ${archive.absolutePath}")
logger.lifecycle("Unpacking Kotlin/Native compiler (version $versionString)...")
project.copy {
it.from(archiveFileTree(archive))
it.into(DependencyDirectories.localKonanDir)
@@ -110,4 +112,4 @@ class NativeCompilerDownloader(
downloadAndExtract()
}
}
}
}
@@ -0,0 +1,18 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.gradle.utils
import java.io.FileNotFoundException
import java.util.*
fun Any.loadPropertyFromResources(propFileName: String, property: String): String {
val props = Properties()
val inputStream = javaClass.classLoader!!.getResourceAsStream(propFileName)
?: throw FileNotFoundException("property file '$propFileName' not found in the classpath")
inputStream.use { props.load(it) }
return props[property] as String
}
@@ -1 +1,2 @@
project.version=${projectVersion}
project.version=${projectVersion}
kotlin.native.version=${kotlinNativeVersion}