[gradle-plugin] Allow setting several common source sets
This commit is contained in:
+8
-7
@@ -242,12 +242,12 @@ project to a common project:
|
|||||||
}
|
}
|
||||||
|
|
||||||
When a common project is added as an `expectedBy` dependency, all the artifacts with the multiplatform support enabled
|
When a common project is added as an `expectedBy` dependency, all the artifacts with the multiplatform support enabled
|
||||||
will use it's `main` source set as a common module. One may specify a custom source set for each artifact using the
|
will use it's `main` source set as a common module. One may specify custom source sets for each artifact using the
|
||||||
`commonSourceSet` DSL method. In this case the multiplatform support will be also enabled for this artifact.
|
`commonSourceSets` DSL method. In this case the multiplatform support will be also enabled for this artifact.
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
program('foo') {
|
program('foo') {
|
||||||
commonSourceSet 'customSourceSet'
|
commonSourceSets 'customSourceSet', 'anotherCustomSourceSet'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,7 +279,7 @@ for each an artifact defined in a `konanArtifacts` block. Such a task may have d
|
|||||||
|`enableAssertions `|`boolean` |Is the assertion support enabled |
|
|`enableAssertions `|`boolean` |Is the assertion support enabled |
|
||||||
|`measureTime `|`boolean` |Does the compiler print phase time |
|
|`measureTime `|`boolean` |Does the compiler print phase time |
|
||||||
|`enableMultiplatform`|`boolean` |Is multiplatform support enabled for this artifact |
|
|`enableMultiplatform`|`boolean` |Is multiplatform support enabled for this artifact |
|
||||||
|`commonSourceSet` |`String` |Name of a source set used as a common module |
|
|`commonSourceSets` |`Collection<String>` |Names of source sets used as a common module |
|
||||||
|
|
||||||
##### Properties available for a cinterop task (task building an interoperability library):
|
##### Properties available for a cinterop task (task building an interoperability library):
|
||||||
|
|
||||||
@@ -573,7 +573,7 @@ tables below.
|
|||||||
|
|
||||||
apply plugin: 'konan'
|
apply plugin: 'konan'
|
||||||
|
|
||||||
// In this example common code is located in 'bar' source set of ':common' project.
|
// In this example common code is located in 'foo' and 'bar' source sets of ':common' project.
|
||||||
|
|
||||||
konanArtifacts {
|
konanArtifacts {
|
||||||
// All the artifact types except interop libraries may use common modules.
|
// All the artifact types except interop libraries may use common modules.
|
||||||
@@ -583,8 +583,9 @@ tables below.
|
|||||||
// Enable multiplatform support for this artifact.
|
// Enable multiplatform support for this artifact.
|
||||||
enableMultiplatform true
|
enableMultiplatform true
|
||||||
|
|
||||||
// Set a custom name for a source set used as a common module.
|
// Set a custom names for source sets used as a common module.
|
||||||
commonSourceSet 'bar'
|
// The default source set is 'main'
|
||||||
|
commonSourceSets 'foo', 'bar'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -52,6 +52,7 @@ abstract class KonanCompileConfig<T: KonanCompileTask>(name: String,
|
|||||||
override fun nativeLibraries(libs: FileCollection) = forEach { it.nativeLibraries(libs) }
|
override fun nativeLibraries(libs: FileCollection) = forEach { it.nativeLibraries(libs) }
|
||||||
|
|
||||||
override fun commonSourceSet(sourceSetName: String) = forEach { it.commonSourceSet(sourceSetName) }
|
override fun commonSourceSet(sourceSetName: String) = forEach { it.commonSourceSet(sourceSetName) }
|
||||||
|
override fun commonSourceSets(vararg sourceSetNames: String) = forEach { it.commonSourceSets(*sourceSetNames) }
|
||||||
override fun enableMultiplatform(flag: Boolean) = forEach { it.enableMultiplatform(flag) }
|
override fun enableMultiplatform(flag: Boolean) = forEach { it.enableMultiplatform(flag) }
|
||||||
|
|
||||||
override fun linkerOpts(values: List<String>) = forEach { it.linkerOpts(values) }
|
override fun linkerOpts(values: List<String>) = forEach { it.linkerOpts(values) }
|
||||||
|
|||||||
+1
@@ -55,6 +55,7 @@ interface KonanCompileSpec: KonanBuildingSpec {
|
|||||||
// DSL. Multiplatform projects
|
// DSL. Multiplatform projects
|
||||||
fun enableMultiplatform(flag: Boolean)
|
fun enableMultiplatform(flag: Boolean)
|
||||||
fun commonSourceSet(sourceSetName: String)
|
fun commonSourceSet(sourceSetName: String)
|
||||||
|
fun commonSourceSets(vararg sourceSetNames: String)
|
||||||
|
|
||||||
// DSL. Other parameters.
|
// DSL. Other parameters.
|
||||||
|
|
||||||
|
|||||||
+10
-8
@@ -40,15 +40,17 @@ open class KotlinNativePlatformPlugin: KotlinPlatformImplementationPluginBase("n
|
|||||||
.withType(KonanCompileTask::class.java)
|
.withType(KonanCompileTask::class.java)
|
||||||
.filter { it.enableMultiplatform }
|
.filter { it.enableMultiplatform }
|
||||||
.forEach { task: KonanCompileTask ->
|
.forEach { task: KonanCompileTask ->
|
||||||
val commonSourceSet = commonProject.sourceSets.findByName(task.commonSourceSet) ?:
|
task.commonSourceSets.forEach { commonSourceSetName ->
|
||||||
throw GradleException("Cannot find a source set with name '${task.commonSourceSet}' " +
|
val commonSourceSet = commonProject.sourceSets.findByName(commonSourceSetName) ?:
|
||||||
"in a common project '${commonProject.path}' " +
|
throw GradleException("Cannot find a source set with name '${commonSourceSetName}' " +
|
||||||
"for an artifact '${task.artifactName}' " +
|
"in a common project '${commonProject.path}' " +
|
||||||
"in a platform project '${platformProject.path}'")
|
"for an artifact '${task.artifactName}' " +
|
||||||
|
"in a platform project '${platformProject.path}'")
|
||||||
|
|
||||||
commonSourceSet.kotlin!!.srcDirs.forEach {
|
commonSourceSet.kotlin!!.srcDirs.forEach {
|
||||||
task.commonSrcDir(it)
|
task.commonSrcDir(it)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-2
@@ -51,7 +51,7 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
|
|
||||||
// Multiplatform support --------------------------------------------------
|
// Multiplatform support --------------------------------------------------
|
||||||
|
|
||||||
@Input var commonSourceSet = "main"
|
@Input var commonSourceSets = listOf("main")
|
||||||
|
|
||||||
@Internal var enableMultiplatform = false
|
@Internal var enableMultiplatform = false
|
||||||
|
|
||||||
@@ -158,7 +158,12 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun commonSourceSet(sourceSetName: String) {
|
override fun commonSourceSet(sourceSetName: String) {
|
||||||
commonSourceSet = sourceSetName
|
commonSourceSets = listOf(sourceSetName)
|
||||||
|
enableMultiplatform(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun commonSourceSets(vararg sourceSetNames: String) {
|
||||||
|
commonSourceSets = sourceSetNames.toList()
|
||||||
enableMultiplatform(true)
|
enableMultiplatform(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+37
@@ -163,6 +163,43 @@ class MultiplatformSpecification extends BaseKonanSpecification {
|
|||||||
project.createRunner().withArguments(":build").build()
|
project.createRunner().withArguments(":build").build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def 'Plugin should allow setting several common source sets'() {
|
||||||
|
expect:
|
||||||
|
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
||||||
|
def commonDirectory = createCommonProject(it)
|
||||||
|
Paths.get(commonDirectory.absolutePath, "build.gradle").append("""
|
||||||
|
sourceSets {
|
||||||
|
common.kotlin.srcDir 'src/common/kotlin'
|
||||||
|
}
|
||||||
|
""".stripIndent())
|
||||||
|
|
||||||
|
createCommonSource(commonDirectory,
|
||||||
|
["src", "common", "kotlin"],
|
||||||
|
"common.kt",
|
||||||
|
"expect fun bar(): Int")
|
||||||
|
|
||||||
|
createCommonSource(commonDirectory,
|
||||||
|
["src", "main", "kotlin"],
|
||||||
|
"main.kt",
|
||||||
|
"expect fun foo() : Int")
|
||||||
|
|
||||||
|
it.generateSrcFile("platform.kt", "actual fun bar() = 42\nactual fun foo() = 43")
|
||||||
|
it.buildFile.append("""
|
||||||
|
konanArtifacts {
|
||||||
|
library('foo') {
|
||||||
|
enableMultiplatform true
|
||||||
|
commonSourceSets 'common', 'main'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
expectedBy project(':common')
|
||||||
|
}
|
||||||
|
""".stripIndent())
|
||||||
|
}
|
||||||
|
project.createRunner().withArguments(":build").build()
|
||||||
|
}
|
||||||
|
|
||||||
def 'Build should fail if the expectedBy dependency is not a project one'() {
|
def 'Build should fail if the expectedBy dependency is not a project one'() {
|
||||||
when:
|
when:
|
||||||
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
||||||
|
|||||||
Reference in New Issue
Block a user