Native deployment update

This commit is contained in:
Alexander Nozik 2020-09-27 17:45:40 +03:00
parent 981687ee5e
commit f4e13a9979
3 changed files with 144 additions and 51 deletions

View File

@ -27,8 +27,8 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") implementation("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4") implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.0") implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.10")
implementation("org.jetbrains.dokka:dokka-base:1.4.0") implementation("org.jetbrains.dokka:dokka-base:1.4.10")
implementation("org.jetbrains.intellij.plugins:gradle-changelog-plugin:0.5.0") implementation("org.jetbrains.intellij.plugins:gradle-changelog-plugin:0.5.0")
} }

View File

@ -15,24 +15,61 @@ class KScienceNativePlugin : Plugin<Project> {
} }
configure<KotlinMultiplatformExtension> { configure<KotlinMultiplatformExtension> {
val hostOs = System.getProperty("os.name") val ideaActive = System.getProperty("idea.active") == "true"
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when { if (ideaActive) {
hostOs == "Mac OS X" -> macosX64("native") //development mode
hostOs == "Linux" -> linuxX64("native") val hostOs = System.getProperty("os.name")
isMingwX64 -> {
mingwX64("native") when {
linuxX64() hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
hostOs.startsWith("Windows") -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
} }
else -> throw GradleException("Host OS is not supported in Kotlin/Native.") } else {
} //deploy mode
linuxX64()
mingwX64()
macosX64()
sourceSets.invoke { sourceSets{
val nativeMain by getting val commonMain by getting
findByName("linuxX64Main")?.dependsOn(nativeMain) val nativeMain by creating{
val nativeTest by getting dependsOn(commonMain)
findByName("linuxX64Test")?.dependsOn(nativeTest) }
val commonTest by getting
val nativeTest by creating{
dependsOn(nativeMain)
dependsOn(commonTest)
}
val linuxX64Main by getting{
dependsOn(nativeMain)
}
val mingwX64Main by getting{
dependsOn(nativeMain)
}
val macosX64Main by getting{
dependsOn(nativeMain)
}
val linuxX64Test by getting{
dependsOn(nativeTest)
}
val mingwX64Test by getting{
dependsOn(nativeTest)
}
val macosX64Test by getting{
dependsOn(nativeTest)
}
}
} }
} }
} }

View File

