[gradle plugin] friend module support.
e.g.
konanArtifacts {
library('A') {
srcDir 'src/A'
}
library('C') {
srcDir 'src/C'
}
library('B') {
srcDir 'src/B'
libraries {
artifact 'A', true
artifact 'C'
}
}
}
This commit is contained in:
+16
-8
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.konan.library.SearchPathResolver
|
|||||||
import org.jetbrains.kotlin.konan.library.defaultResolver
|
import org.jetbrains.kotlin.konan.library.defaultResolver
|
||||||
import org.jetbrains.kotlin.konan.target.Distribution
|
import org.jetbrains.kotlin.konan.target.Distribution
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.konan.util.visibleName
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
open class KonanLibrariesSpec(val task: KonanArtifactWithLibrariesTask, val project: Project) {
|
open class KonanLibrariesSpec(val task: KonanArtifactWithLibrariesTask, val project: Project) {
|
||||||
@@ -56,6 +55,11 @@ open class KonanLibrariesSpec(val task: KonanArtifactWithLibrariesTask, val proj
|
|||||||
val target: KonanTarget
|
val target: KonanTarget
|
||||||
@Internal get() = task.konanTarget
|
@Internal get() = task.konanTarget
|
||||||
|
|
||||||
|
private val friendsTasks = mutableSetOf<KonanBuildingTask>()
|
||||||
|
val friends:Set<File> get() = mutableSetOf<File>().apply {
|
||||||
|
addAll(friendsTasks.map { it.artifact })
|
||||||
|
}
|
||||||
|
|
||||||
// DSL Methods
|
// DSL Methods
|
||||||
|
|
||||||
/** Absolute path */
|
/** Absolute path */
|
||||||
@@ -68,7 +72,7 @@ open class KonanLibrariesSpec(val task: KonanArtifactWithLibrariesTask, val proj
|
|||||||
fun klibs(vararg libs: String) = namedKlibs.addAll(libs)
|
fun klibs(vararg libs: String) = namedKlibs.addAll(libs)
|
||||||
fun klibs(libs: Iterable<String>) = namedKlibs.addAll(libs)
|
fun klibs(libs: Iterable<String>) = namedKlibs.addAll(libs)
|
||||||
|
|
||||||
private fun klibInternal(lib: KonanBuildingConfig<*>) {
|
private fun klibInternal(lib: KonanBuildingConfig<*>, friend: Boolean) {
|
||||||
if (!(lib is KonanLibrary || lib is KonanInteropLibrary)) {
|
if (!(lib is KonanLibrary || lib is KonanInteropLibrary)) {
|
||||||
throw InvalidUserDataException("Config ${lib.name} is not a library")
|
throw InvalidUserDataException("Config ${lib.name} is not a library")
|
||||||
}
|
}
|
||||||
@@ -82,21 +86,25 @@ open class KonanLibrariesSpec(val task: KonanArtifactWithLibrariesTask, val proj
|
|||||||
}
|
}
|
||||||
artifacts.add(libraryTask)
|
artifacts.add(libraryTask)
|
||||||
task.dependsOn(libraryTask)
|
task.dependsOn(libraryTask)
|
||||||
|
if (friend) friendsTasks.add(libraryTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Direct link to a config */
|
/** Direct link to a config */
|
||||||
fun klib(lib: KonanLibrary) = klibInternal(lib)
|
fun klib(lib: KonanLibrary) = klibInternal(lib, false)
|
||||||
/** Direct link to a config */
|
/** Direct link to a config */
|
||||||
fun klib(lib: KonanInteropLibrary) = klibInternal(lib)
|
fun klib(lib: KonanInteropLibrary) = klibInternal(lib, false)
|
||||||
|
|
||||||
/** Artifact in the specified project by name */
|
/** Artifact in the specified project by name */
|
||||||
fun artifact(libraryProject: Project, name: String) {
|
fun artifact(libraryProject: Project, name: String, friend: Boolean) {
|
||||||
project.evaluationDependsOn(libraryProject)
|
project.evaluationDependsOn(libraryProject)
|
||||||
klibInternal(libraryProject.konanArtifactsContainer.getByName(name))
|
klibInternal(libraryProject.konanArtifactsContainer.getByName(name), friend)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun artifact(libraryProject: Project, name: String) = artifact(libraryProject, name, false)
|
||||||
/** Artifact in the current project by name */
|
/** Artifact in the current project by name */
|
||||||
fun artifact(name: String) = artifact(project, name)
|
fun artifact(name: String, friend: Boolean) = artifact(project, name, friend)
|
||||||
|
|
||||||
|
fun artifact(name: String) = artifact(project, name, false)
|
||||||
|
|
||||||
/** Artifact by direct link */
|
/** Artifact by direct link */
|
||||||
fun artifact(artifact: KonanLibrary) = klib(artifact)
|
fun artifact(artifact: KonanLibrary) = klib(artifact)
|
||||||
@@ -108,7 +116,7 @@ open class KonanLibrariesSpec(val task: KonanArtifactWithLibrariesTask, val proj
|
|||||||
libraryProjects.forEach { prj ->
|
libraryProjects.forEach { prj ->
|
||||||
project.evaluationDependsOn(prj)
|
project.evaluationDependsOn(prj)
|
||||||
prj.konanArtifactsContainer.filter(filter).forEach {
|
prj.konanArtifactsContainer.filter(filter).forEach {
|
||||||
klibInternal(it)
|
klibInternal(it, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -136,6 +136,9 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
addKey("-nodefaultlibs", noDefaultLibs)
|
addKey("-nodefaultlibs", noDefaultLibs)
|
||||||
addKey("-Xmulti-platform", enableMultiplatform)
|
addKey("-Xmulti-platform", enableMultiplatform)
|
||||||
|
|
||||||
|
if (libraries.friends.isNotEmpty())
|
||||||
|
addArg("-friend-modules", libraries.friends.joinToString(File.pathSeparator))
|
||||||
|
|
||||||
addAll(extraOpts)
|
addAll(extraOpts)
|
||||||
|
|
||||||
allSourceFiles.mapTo(this) { it.canonicalPath }
|
allSourceFiles.mapTo(this) { it.canonicalPath }
|
||||||
|
|||||||
Reference in New Issue
Block a user