[gradle-plugin] Rename konan.home -> org.jetbrains.kotlin.native.home
This commit is contained in:
committed by
Ilya Matveev
parent
474b401dd1
commit
e365fb8f40
+2
-4
@@ -44,10 +44,7 @@ import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeTestComponent
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.*
|
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.CInteropTask
|
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.CInteropTask
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
|
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
|
||||||
import org.jetbrains.kotlin.gradle.plugin.konan.KonanPlugin
|
import org.jetbrains.kotlin.gradle.plugin.konan.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.konan.hasProperty
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.konan.konanCompilerDownloadDir
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.konan.setProperty
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.loadKotlinVersionFromResource
|
import org.jetbrains.kotlin.gradle.plugin.loadKotlinVersionFromResource
|
||||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompilerDownloadTask
|
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanCompilerDownloadTask
|
||||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||||
@@ -288,6 +285,7 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
|||||||
|
|
||||||
private fun ProjectInternal.addCompilerDownloadingTask(): KonanCompilerDownloadTask {
|
private fun ProjectInternal.addCompilerDownloadingTask(): KonanCompilerDownloadTask {
|
||||||
val result = tasks.create(KonanPlugin.KONAN_DOWNLOAD_TASK_NAME, KonanCompilerDownloadTask::class.java)
|
val result = tasks.create(KonanPlugin.KONAN_DOWNLOAD_TASK_NAME, KonanCompilerDownloadTask::class.java)
|
||||||
|
project.warnAboutDeprecatedProperty(KonanPlugin.ProjectProperty.KONAN_HOME)
|
||||||
if (!hasProperty(KonanPlugin.ProjectProperty.KONAN_HOME)) {
|
if (!hasProperty(KonanPlugin.ProjectProperty.KONAN_HOME)) {
|
||||||
setProperty(KonanPlugin.ProjectProperty.KONAN_HOME, project.konanCompilerDownloadDir())
|
setProperty(KonanPlugin.ProjectProperty.KONAN_HOME, project.konanCompilerDownloadDir())
|
||||||
setProperty(KonanPlugin.ProjectProperty.DOWNLOAD_COMPILER, true)
|
setProperty(KonanPlugin.ProjectProperty.DOWNLOAD_COMPILER, true)
|
||||||
|
|||||||
+26
-8
@@ -45,14 +45,30 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* We use the following properties:
|
* We use the following properties:
|
||||||
* konan.home - directory where compiler is located (aka dist in konan project output).
|
* org.jetbrains.kotlin.native.home - directory where compiler is located (aka dist in konan project output).
|
||||||
* konan.version - a konan compiler version for downloading.
|
* org.jetbrains.kotlin.native.version - a konan compiler version for downloading.
|
||||||
* konan.build.targets - list of targets to build (by default all the declared targets are built).
|
* konan.build.targets - list of targets to build (by default all the declared targets are built).
|
||||||
* konan.jvmArgs - additional args to be passed to a JVM executing the compiler/cinterop tool.
|
* konan.jvmArgs - additional args to be passed to a JVM executing the compiler/cinterop tool.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
internal fun Project.hasProperty(property: KonanPlugin.ProjectProperty) = hasProperty(property.propertyName)
|
internal fun Project.warnAboutDeprecatedProperty(property: KonanPlugin.ProjectProperty) =
|
||||||
internal fun Project.findProperty(property: KonanPlugin.ProjectProperty): Any? = findProperty(property.propertyName)
|
property.deprecatedPropertyName?.let { deprecated ->
|
||||||
|
if (project.hasProperty(deprecated)) {
|
||||||
|
logger.warn("Project property '$deprecated' is deprecated. Use '${property.propertyName}' instead.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun Project.hasProperty(property: KonanPlugin.ProjectProperty) = with(property) {
|
||||||
|
when {
|
||||||
|
hasProperty(propertyName) -> true
|
||||||
|
deprecatedPropertyName != null && hasProperty(deprecatedPropertyName) -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun Project.findProperty(property: KonanPlugin.ProjectProperty): Any? = with(property) {
|
||||||
|
return findProperty(propertyName) ?: deprecatedPropertyName?.let { findProperty(it) }
|
||||||
|
}
|
||||||
|
|
||||||
internal fun Project.getProperty(property: KonanPlugin.ProjectProperty) = findProperty(property)
|
internal fun Project.getProperty(property: KonanPlugin.ProjectProperty) = findProperty(property)
|
||||||
?: throw IllegalArgumentException("No such property in the project: ${property.propertyName}")
|
?: throw IllegalArgumentException("No such property in the project: ${property.propertyName}")
|
||||||
@@ -270,8 +286,8 @@ open class KonanSoftwareComponent(val project: ProjectInternal?): SoftwareCompon
|
|||||||
class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderRegistry)
|
class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderRegistry)
|
||||||
: Plugin<ProjectInternal> {
|
: Plugin<ProjectInternal> {
|
||||||
|
|
||||||
enum class ProjectProperty(val propertyName: String) {
|
enum class ProjectProperty(val propertyName: String, val deprecatedPropertyName: String? = null) {
|
||||||
KONAN_HOME ("konan.home"),
|
KONAN_HOME ("org.jetbrains.kotlin.native.home", "konan.home"),
|
||||||
KONAN_VERSION ("org.jetbrains.kotlin.native.version"),
|
KONAN_VERSION ("org.jetbrains.kotlin.native.version"),
|
||||||
KONAN_BUILD_TARGETS ("konan.build.targets"),
|
KONAN_BUILD_TARGETS ("konan.build.targets"),
|
||||||
KONAN_JVM_ARGS ("konan.jvmArgs"),
|
KONAN_JVM_ARGS ("konan.jvmArgs"),
|
||||||
@@ -328,6 +344,8 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
|
|||||||
project.logger.warn("feature GRADLE_METADATA is not enabled: publication is disabled")
|
project.logger.warn("feature GRADLE_METADATA is not enabled: publication is disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
project.warnAboutDeprecatedProperty(ProjectProperty.KONAN_HOME)
|
||||||
|
|
||||||
// Set additional project properties like konan.home, konan.build.targets etc.
|
// Set additional project properties like konan.home, konan.build.targets etc.
|
||||||
if (!project.hasProperty(ProjectProperty.KONAN_HOME)) {
|
if (!project.hasProperty(ProjectProperty.KONAN_HOME)) {
|
||||||
project.setProperty(ProjectProperty.KONAN_HOME, project.konanCompilerDownloadDir())
|
project.setProperty(ProjectProperty.KONAN_HOME, project.konanCompilerDownloadDir())
|
||||||
|
|||||||
+1
-1
@@ -214,7 +214,7 @@ class KonanProject {
|
|||||||
/** Generates gradle.properties file with the konan.home and konan.jvmArgs properties set. */
|
/** Generates gradle.properties file with the konan.home and konan.jvmArgs properties set. */
|
||||||
File generatePropertiesFile(String konanHome, String konanJvmArgs = System.getProperty("konan.jvmArgs") ?: "") {
|
File generatePropertiesFile(String konanHome, String konanJvmArgs = System.getProperty("konan.jvmArgs") ?: "") {
|
||||||
propertiesFile = createFile(projectPath, "gradle.properties", """\
|
propertiesFile = createFile(projectPath, "gradle.properties", """\
|
||||||
konan.home=$konanHome
|
org.jetbrains.kotlin.native.home=$konanHome
|
||||||
${!konanJvmArgs.isEmpty() ? "konan.jvmArgs=$konanJvmArgs\n" : ""}
|
${!konanJvmArgs.isEmpty() ? "konan.jvmArgs=$konanJvmArgs\n" : ""}
|
||||||
""".stripIndent())
|
""".stripIndent())
|
||||||
return propertiesFile
|
return propertiesFile
|
||||||
|
|||||||
@@ -1019,7 +1019,21 @@ class ExperimentalPluginTests {
|
|||||||
"-i"
|
"-i"
|
||||||
).build()
|
).build()
|
||||||
assertTrue(result.output.contains(
|
assertTrue(result.output.contains(
|
||||||
"Downloading Kotlin/Native compiler from.*kotlin-native-${HostManager.simpleOsName()}-0.9.3".toRegex())
|
"Downloading Kotlin/Native compiler from.*kotlin-native-${HostManager.simpleOsName()}-0.9.3".toRegex()
|
||||||
)
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Plugin should show warning if deprecated properties are used`() {
|
||||||
|
val project = KonanProject.createEmpty(projectDirectory).apply {
|
||||||
|
buildFile.writeText("plugins { id 'kotlin-native' }")
|
||||||
|
val properties = propertiesFile.readText().replace("org.jetbrains.kotlin.native.home", "konan.home")
|
||||||
|
propertiesFile.writeText(properties)
|
||||||
|
}
|
||||||
|
|
||||||
|
val result = project.createRunner().withArguments("tasks").build()
|
||||||
|
assertTrue(result.output.contains(
|
||||||
|
"Project property 'konan.home' is deprecated. Use 'org.jetbrains.kotlin.native.home' instead."
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ open class ToolingModelTests {
|
|||||||
dependsOn('compileKonanBaz')
|
dependsOn('compileKonanBaz')
|
||||||
doLast {
|
doLast {
|
||||||
def model = KonanToolingModelBuilder.INSTANCE.buildAll("KonanModel", project)
|
def model = KonanToolingModelBuilder.INSTANCE.buildAll("KonanModel", project)
|
||||||
assertEquals(model.konanHome, file(project.getProperty('konan.home')))
|
assertEquals(model.konanHome, file(project.getProperty('org.jetbrains.kotlin.native.home')))
|
||||||
assertEquals(model.konanVersion.toString(), "$konanVersion")
|
assertEquals(model.konanVersion.toString(), "$konanVersion")
|
||||||
|
|
||||||
assertEquals(model.languageVersion, "1.2")
|
assertEquals(model.languageVersion, "1.2")
|
||||||
|
|||||||
Reference in New Issue
Block a user