gradle-plugin: Support adding interop from other projects

This commit is contained in:
Ilya Matveev
2017-08-09 20:01:03 +07:00
committed by ilmat192
parent 1132e739ae
commit 07796442d4
3 changed files with 41 additions and 13 deletions
@@ -221,7 +221,7 @@ open class KonanCompileConfig(
if (anotherTask.enableAssertions) enableAssertions()
}
private fun useInteropFromConfig(interopConfig: KonanInteropConfig) {
fun useInterop(interopConfig: KonanInteropConfig) {
val generateStubsTask = interopConfig.generateStubsTask
val compileStubsTask = interopConfig.compileStubsTask
@@ -237,12 +237,18 @@ open class KonanCompileConfig(
generateStubsTask.manifest ?.let {manifest(it)}
}
fun useInterops(interops: ArrayList<String>) {
interops.forEach { useInteropFromConfig(project.konanInteropContainer.getByName(it)) }
fun useInterop(interop: String) {
useInterop(project.konanInteropContainer.getByName(interop))
}
fun useInterop(interop: String) {
useInteropFromConfig(project.konanInteropContainer.getByName(interop))
fun useInterops(interops: Collection<Any>) {
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
@@ -56,8 +56,9 @@ class KonanProject {
}
/** Creates a file with the given content in project subdirectory specified by parentDirectory. */
File createFile(Path parentDirectory, String fileName, String content) {
def result = Files.createFile(projectPath.resolve(parentDirectory).resolve(fileName)).toFile()
File createFile(Path parentDirectory = projectPath, String fileName, String content) {
def result = projectPath.resolve(parentDirectory).resolve(fileName).toFile()
result.createNewFile()
result.write(content)
return result
}
@@ -67,11 +68,6 @@ class KonanProject {
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). */
void generateFolders() {
createSubDir("src", "main", "kotlin")
@@ -274,7 +270,7 @@ class KonanInteropProject extends KonanProject {
*
* headers = stdio.h stdlib.h string.h
*/
File generateDefFile(String fileName) {
File generateDefFile(String fileName = "${DEFAULT_INTEROP_NAME}.def") {
return generateDefFile(fileName, """
headers = stdio.h stdlib.h string.h
""".stripIndent()
@@ -28,4 +28,30 @@ class TaskSpecification extends BaseKonanSpecification {
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)
}
}