gradle-plugin: Support adding interop from other projects
This commit is contained in:
+11
-5
@@ -221,7 +221,7 @@ open class KonanCompileConfig(
|
|||||||
if (anotherTask.enableAssertions) enableAssertions()
|
if (anotherTask.enableAssertions) enableAssertions()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun useInteropFromConfig(interopConfig: KonanInteropConfig) {
|
fun useInterop(interopConfig: KonanInteropConfig) {
|
||||||
val generateStubsTask = interopConfig.generateStubsTask
|
val generateStubsTask = interopConfig.generateStubsTask
|
||||||
val compileStubsTask = interopConfig.compileStubsTask
|
val compileStubsTask = interopConfig.compileStubsTask
|
||||||
|
|
||||||
@@ -237,12 +237,18 @@ open class KonanCompileConfig(
|
|||||||
generateStubsTask.manifest ?.let {manifest(it)}
|
generateStubsTask.manifest ?.let {manifest(it)}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun useInterops(interops: ArrayList<String>) {
|
fun useInterop(interop: String) {
|
||||||
interops.forEach { useInteropFromConfig(project.konanInteropContainer.getByName(it)) }
|
useInterop(project.konanInteropContainer.getByName(interop))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun useInterop(interop: String) {
|
fun useInterops(interops: Collection<Any>) {
|
||||||
useInteropFromConfig(project.konanInteropContainer.getByName(interop))
|
interops.forEach {
|
||||||
|
when(it) {
|
||||||
|
is String -> useInterop(project.konanInteropContainer.getByName(it))
|
||||||
|
is KonanInteropConfig -> useInterop(it)
|
||||||
|
else -> throw IllegalArgumentException("Cannot convert the object to an interop description: $it")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DSL. Input/output files
|
// DSL. Input/output files
|
||||||
|
|||||||
+4
-8
@@ -56,8 +56,9 @@ class KonanProject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a file with the given content in project subdirectory specified by parentDirectory. */
|
/** Creates a file with the given content in project subdirectory specified by parentDirectory. */
|
||||||
File createFile(Path parentDirectory, String fileName, String content) {
|
File createFile(Path parentDirectory = projectPath, String fileName, String content) {
|
||||||
def result = Files.createFile(projectPath.resolve(parentDirectory).resolve(fileName)).toFile()
|
def result = projectPath.resolve(parentDirectory).resolve(fileName).toFile()
|
||||||
|
result.createNewFile()
|
||||||
result.write(content)
|
result.write(content)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -67,11 +68,6 @@ class KonanProject {
|
|||||||
return createFile(Paths.get(*parentPath), fileName, content)
|
return createFile(Paths.get(*parentPath), fileName, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a file with the given content in project root directory. */
|
|
||||||
File createFile(String fileName, String content) {
|
|
||||||
return createFile(projectPath, fileName, content)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a folder for project source files (src/main/kotlin). */
|
/** Creates a folder for project source files (src/main/kotlin). */
|
||||||
void generateFolders() {
|
void generateFolders() {
|
||||||
createSubDir("src", "main", "kotlin")
|
createSubDir("src", "main", "kotlin")
|
||||||
@@ -274,7 +270,7 @@ class KonanInteropProject extends KonanProject {
|
|||||||
*
|
*
|
||||||
* headers = stdio.h stdlib.h string.h
|
* headers = stdio.h stdlib.h string.h
|
||||||
*/
|
*/
|
||||||
File generateDefFile(String fileName) {
|
File generateDefFile(String fileName = "${DEFAULT_INTEROP_NAME}.def") {
|
||||||
return generateDefFile(fileName, """
|
return generateDefFile(fileName, """
|
||||||
headers = stdio.h stdlib.h string.h
|
headers = stdio.h stdlib.h string.h
|
||||||
""".stripIndent()
|
""".stripIndent()
|
||||||
|
|||||||
+26
@@ -28,4 +28,30 @@ class TaskSpecification extends BaseKonanSpecification {
|
|||||||
beforeCompilation != null && beforeCompilation.outcome == TaskOutcome.SUCCESS
|
beforeCompilation != null && beforeCompilation.outcome == TaskOutcome.SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def 'Compilation config should work with konanInterop from another project'() {
|
||||||
|
when:
|
||||||
|
def rootProject = KonanProject.create(projectDirectory) { KonanProject it ->
|
||||||
|
it.buildFile.append("evaluationDependsOn(':interop')\n")
|
||||||
|
it.createFile("settings.gradle", "include ':interop'")
|
||||||
|
it.addCompilationSetting("useInterop", "project(':interop').konanInterop['interop']")
|
||||||
|
}
|
||||||
|
def interopProjectDir = rootProject.createSubDir("interop")
|
||||||
|
def interopProject = KonanInteropProject.createEmpty(interopProjectDir) { KonanInteropProject it ->
|
||||||
|
it.generateBuildFile("""
|
||||||
|
apply plugin: 'konan'
|
||||||
|
|
||||||
|
konanInterop {
|
||||||
|
interop { }
|
||||||
|
}
|
||||||
|
""".stripIndent())
|
||||||
|
it.interopTasks = [":interop:genInteropInteropStubs", ":interop:compileInteropInteropStubs"]
|
||||||
|
it.generateDefFile("interop.def")
|
||||||
|
}
|
||||||
|
def result = rootProject.createRunner().withArguments("build").build()
|
||||||
|
|
||||||
|
then:
|
||||||
|
result.taskPaths(TaskOutcome.SUCCESS).containsAll(rootProject.compilationTasks + interopProject.interopTasks)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user