[gradle-plugin] Support multiplatform projects in current DSL.
This commit is contained in:
@@ -76,6 +76,7 @@ configurations {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
compile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion"
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion"
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$buildKotlinVersion"
|
||||||
compile gradleApi()
|
compile gradleApi()
|
||||||
|
|
||||||
bundleDependencies "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
bundleDependencies "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
||||||
@@ -119,15 +120,23 @@ processResources {
|
|||||||
from(file("$rootBuildDirectory/utilities/env_blacklist"))
|
from(file("$rootBuildDirectory/utilities/env_blacklist"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Get rid of manual pom generation
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
gradlePlugin(MavenPublication) {
|
gradlePlugin(MavenPublication) {
|
||||||
artifact shadowJar
|
artifact shadowJar
|
||||||
pom.withXml { XmlProvider xml ->
|
pom.withXml { XmlProvider xml ->
|
||||||
def stdlibDep = xml.asNode().appendNode("dependencies").appendNode("dependency")
|
def deps = xml.asNode().appendNode("dependencies")
|
||||||
|
|
||||||
|
def stdlibDep = deps.appendNode("dependency")
|
||||||
stdlibDep.appendNode("groupId", "org.jetbrains.kotlin")
|
stdlibDep.appendNode("groupId", "org.jetbrains.kotlin")
|
||||||
stdlibDep.appendNode("artifactId", "kotlin-stdlib")
|
stdlibDep.appendNode("artifactId", "kotlin-stdlib")
|
||||||
stdlibDep.appendNode("version", "$buildKotlinVersion")
|
stdlibDep.appendNode("version", "$buildKotlinVersion")
|
||||||
|
|
||||||
|
def kotlinPluginDep = deps.appendNode("dependency")
|
||||||
|
kotlinPluginDep.appendNode("groupId", "org.jetbrains.kotlin")
|
||||||
|
kotlinPluginDep.appendNode("artifactId", "kotlin-gradle-plugin")
|
||||||
|
kotlinPluginDep.appendNode("version", "$buildKotlinVersion")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin
|
package org.jetbrains.kotlin.gradle.plugin
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.internal.project.ProjectInternal
|
import org.gradle.api.internal.project.ProjectInternal
|
||||||
@@ -51,6 +52,14 @@ abstract class KonanCompileConfig<T: KonanCompileTask>(name: String,
|
|||||||
override fun nativeLibraries(vararg libs: Any) = forEach { it.nativeLibraries(*libs) }
|
override fun nativeLibraries(vararg libs: Any) = forEach { it.nativeLibraries(*libs) }
|
||||||
override fun nativeLibraries(libs: FileCollection) = forEach { it.nativeLibraries(libs) }
|
override fun nativeLibraries(libs: FileCollection) = forEach { it.nativeLibraries(libs) }
|
||||||
|
|
||||||
|
override fun expectedBy(parameters: Map<String, Any>) = forEach { it.expectedBy(parameters) }
|
||||||
|
override fun expectedBy(commonProject: String) = forEach { it.expectedBy(commonProject) }
|
||||||
|
override fun expectedBy(commonProject: Project) = forEach { it.expectedBy(commonProject) }
|
||||||
|
override fun expectedBy(commonProject: String, sourceSetName: String) =
|
||||||
|
forEach { it.expectedBy(commonProject, sourceSetName) }
|
||||||
|
override fun expectedBy(commonProject: Project, sourceSetName: String) =
|
||||||
|
forEach { it.expectedBy(commonProject, sourceSetName) }
|
||||||
|
|
||||||
override fun linkerOpts(values: List<String>) = forEach { it.linkerOpts(values) }
|
override fun linkerOpts(values: List<String>) = forEach { it.linkerOpts(values) }
|
||||||
override fun linkerOpts(vararg values: String) = forEach { it.linkerOpts(*values) }
|
override fun linkerOpts(vararg values: String) = forEach { it.linkerOpts(*values) }
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -23,8 +23,8 @@ import org.gradle.api.file.FileCollection
|
|||||||
import org.gradle.api.internal.project.ProjectInternal
|
import org.gradle.api.internal.project.ProjectInternal
|
||||||
import org.gradle.internal.reflect.Instantiator
|
import org.gradle.internal.reflect.Instantiator
|
||||||
import org.gradle.util.ConfigureUtil
|
import org.gradle.util.ConfigureUtil
|
||||||
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanInteropTask
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KonanInteropSpec.IncludeDirectoriesSpec
|
import org.jetbrains.kotlin.gradle.plugin.KonanInteropSpec.IncludeDirectoriesSpec
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.tasks.KonanInteropTask
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|||||||
+8
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.plugin
|
|||||||
|
|
||||||
import groovy.lang.Closure
|
import groovy.lang.Closure
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
|
|
||||||
interface KonanArtifactSpec {
|
interface KonanArtifactSpec {
|
||||||
@@ -51,6 +52,13 @@ interface KonanCompileSpec: KonanBuildingSpec {
|
|||||||
fun nativeLibraries(vararg libs: Any)
|
fun nativeLibraries(vararg libs: Any)
|
||||||
fun nativeLibraries(libs: FileCollection)
|
fun nativeLibraries(libs: FileCollection)
|
||||||
|
|
||||||
|
// DSL. Mutliplatform projects
|
||||||
|
fun expectedBy(parameters: Map<String, Any>)
|
||||||
|
fun expectedBy(commonProject: String, sourceSetName: String)
|
||||||
|
fun expectedBy(commonProject: String)
|
||||||
|
fun expectedBy(commonProject: Project)
|
||||||
|
fun expectedBy(commonProject: Project, sourceSetName: String)
|
||||||
|
|
||||||
// DSL. Other parameters.
|
// DSL. Other parameters.
|
||||||
|
|
||||||
fun linkerOpts(vararg values: String)
|
fun linkerOpts(vararg values: String)
|
||||||
|
|||||||
+103
-6
@@ -16,7 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin.tasks
|
package org.jetbrains.kotlin.gradle.plugin.tasks
|
||||||
|
|
||||||
|
import org.gradle.api.GradleException
|
||||||
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
|
import org.gradle.api.file.SourceDirectorySet
|
||||||
|
import org.gradle.api.internal.HasConvention
|
||||||
|
import org.gradle.api.plugins.JavaPluginConvention
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||||
@@ -36,7 +41,6 @@ enum class Produce(val cliOption: String, val kind: CompilerOutputKind) {
|
|||||||
*/
|
*/
|
||||||
abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
||||||
|
|
||||||
// TODO: Support custom runner options (java options)
|
|
||||||
@Internal override val toolRunner = KonanCompilerRunner(project)
|
@Internal override val toolRunner = KonanCompilerRunner(project)
|
||||||
|
|
||||||
abstract val produce: Produce
|
abstract val produce: Produce
|
||||||
@@ -50,6 +54,16 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
override val artifactPrefix: String
|
override val artifactPrefix: String
|
||||||
@Internal get() = produce.kind.prefix(konanTarget)
|
@Internal get() = produce.kind.prefix(konanTarget)
|
||||||
|
|
||||||
|
// Mutliplatform support --------------------------------------------------
|
||||||
|
|
||||||
|
internal var commonProject: Project? = null
|
||||||
|
internal set
|
||||||
|
@Internal get
|
||||||
|
|
||||||
|
@InputFiles val commonSrcFiles = mutableSetOf<FileCollection>()
|
||||||
|
|
||||||
|
@Internal protected val defaultSourceSetName = "main"
|
||||||
|
|
||||||
// Other compilation parameters -------------------------------------------
|
// Other compilation parameters -------------------------------------------
|
||||||
|
|
||||||
protected val srcFiles_ = mutableSetOf<FileCollection>()
|
protected val srcFiles_ = mutableSetOf<FileCollection>()
|
||||||
@@ -78,6 +92,11 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
val apiVersion : String?
|
val apiVersion : String?
|
||||||
@Optional @Input get() = project.konanExtension.apiVersion
|
@Optional @Input get() = project.konanExtension.apiVersion
|
||||||
|
|
||||||
|
protected fun directoryToKt(dir: Any) = project.fileTree(dir).apply {
|
||||||
|
include("**/*.kt")
|
||||||
|
exclude { it.file.startsWith(project.buildDir) }
|
||||||
|
}
|
||||||
|
|
||||||
// Command line ------------------------------------------------------------
|
// Command line ------------------------------------------------------------
|
||||||
|
|
||||||
override fun buildArgs() = mutableListOf<String>().apply {
|
override fun buildArgs() = mutableListOf<String>().apply {
|
||||||
@@ -106,10 +125,13 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
addKey("-ea", enableAssertions)
|
addKey("-ea", enableAssertions)
|
||||||
addKey("--time", measureTime)
|
addKey("--time", measureTime)
|
||||||
addKey("-nodefaultlibs", noDefaultLibs)
|
addKey("-nodefaultlibs", noDefaultLibs)
|
||||||
|
addKey("-Xmulti-platform", commonProject != null)
|
||||||
|
|
||||||
addAll(extraOpts)
|
addAll(extraOpts)
|
||||||
|
|
||||||
srcFiles.flatMap { it.files }.filter { it.name.endsWith(".kt") }.mapTo(this) { it.canonicalPath }
|
listOf(srcFiles, commonSrcFiles).forEach {
|
||||||
|
it.flatMap { it.files }.filter { it.name.endsWith(".kt") }.mapTo(this) { it.canonicalPath }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// region DSL.
|
// region DSL.
|
||||||
@@ -117,10 +139,7 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
// DSL. Input/output files.
|
// DSL. Input/output files.
|
||||||
|
|
||||||
override fun srcDir(dir: Any) {
|
override fun srcDir(dir: Any) {
|
||||||
srcFiles_.add(project.fileTree(dir).apply {
|
srcFiles_.add(directoryToKt(dir))
|
||||||
include("**/*.kt")
|
|
||||||
exclude { it.file.startsWith(project.buildDir) }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
override fun srcFiles(vararg files: Any) {
|
override fun srcFiles(vararg files: Any) {
|
||||||
srcFiles_.add(project.files(files))
|
srcFiles_.add(project.files(files))
|
||||||
@@ -137,6 +156,53 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
nativeLibraries.add(libs)
|
nativeLibraries.add(libs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DSL. Multiplatform projects.
|
||||||
|
|
||||||
|
override fun expectedBy(parameters: Map<String, Any>) {
|
||||||
|
val project = parameters[PROJECT_KEY] ?:
|
||||||
|
throw GradleException("A project should be passed to expectedBy method")
|
||||||
|
val sourceSetName = parameters[SOURCE_SET_KEY] ?: defaultSourceSetName
|
||||||
|
|
||||||
|
if (sourceSetName !is String) {
|
||||||
|
throw GradleException("sourceSet parameter of expectedBy should be String")
|
||||||
|
}
|
||||||
|
|
||||||
|
when (project) {
|
||||||
|
is Project -> expectedBy(project, sourceSetName)
|
||||||
|
is String -> expectedBy(project, sourceSetName)
|
||||||
|
else -> throw GradleException("project parameter of expectedBy should be String")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun expectedBy(commonProject: String, sourceSetName: String) = expectedBy(project.project(commonProject), sourceSetName)
|
||||||
|
override fun expectedBy(commonProject: String) = expectedBy(commonProject, defaultSourceSetName)
|
||||||
|
override fun expectedBy(commonProject: Project) = expectedBy(commonProject, defaultSourceSetName)
|
||||||
|
override fun expectedBy(commonProject: Project, sourceSetName: String) {
|
||||||
|
if (this.commonProject != null) {
|
||||||
|
throw GradleException("Artifact ${artifactName} has more then one expectedBy dependency")
|
||||||
|
}
|
||||||
|
|
||||||
|
this.commonProject = commonProject
|
||||||
|
|
||||||
|
commonProject.whenEvaluated {
|
||||||
|
if (!commonProject.pluginManager.hasPlugin("kotlin-platform-common")) {
|
||||||
|
throw GradleException("Artifact ${artifactName} of project ${this@KonanCompileTask.project.path} " +
|
||||||
|
"has an expectedBy dependency to a non-common project ${this.path}")
|
||||||
|
}
|
||||||
|
|
||||||
|
val commonSourceSet = commonProject.sourceSets.let {
|
||||||
|
it.findByName(sourceSetName) ?: run {
|
||||||
|
logger.warn("Cannot find a source set ${sourceSetName} in project ${this.path}. " +
|
||||||
|
"Use the default one: ${defaultSourceSetName}")
|
||||||
|
it.getByName(defaultSourceSetName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commonSourceSet.kotlin!!.srcDirs.forEach {
|
||||||
|
commonSrcFiles.add(directoryToKt(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DSL. Other parameters.
|
// DSL. Other parameters.
|
||||||
|
|
||||||
override fun linkerOpts(values: List<String>) = linkerOpts(*values.toTypedArray())
|
override fun linkerOpts(values: List<String>) = linkerOpts(*values.toTypedArray())
|
||||||
@@ -172,6 +238,37 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
measureTime = flag
|
measureTime = flag
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
// Some functions from Kotlin Gradle plugin.
|
||||||
|
protected fun Project.whenEvaluated(fn: Project.() -> Unit) {
|
||||||
|
if (state.executed) {
|
||||||
|
fn()
|
||||||
|
} else {
|
||||||
|
afterEvaluate { it.fn() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected val Project.sourceSets: SourceSetContainer
|
||||||
|
get() = convention.getPlugin(JavaPluginConvention::class.java).sourceSets
|
||||||
|
|
||||||
|
protected val SourceSet.kotlin: SourceDirectorySet?
|
||||||
|
get() {
|
||||||
|
// Access through reflection, because another project's KotlinSourceSet might be loaded
|
||||||
|
// by a different class loader:
|
||||||
|
val convention = (getConvention("kotlin") ?: getConvention("kotlin2js")) ?: return null
|
||||||
|
val kotlinSourceSetIface = convention.javaClass.interfaces.find { it.name == KotlinSourceSet::class.qualifiedName }
|
||||||
|
val getKotlin = kotlinSourceSetIface?.methods?.find { it.name == "getKotlin" } ?: return null
|
||||||
|
return getKotlin(convention) as? SourceDirectorySet
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun Any.getConvention(name: String): Any? =
|
||||||
|
(this as HasConvention).convention.plugins[name]
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val PROJECT_KEY = "project"
|
||||||
|
const val SOURCE_SET_KEY = "sourceSet"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open class KonanCompileProgramTask: KonanCompileTask() {
|
open class KonanCompileProgramTask: KonanCompileTask() {
|
||||||
|
|||||||
+3
-1
@@ -21,7 +21,9 @@ import org.gradle.api.GradleScriptException
|
|||||||
import org.gradle.api.tasks.Internal
|
import org.gradle.api.tasks.Internal
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.konan.util.*
|
import org.jetbrains.kotlin.konan.util.DependencyProcessor
|
||||||
|
import org.jetbrains.kotlin.konan.util.DependencySource
|
||||||
|
import org.jetbrains.kotlin.konan.util.visibleName
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user