[gradle-plugin] Fix a bug with up-to-date checks for frameworks
This commit is contained in:
+11
-19
@@ -39,12 +39,12 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
||||
group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
description = "Executes Kotlin/Native unit tests."
|
||||
|
||||
val testExecutableProperty = compileTask.outputFile
|
||||
executable = testExecutableProperty.asFile.get().absolutePath
|
||||
val testExecutable = compileTask.outputFile
|
||||
executable = testExecutable.absolutePath
|
||||
|
||||
onlyIf { testExecutableProperty.asFile.get().exists() }
|
||||
inputs.file(testExecutableProperty)
|
||||
dependsOn(testExecutableProperty)
|
||||
onlyIf { testExecutable.exists() }
|
||||
inputs.file(testExecutable)
|
||||
dependsOn(compileTask)
|
||||
|
||||
// TODO: Find or implement some mechanism for test result saving.
|
||||
outputDir = project.layout.buildDirectory.dir("test-results/" + binary.names.dirName).get().asFile
|
||||
@@ -66,6 +66,7 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
||||
get() = this == HostManager.host
|
||||
|
||||
|
||||
// TODO: Rework this part: the task should be created in the binary constructor (if it is possible).
|
||||
private fun Project.addCompilationTasks() {
|
||||
val assembleTask = tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||
val typeToAssemble = mutableMapOf<KotlinNativeBuildType, Task>()
|
||||
@@ -80,31 +81,22 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
||||
components.withType(AbstractKotlinNativeBinary::class.java) { binary ->
|
||||
val names = binary.names
|
||||
val target = binary.konanTarget
|
||||
val kind = binary.kind
|
||||
val buildType = binary.buildType
|
||||
|
||||
val compileTask = tasks.create(
|
||||
names.getCompileTaskName(LANGUAGE_NAME),
|
||||
KotlinNativeCompile::class.java
|
||||
KotlinNativeCompile::class.java,
|
||||
binary
|
||||
).apply {
|
||||
this.binary = binary
|
||||
outputFile.set(layout.buildDirectory.file(providers.provider {
|
||||
val root = binary.outputRootName
|
||||
val prefix = kind.prefix(target)
|
||||
val suffix = kind.suffix(target)
|
||||
val baseName = binary.getBaseName().get()
|
||||
"$root/${names.dirName}/${prefix}${baseName}${suffix}"
|
||||
}))
|
||||
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Compiles Kotlin/Native source set '${binary.sourceSet.name}' into a ${binary.kind.name.toLowerCase()}"
|
||||
}
|
||||
binary.compileTask.set(compileTask)
|
||||
binary.outputs.from(compileTask.outputFile)
|
||||
binary.outputs.from(compileTask.outputLocationProvider)
|
||||
|
||||
when(binary) {
|
||||
is KotlinNativeExecutableImpl -> binary.runtimeFile.set(compileTask.outputFile)
|
||||
is KotlinNativeLibraryImpl -> binary.linkFile.set(compileTask.outputFile)
|
||||
is KotlinNativeExecutableImpl -> binary.runtimeFile.set(compileTask.outputLocationProvider as RegularFileProperty)
|
||||
is KotlinNativeLibraryImpl -> binary.linkFile.set(compileTask.outputLocationProvider as RegularFileProperty)
|
||||
}
|
||||
|
||||
if (binary is KotlinNativeTestExecutableImpl) {
|
||||
|
||||
+34
-10
@@ -4,7 +4,9 @@ import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.FileSystemLocation
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanCompilerRunner
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanPlugin
|
||||
@@ -13,16 +15,15 @@ import org.jetbrains.kotlin.gradle.plugin.addKey
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.AbstractKotlinNativeBinary
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinNativeCompile: DefaultTask() {
|
||||
|
||||
open class KotlinNativeCompile @Inject constructor(internal val binary: AbstractKotlinNativeBinary)
|
||||
: DefaultTask()
|
||||
{
|
||||
init {
|
||||
super.dependsOn(KonanPlugin.KONAN_DOWNLOAD_TASK_NAME)
|
||||
}
|
||||
|
||||
// TODO: May be replace with Gradle's property
|
||||
internal lateinit var binary: AbstractKotlinNativeBinary
|
||||
|
||||
// Inputs and outputs
|
||||
|
||||
val sources: FileCollection
|
||||
@@ -40,18 +41,41 @@ open class KotlinNativeCompile: DefaultTask() {
|
||||
|
||||
val additionalCompilerOptions: Collection<String> @Input get() = binary.additionalCompilerOptions
|
||||
|
||||
@OutputFile
|
||||
val outputFile: RegularFileProperty = newOutputFile()
|
||||
val outputFile: File
|
||||
get() = outputLocationProvider.get().asFile
|
||||
|
||||
private val outputPathProvider: Provider<String> = project.provider {
|
||||
with(binary) {
|
||||
val root = outputRootName
|
||||
val prefix = kind.prefix(konanTarget)
|
||||
val suffix = kind.suffix(konanTarget)
|
||||
val baseName = getBaseName().get()
|
||||
"$root/${binary.names.dirName}/${prefix}${baseName}${suffix}"
|
||||
}
|
||||
}
|
||||
|
||||
val outputLocationProvider: Provider<out FileSystemLocation> = with(project.layout) {
|
||||
if (kind == CompilerOutputKind.FRAMEWORK) {
|
||||
newOutputDirectory().apply {
|
||||
set(buildDirectory.dir(outputPathProvider))
|
||||
outputs.dir(this)
|
||||
}
|
||||
} else {
|
||||
newOutputFile().apply {
|
||||
set(buildDirectory.file(outputPathProvider))
|
||||
outputs.file(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Task action
|
||||
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
val output = outputFile.asFile.get()
|
||||
output.parentFile.mkdirs()
|
||||
outputFile.parentFile.mkdirs()
|
||||
|
||||
val args = mutableListOf<String>().apply {
|
||||
addArg("-o", outputFile.get().asFile.absolutePath)
|
||||
addArg("-o", outputFile.absolutePath)
|
||||
addKey("-opt", optimized)
|
||||
addKey("-g", debuggable)
|
||||
addKey("-ea", debuggable)
|
||||
|
||||
@@ -419,8 +419,8 @@ class ExperimentalPluginTests {
|
||||
val task = result.task(taskName)
|
||||
assertNotNull(task, "Task '$taskName' was not executed") {
|
||||
assertEquals(
|
||||
it.outcome,
|
||||
expectedOutcome,
|
||||
it.outcome,
|
||||
"Task '$taskName' has incorrect outcome. Expected: $expectedOutcome, actual: ${it.outcome}"
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user