gradle-plugin: Allow interop args change after useInterop call
This commit is contained in:
+14
-6
@@ -191,6 +191,8 @@ open class KonanCompileConfig(
|
|||||||
|
|
||||||
override fun getName() = configName
|
override fun getName() = configName
|
||||||
|
|
||||||
|
val interops = mutableSetOf<KonanInteropConfig>()
|
||||||
|
|
||||||
val compilationTask: KonanCompileTask = project.tasks.create(
|
val compilationTask: KonanCompileTask = project.tasks.create(
|
||||||
"$taskNamePrefix${configName.capitalize()}",
|
"$taskNamePrefix${configName.capitalize()}",
|
||||||
KonanCompileTask::class.java) {
|
KonanCompileTask::class.java) {
|
||||||
@@ -199,11 +201,9 @@ open class KonanCompileConfig(
|
|||||||
it.description = "Compiles the Kotlin/Native artifact '${this@KonanCompileConfig.name}'"
|
it.description = "Compiles the Kotlin/Native artifact '${this@KonanCompileConfig.name}'"
|
||||||
}
|
}
|
||||||
|
|
||||||
// DSL methods --------------------------------------------------
|
protected fun addInteropParameters(interop: KonanInteropConfig) {
|
||||||
|
val generateStubsTask = interop.generateStubsTask
|
||||||
fun useInterop(interopConfig: KonanInteropConfig) {
|
val compileStubsTask = interop.compileStubsTask
|
||||||
val generateStubsTask = interopConfig.generateStubsTask
|
|
||||||
val compileStubsTask = interopConfig.compileStubsTask
|
|
||||||
|
|
||||||
compilationTask.dependsOn(compileStubsTask)
|
compilationTask.dependsOn(compileStubsTask)
|
||||||
compilationTask.dependsOn(generateStubsTask)
|
compilationTask.dependsOn(generateStubsTask)
|
||||||
@@ -217,6 +217,14 @@ open class KonanCompileConfig(
|
|||||||
generateStubsTask.manifest ?.let {manifest(it)}
|
generateStubsTask.manifest ?.let {manifest(it)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun processInterops() = interops.forEach(this::addInteropParameters)
|
||||||
|
|
||||||
|
// DSL methods --------------------------------------------------
|
||||||
|
|
||||||
|
fun useInterop(interopConfig: KonanInteropConfig) {
|
||||||
|
interops.add(interopConfig)
|
||||||
|
}
|
||||||
|
|
||||||
fun useInterop(interop: String) {
|
fun useInterop(interop: String) {
|
||||||
useInterop(project.konanInteropContainer.getByName(interop))
|
useInterop(project.konanInteropContainer.getByName(interop))
|
||||||
}
|
}
|
||||||
@@ -224,7 +232,7 @@ open class KonanCompileConfig(
|
|||||||
fun useInterops(interops: Collection<Any>) {
|
fun useInterops(interops: Collection<Any>) {
|
||||||
interops.forEach {
|
interops.forEach {
|
||||||
when(it) {
|
when(it) {
|
||||||
is String -> useInterop(project.konanInteropContainer.getByName(it))
|
is String -> useInterop(it)
|
||||||
is KonanInteropConfig -> useInterop(it)
|
is KonanInteropConfig -> useInterop(it)
|
||||||
else -> throw IllegalArgumentException("Cannot convert the object to an interop description: $it")
|
else -> throw IllegalArgumentException("Cannot convert the object to an interop description: $it")
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -282,6 +282,11 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
|
|||||||
// Add default source paths after project evaluation.
|
// Add default source paths after project evaluation.
|
||||||
project.afterEvaluate(::setDefaultInputs)
|
project.afterEvaluate(::setDefaultInputs)
|
||||||
|
|
||||||
|
// Set compilation parameters for artifacts using interop.
|
||||||
|
project.afterEvaluate { prj ->
|
||||||
|
prj.konanArtifactsContainer.forEach { it.processInterops() }
|
||||||
|
}
|
||||||
|
|
||||||
// Create task to run supported executables.
|
// Create task to run supported executables.
|
||||||
project.getOrCreateTask("run").apply {
|
project.getOrCreateTask("run").apply {
|
||||||
dependsOn(project.getTask("build"))
|
dependsOn(project.getTask("build"))
|
||||||
@@ -301,5 +306,4 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -12,6 +12,7 @@ class KonanProject {
|
|||||||
|
|
||||||
File projectDir
|
File projectDir
|
||||||
Path projectPath
|
Path projectPath
|
||||||
|
File konanBuildDir
|
||||||
|
|
||||||
String konanHome
|
String konanHome
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ class KonanProject {
|
|||||||
protected KonanProject(File projectDir) {
|
protected KonanProject(File projectDir) {
|
||||||
this.projectDir = projectDir
|
this.projectDir = projectDir
|
||||||
projectPath = projectDir.toPath()
|
projectPath = projectDir.toPath()
|
||||||
|
konanBuildDir = projectPath.resolve('build/konan').toFile()
|
||||||
def konanHome = System.getProperty("konan.home")
|
def konanHome = System.getProperty("konan.home")
|
||||||
if (konanHome == null) {
|
if (konanHome == null) {
|
||||||
throw new IllegalStateException("konan.home isn't specified")
|
throw new IllegalStateException("konan.home isn't specified")
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ class PathSpecification extends BaseKonanSpecification {
|
|||||||
def result = project.createRunner().withArguments('build').build()
|
def result = project.createRunner().withArguments('build').build()
|
||||||
|
|
||||||
then:
|
then:
|
||||||
def konan = "$projectDirectory/build/konan"
|
def konan = project.konanBuildDir
|
||||||
new File("$konan/bin").listFiles().findAll {
|
new File("$konan/bin").listFiles().findAll {
|
||||||
File it -> it.file && it.name.matches('^main\\.[^.]+')
|
File it -> it.file && it.name.matches('^main\\.[^.]+')
|
||||||
}.size() > 0
|
}.size() > 0
|
||||||
|
|||||||
+31
@@ -51,7 +51,38 @@ class TaskSpecification extends BaseKonanSpecification {
|
|||||||
|
|
||||||
then:
|
then:
|
||||||
result.taskPaths(TaskOutcome.SUCCESS).containsAll(rootProject.compilationTasks + interopProject.interopTasks)
|
result.taskPaths(TaskOutcome.SUCCESS).containsAll(rootProject.compilationTasks + interopProject.interopTasks)
|
||||||
|
}
|
||||||
|
|
||||||
|
def 'Compilation should support interop parameters changing after `useInterop` call'() {
|
||||||
|
when:
|
||||||
|
def project = KonanInteropProject.create(projectDirectory)
|
||||||
|
project.addInteropSetting("linkerOpts", "'-lpthread'")
|
||||||
|
project.buildFile.append("""
|
||||||
|
task printArgs {
|
||||||
|
dependsOn 'build'
|
||||||
|
doLast {
|
||||||
|
println(konanArtifacts['$project.DEFAULT_ARTIFACT_NAME'].compilationTask.linkerOpts)
|
||||||
|
konanArtifacts['$project.DEFAULT_ARTIFACT_NAME'].compilationTask.libraries.each { println it.files }
|
||||||
|
konanArtifacts['$project.DEFAULT_ARTIFACT_NAME'].compilationTask.nativeLibraries.each { println it.files }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""".stripIndent())
|
||||||
|
def result = project.createRunner().withArguments('printArgs').build()
|
||||||
|
|
||||||
|
then:
|
||||||
|
result.task(":printArgs") != null
|
||||||
|
result.task(":printArgs").outcome == TaskOutcome.SUCCESS
|
||||||
|
def expectedKlibPath = project.konanBuildDir.toPath()
|
||||||
|
.resolve("interopCompiledStubs/stdioInteropStubs/stdioInteropStubs.klib")
|
||||||
|
.toFile().canonicalPath
|
||||||
|
def expectedBcPath = project.konanBuildDir.toPath()
|
||||||
|
.resolve("nativelibs/genStdioInteropStubs/stdiostubs.bc")
|
||||||
|
.toFile().canonicalPath
|
||||||
|
result.output.contains("""
|
||||||
|
[-lpthread]
|
||||||
|
[$expectedKlibPath]
|
||||||
|
[$expectedBcPath]
|
||||||
|
""".stripIndent().trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user