@ -3,15 +3,13 @@ package ru.mipt.npm.gradle
import groovy.text.SimpleTemplateEngine import groovy.text.SimpleTemplateEngine
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.*
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.provideDelegate
import org.jetbrains.changelog.ChangelogPlugin import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask
import java.io.File import java.io.File
import kotlin.collections.component1 import kotlin.collections.component1
import kotlin.collections.component2 import kotlin.collections.component2
import kotlin.reflect.KFunction
class KSciencePublishingExtension(val project: Project) { class KSciencePublishingExtension(val project: Project) {
var githubOrg: String? by project.extra var githubOrg: String? by project.extra
@ -36,7 +34,7 @@ class KScienceReadmeExtension(val project: Project) {
var description: String = "" var description: String = ""
var maturity: Maturity = Maturity.EXPERIMENTAL var maturity: Maturity = Maturity.EXPERIMENTAL
var readmeTemplate: File = project.file("docs/README-TEMPLATE.md")//"docs/README-TEMPLATE.md" var readmeTemplate: File = project.file("docs/README-TEMPLATE.md")
data class Feature(val id: String, val ref: String, val description: String, val name: String = id) data class Feature(val id: String, val ref: String, val description: String, val name: String = id)
@ -46,31 +44,32 @@ class KScienceReadmeExtension(val project: Project) {
features.add(Feature(id, ref, description, name)) features.add(Feature(id, ref, description, name))
} }
val properties: MutableMap<String, Any?> = mutableMapOf( val properties: MutableMap<String, () -> Any?> = mutableMapOf(
"name" to project.name, "name" to { project.name },
"group" to project.group, "group" to { project.group },
"version" to project.version, "version" to { project.version },
"features" to featuresString() "features" to { featuresString() }
) )
private val actualizedProperties get() = properties.mapValues {(_,value)-> private fun getActualizedProperties() = properties.mapValues { (_, value) ->
if(value is KFunction<*>){ value.invoke()
value.call()
} else {
value
}
} }
fun property(key: String, value: Any?) { fun property(key: String, value: Any?) {
properties[key] = value properties[key] = {value}
} }
fun propertyByTemplate(key: String, template: String){ fun propertyByTemplate(key: String, template: String) {
properties[key] = SimpleTemplateEngine().createTemplate(template).make(actualizedProperties).toString() val actual = getActualizedProperties()
properties[key] = {SimpleTemplateEngine().createTemplate(template).make(actual).toString()}
} }
fun propertyByTemplate(key: String, template: File){ internal val additionalFiles = ArrayList<File>()
properties[key] = SimpleTemplateEngine().createTemplate(template).make(actualizedProperties).toString()
fun propertyByTemplate(key: String, template: File) {
val actual = getActualizedProperties()
properties[key] = {SimpleTemplateEngine().createTemplate(template).make(actual).toString()}
additionalFiles.add(template)
} }
/** /**
@ -87,7 +86,8 @@ class KScienceReadmeExtension(val project: Project) {
*/ */
fun readmeString(): String? { fun readmeString(): String? {
return if (readmeTemplate.exists()) { return if (readmeTemplate.exists()) {
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actualizedProperties).toString() val actual = getActualizedProperties()
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString()
} else { } else {
null null
} }
@ -100,6 +100,7 @@ class KScienceReadmeExtension(val project: Project) {
open class KScienceProjectPlugin : Plugin<Project> { open class KScienceProjectPlugin : Plugin<Project> {
override fun apply(target: Project): Unit = target.run { override fun apply(target: Project): Unit = target.run {
apply<ChangelogPlugin>() apply<ChangelogPlugin>()
apply<DokkaPlugin>()
val rootReadmeExtension = KScienceReadmeExtension(this) val rootReadmeExtension = KScienceReadmeExtension(this)
extensions.add("ksciencePublish", KSciencePublishingExtension(this)) extensions.add("ksciencePublish", KSciencePublishingExtension(this))
extensions.add("readme", rootReadmeExtension) extensions.add("readme", rootReadmeExtension)
@ -108,25 +109,57 @@ open class KScienceProjectPlugin : Plugin<Project> {
subprojects { subprojects {
val readmeExtension = KScienceReadmeExtension(this) val readmeExtension = KScienceReadmeExtension(this)
extensions.add("readme", readmeExtension) extensions.add("readme", readmeExtension)
tasks.create("generateReadme") { val generateReadme by tasks.creating {
group = "documentation" group = "documentation"
description = "Generate a README file if stub is present" description = "Generate a README file if stub is present"
if(readmeExtension.readmeTemplate.exists()) {
inputs.file(readmeExtension.readmeTemplate)
}
readmeExtension.additionalFiles.forEach {
if(it.exists()){
inputs.file(it)
}
}
val readmeFile = this@subprojects.file("README.md")
outputs.file(readmeFile)
doLast { doLast {
val readmeString = readmeExtension.readmeString() val readmeString = readmeExtension.readmeString()
if (readmeString != null) { if (readmeString != null) {
val readmeFile = this@subprojects.file("README.md")
readmeFile.writeText(readmeString) readmeFile.writeText(readmeString)
} }
} }
} }
tasks.withType<DokkaTask>{
dependsOn(generateReadme)
}
} }
tasks.create("generateReadme") { val generateReadme by tasks.creating {
group = "documentation" group = "documentation"
description = "Generate a README file and a feature matrix if stub is present" description = "Generate a README file and a feature matrix if stub is present"
subprojects {
tasks.findByName("generateReadme")?.let {
dependsOn(it)
}
}
if(rootReadmeExtension.readmeTemplate.exists()) {
inputs.file(rootReadmeExtension.readmeTemplate)
}
rootReadmeExtension.additionalFiles.forEach {
if(it.exists()){
inputs.file(it)
}
}
val readmeFile = project.file("README.md")
outputs.file(readmeFile)
doLast { doLast {
val reader = groovy.json.JsonSlurper()
val projects = subprojects.associate { val projects = subprojects.associate {
it.name to it.extensions.findByType<KScienceReadmeExtension>() it.name to it.extensions.findByType<KScienceReadmeExtension>()
} }
@ -135,14 +168,19 @@ open class KScienceProjectPlugin : Plugin<Project> {
val modulesString = buildString { val modulesString = buildString {
projects.entries.forEach { (name, ext) -> projects.entries.forEach { (name, ext) ->
appendln("### [$name]($name)") appendln("<hr/>")
appendln("\n* ### [$name]($name)")
if (ext != null) { if (ext != null) {
appendln(ext.description) appendln("> ${ext.description}")
appendln("**Maturity**: ${ext.maturity}") appendln(">\n> **Maturity**: ${ext.maturity}")
appendln("#### Features:") val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$name/")
appendln(ext.featuresString(pathPrefix = "$name/")) if(featureString.isNotBlank()) {
appendln(">\n> **Features:**")
appendln(featureString)
}
} }
} }
appendln("<hr/>")
} }
val rootReadmeProperties: Map<String, Any?> = mapOf( val rootReadmeProperties: Map<String, Any?> = mapOf(
@ -152,13 +190,31 @@ open class KScienceProjectPlugin : Plugin<Project> {
"modules" to modulesString "modules" to modulesString
) )
val readmeFile = project.file("README.md")
readmeFile.writeText( readmeFile.writeText(
SimpleTemplateEngine().createTemplate(rootReadmeExtension.readmeTemplate).make(rootReadmeProperties).toString() SimpleTemplateEngine().createTemplate(rootReadmeExtension.readmeTemplate)
.make(rootReadmeProperties).toString()
) )
} }
} }
} }
tasks.withType<DokkaTask>{
dependsOn(generateReadme)
}
val patchChangelog by tasks.getting
val release by tasks.creating{
group = RELEASE_GROUP
description = "Publish development or production release based on version suffix"
dependsOn(generateReadme, patchChangelog)
tasks.findByName("publishAllPublicationsToBintrayRepository")?.let {
dependsOn(it)
}
}
}
companion object{
const val RELEASE_GROUP = "release"
} }
} }