[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
|
||||
will use it's `main` source set as a common module. One may specify a custom source set for each artifact using the
|
||||
`commonSourceSet` DSL method. In this case the multiplatform support will be also enabled for this artifact.
|
||||
will use it's `main` source set as a common module. One may specify custom source sets for each artifact using the
|
||||
`commonSourceSets` DSL method. In this case the multiplatform support will be also enabled for this artifact.
|
||||
|
||||
konanArtifacts {
|
||||
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 |
|
||||
|`measureTime `|`boolean` |Does the compiler print phase time |
|
||||
|`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):
|
||||
|
||||
@@ -573,7 +573,7 @@ tables below.
|
||||
|
||||
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 {
|
||||
// All the artifact types except interop libraries may use common modules.
|
||||
@@ -583,8 +583,9 @@ tables below.
|
||||
// Enable multiplatform support for this artifact.
|
||||
enableMultiplatform true
|
||||
|
||||
// Set a custom name for a source set used as a common module.
|
||||
commonSourceSet 'bar'
|
||||
// Set a custom names for source sets used as a common module.
|
||||
// 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 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 linkerOpts(values: List<String>) = forEach { it.linkerOpts(values) }
|
||||
|
||||
+1
@@ -55,6 +55,7 @@ interface KonanCompileSpec: KonanBuildingSpec {
|
||||
// DSL. Multiplatform projects
|
||||
fun enableMultiplatform(flag: Boolean)
|
||||
fun commonSourceSet(sourceSetName: String)
|
||||
fun commonSourceSets(vararg sourceSetNames: String)
|
||||
|
||||
// DSL. Other parameters.
|
||||
|
||||
|
||||
+10
-8
@@ -40,15 +40,17 @@ open class KotlinNativePlatformPlugin: KotlinPlatformImplementationPluginBase("n
|
||||
.withType(KonanCompileTask::class.java)
|
||||
.filter { it.enableMultiplatform }
|
||||
.forEach { task: KonanCompileTask ->
|
||||
val commonSourceSet = commonProject.sourceSets.findByName(task.commonSourceSet) ?:
|
||||
throw GradleException("Cannot find a source set with name '${task.commonSourceSet}' " +
|
||||
"in a common project '${commonProject.path}' " +
|
||||
"for an artifact '${task.artifactName}' " +
|
||||
"in a platform project '${platformProject.path}'")
|
||||
task.commonSourceSets.forEach { commonSourceSetName ->
|
||||
val commonSourceSet = commonProject.sourceSets.findByName(commonSourceSetName) ?:
|
||||
throw GradleException("Cannot find a source set with name '${commonSourceSetName}' " +
|
||||
"in a common project '${commonProject.path}' " +
|
||||
"for an artifact '${task.artifactName}' " +
|
||||
"in a platform project '${platformProject.path}'")
|
||||
|
||||
commonSourceSet.kotlin!!.srcDirs.forEach {
|
||||
task.commonSrcDir(it)
|
||||
}
|
||||
commonSourceSet.kotlin!!.srcDirs.forEach {
|
||||
task.commonSrcDir(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -51,7 +51,7 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
||||
|
||||
// Multiplatform support --------------------------------------------------
|
||||
|
||||
@Input var commonSourceSet = "main"
|
||||
@Input var commonSourceSets = listOf("main")
|
||||
|
||||
@Internal var enableMultiplatform = false
|
||||
|
||||
@@ -158,7 +158,12 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
||||
}
|
||||
|
||||
override fun commonSourceSet(sourceSetName: String) {
|
||||
commonSourceSet = sourceSetName
|
||||
commonSourceSets = listOf(sourceSetName)
|
||||
enableMultiplatform(true)
|
||||
}
|
||||
|
||||
override fun commonSourceSets(vararg sourceSetNames: String) {
|
||||
commonSourceSets = sourceSetNames.toList()
|
||||
enableMultiplatform(true)
|
||||
}
|
||||
|
||||
|
||||
+37
@@ -163,6 +163,43 @@ class MultiplatformSpecification extends BaseKonanSpecification {
|
||||
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'() {
|
||||
when:
|
||||
def project = KonanProject.createEmpty(projectDirectory) { KonanProject it ->
|
||||
|
||||
Reference in New Issue
Block a user