gradle-plugin: Allow interop args change after useInterop call

This commit is contained in:
Ilya Matveev
2017-08-10 19:30:33 +07:00
committed by ilmat192
parent e84493dfb7
commit 415660f428
5 changed files with 53 additions and 8 deletions
@@ -191,6 +191,8 @@ open class KonanCompileConfig(
override fun getName() = configName
val interops = mutableSetOf<KonanInteropConfig>()
val compilationTask: KonanCompileTask = project.tasks.create(
"$taskNamePrefix${configName.capitalize()}",
KonanCompileTask::class.java) {
@@ -199,11 +201,9 @@ open class KonanCompileConfig(
it.description = "Compiles the Kotlin/Native artifact '${this@KonanCompileConfig.name}'"
}
// DSL methods --------------------------------------------------
fun useInterop(interopConfig: KonanInteropConfig) {
val generateStubsTask = interopConfig.generateStubsTask
val compileStubsTask = interopConfig.compileStubsTask
protected fun addInteropParameters(interop: KonanInteropConfig) {
val generateStubsTask = interop.generateStubsTask
val compileStubsTask = interop.compileStubsTask
compilationTask.dependsOn(compileStubsTask)
compilationTask.dependsOn(generateStubsTask)
@@ -217,6 +217,14 @@ open class KonanCompileConfig(
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) {
useInterop(project.konanInteropContainer.getByName(interop))
}
@@ -224,7 +232,7 @@ open class KonanCompileConfig(
fun useInterops(interops: Collection<Any>) {
interops.forEach {
when(it) {
is String -> useInterop(project.konanInteropContainer.getByName(it))
is String -> useInterop(it)
is KonanInteropConfig -> useInterop(it)
else -> throw IllegalArgumentException("Cannot convert the object to an interop description: $it")
}
@@ -282,6 +282,11 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
// Add default source paths after project evaluation.
project.afterEvaluate(::setDefaultInputs)
// Set compilation parameters for artifacts using interop.
project.afterEvaluate { prj ->
prj.konanArtifactsContainer.forEach { it.processInterops() }
}
// Create task to run supported executables.
project.getOrCreateTask("run").apply {
dependsOn(project.getTask("build"))
@@ -301,5 +306,4 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
}
}
}
}
@@ -12,6 +12,7 @@ class KonanProject {
File projectDir
Path projectPath
File konanBuildDir
String konanHome
@@ -29,6 +30,7 @@ class KonanProject {
protected KonanProject(File projectDir) {
this.projectDir = projectDir
projectPath = projectDir.toPath()
konanBuildDir = projectPath.resolve('build/konan').toFile()
def konanHome = System.getProperty("konan.home")
if (konanHome == null) {
throw new IllegalStateException("konan.home isn't specified")
@@ -14,7 +14,7 @@ class PathSpecification extends BaseKonanSpecification {
def result = project.createRunner().withArguments('build').build()
then:
def konan = "$projectDirectory/build/konan"
def konan = project.konanBuildDir
new File("$konan/bin").listFiles().findAll {
File it -> it.file && it.name.matches('^main\\.[^.]+')
}.size() > 0
@@ -51,7 +51,38 @@ class TaskSpecification extends BaseKonanSpecification {
then:
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())
}
}