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-serialization:$kotlinVersion")
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-base:1.4.0")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.10")
implementation("org.jetbrains.dokka:dokka-base:1.4.10")
implementation("org.jetbrains.intellij.plugins:gradle-changelog-plugin:0.5.0")
}

View File

@ -15,24 +15,61 @@ class KScienceNativePlugin : Plugin<Project> {
}
configure<KotlinMultiplatformExtension> {
val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val ideaActive = System.getProperty("idea.active") == "true"
val nativeTarget = when {
if (ideaActive) {
//development mode
val hostOs = System.getProperty("os.name")
when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> {
mingwX64("native")
linuxX64()
}
hostOs.startsWith("Windows") -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}
} else {
//deploy mode
linuxX64()
mingwX64()
macosX64()
sourceSets.invoke {
val nativeMain by getting
findByName("linuxX64Main")?.dependsOn(nativeMain)
val nativeTest by getting
findByName("linuxX64Test")?.dependsOn(nativeTest)
sourceSets{
val commonMain by getting
val nativeMain by creating{
dependsOn(commonMain)
}
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 org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.*
import org.jetbrains.changelog.ChangelogPlugin
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask
import java.io.File
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.reflect.KFunction
class KSciencePublishingExtension(val project: Project) {
var githubOrg: String? by project.extra
@ -36,7 +34,7 @@ class KScienceReadmeExtension(val project: Project) {
var description: String = ""
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)
@ -46,31 +44,32 @@ class KScienceReadmeExtension(val project: Project) {
features.add(Feature(id, ref, description, name))
}
val properties: MutableMap<String, Any?> = mutableMapOf(
"name" to project.name,
"group" to project.group,
"version" to project.version,
"features" to featuresString()
val properties: MutableMap<String, () -> Any?> = mutableMapOf(
"name" to { project.name },
"group" to { project.group },
"version" to { project.version },
"features" to { featuresString() }
)
private val actualizedProperties get() = properties.mapValues {(_,value)->
if(value is KFunction<*>){
value.call()
} else {
value
}
private fun getActualizedProperties() = properties.mapValues { (_, value) ->
value.invoke()
}
fun property(key: String, value: Any?) {
properties[key] = value
properties[key] = {value}
}
fun propertyByTemplate(key: String, template: String){
properties[key] = SimpleTemplateEngine().createTemplate(template).make(actualizedProperties).toString()
fun propertyByTemplate(key: String, template: String) {
val actual = getActualizedProperties()
properties[key] = {SimpleTemplateEngine().createTemplate(template).make(actual).toString()}
}
fun propertyByTemplate(key: String, template: File){
properties[key] = SimpleTemplateEngine().createTemplate(template).make(actualizedProperties).toString()
internal val additionalFiles = ArrayList<File>()
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? {
return if (readmeTemplate.exists()) {
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actualizedProperties).toString()
val actual = getActualizedProperties()
SimpleTemplateEngine().createTemplate(readmeTemplate).make(actual).toString()
} else {
null
}
@ -100,6 +100,7 @@ class KScienceReadmeExtension(val project: Project) {
open class KScienceProjectPlugin : Plugin<Project> {
override fun apply(target: Project): Unit = target.run {
apply<ChangelogPlugin>()
apply<DokkaPlugin>()
val rootReadmeExtension = KScienceReadmeExtension(this)
extensions.add("ksciencePublish", KSciencePublishingExtension(this))
extensions.add("readme", rootReadmeExtension)
@ -108,25 +109,57 @@ open class KScienceProjectPlugin : Plugin<Project> {
subprojects {
val readmeExtension = KScienceReadmeExtension(this)
extensions.add("readme", readmeExtension)
tasks.create("generateReadme") {
val generateReadme by tasks.creating {
group = "documentation"
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 {
val readmeString = readmeExtension.readmeString()
if (readmeString != null) {
val readmeFile = this@subprojects.file("README.md")
readmeFile.writeText(readmeString)
}
}
}
tasks.withType<DokkaTask>{
dependsOn(generateReadme)
}
}
tasks.create("generateReadme") {
val generateReadme by tasks.creating {
group = "documentation"
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 {
val reader = groovy.json.JsonSlurper()
val projects = subprojects.associate {
it.name to it.extensions.findByType<KScienceReadmeExtension>()
}
@ -135,15 +168,20 @@ open class KScienceProjectPlugin : Plugin<Project> {
val modulesString = buildString {
projects.entries.forEach { (name, ext) ->
appendln("### [$name]($name)")
appendln("<hr/>")
appendln("\n* ### [$name]($name)")
if (ext != null) {
appendln(ext.description)
appendln("**Maturity**: ${ext.maturity}")
appendln("#### Features:")
appendln(ext.featuresString(pathPrefix = "$name/"))
appendln("> ${ext.description}")
appendln(">\n> **Maturity**: ${ext.maturity}")
val featureString = ext.featuresString(itemPrefix = "> - ", pathPrefix = "$name/")
if(featureString.isNotBlank()) {
appendln(">\n> **Features:**")
appendln(featureString)
}
}
}
appendln("<hr/>")
}
val rootReadmeProperties: Map<String, Any?> = mapOf(
"name" to project.name,
@ -152,13 +190,31 @@ open class KScienceProjectPlugin : Plugin<Project> {
"modules" to modulesString
)
val readmeFile = project.file("README.md")
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"
}
}