diff --git a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanCompileTask.kt b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanCompileTask.kt index 6f075020779..b3d998b0d2b 100644 --- a/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanCompileTask.kt +++ b/tools/kotlin-native-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KonanCompileTask.kt @@ -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) { - 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) { + 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 diff --git a/tools/kotlin-native-gradle-plugin/src/test/groovy/org/jetbrains/kotlin/gradle/plugin/test/KonanProject.groovy b/tools/kotlin-native-gradle-plugin/src/test/groovy/org/jetbrains/kotlin/gradle/plugin/test/KonanProject.groovy index cf272c8a723..8c73c742dfb 100644 --- a/tools/kotlin-native-gradle-plugin/src/test/groovy/org/jetbrains/kotlin/gradle/plugin/test/KonanProject.groovy +++ b/tools/kotlin-native-gradle-plugin/src/test/groovy/org/jetbrains/kotlin/gradle/plugin/test/KonanProject.groovy @@ -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() diff --git a/tools/kotlin-native-gradle-plugin/src/test/groovy/org/jetbrains/kotlin/gradle/plugin/test/TaskSpecification.groovy b/tools/kotlin-native-gradle-plugin/src/test/groovy/org/jetbrains/kotlin/gradle/plugin/test/TaskSpecification.groovy index c7c5fadccb8..f60c42f67f0 100644 --- a/tools/kotlin-native-gradle-plugin/src/test/groovy/org/jetbrains/kotlin/gradle/plugin/test/TaskSpecification.groovy +++ b/tools/kotlin-native-gradle-plugin/src/test/groovy/org/jetbrains/kotlin/gradle/plugin/test/TaskSpecification.groovy @@ -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) + + } + }