Convert main task creating helper to lazy API, refactor accordingly

This commit is contained in:
Ilya Chernikov
2019-08-14 15:42:42 +02:00
parent 0f41dc814f
commit 2ed8fa7624
8 changed files with 41 additions and 35 deletions
+4 -1
View File
@@ -12,11 +12,14 @@ import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.SourceSetOutput
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.registering
import org.gradle.kotlin.dsl.the
import java.io.File
import java.util.concurrent.Callable
inline fun <reified T : Task> Project.task(noinline configuration: T.() -> Unit) = tasks.creating(T::class, configuration)
inline fun <reified T : Task> Project.task(noinline configuration: T.() -> Unit) = tasks.registering(T::class, configuration)
inline fun <reified T : Task> Project.eagerTask(noinline configuration: T.() -> Unit) = tasks.creating(T::class, configuration)
fun Project.callGroovy(name: String, vararg args: Any?): Any? {
return (property(name) as Closure<*>).call(*args)
+3 -1
View File
@@ -1,6 +1,7 @@
import org.gradle.api.Project
import org.gradle.api.tasks.JavaExec
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.task
/*
@@ -8,7 +9,8 @@ import org.gradle.kotlin.dsl.task
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
fun Project.smartJavaExec(configure: JavaExec.() -> Unit) = task<JavaExec> {
// creating class eagerly here: using register causes problems due to quite complicated relationships between these tasks
fun Project.smartJavaExec(configure: JavaExec.() -> Unit) = tasks.creating(JavaExec::class) {
configure()
passClasspathInJar()
}
+8 -9
View File
@@ -68,16 +68,15 @@ fun Project.configureFormInstrumentation() {
val instrumentedClassesDir = File(project.buildDir, "classes/${sourceSetParam.name}-instrumented")
(sourceSetParam.output.classesDirs as ConfigurableFileCollection).setFrom(instrumentedClassesDir)
val instrumentTask =
project.tasks.create(sourceSetParam.getTaskName("instrument", "classes"), IntelliJInstrumentCodeTask::class.java)
instrumentTask.apply {
dependsOn(sourceSetParam.classesTaskName).onlyIf { !classesDirsCopy.isEmpty }
sourceSet = sourceSetParam
instrumentationClasspath = instrumentationClasspathCfg
originalClassesDirs = classesDirsCopy
output = instrumentedClassesDir
}
project.tasks.register(sourceSetParam.getTaskName("instrument", "classes"), IntelliJInstrumentCodeTask::class.java) {
dependsOn(sourceSetParam.classesTaskName).onlyIf { !classesDirsCopy.isEmpty }
sourceSet = sourceSetParam
instrumentationClasspath = instrumentationClasspathCfg
originalClassesDirs = classesDirsCopy
output = instrumentedClassesDir
outputs.dir(instrumentedClassesDir)
}
instrumentTask.outputs.dir(instrumentedClassesDir)
// Ensure that our task is invoked when the source set is built
sourceSetParam.compiledBy(instrumentTask)
@Suppress("UNUSED_EXPRESSION")
@@ -85,7 +85,7 @@ val fullRuntimeSources by task<Sync> {
val reducedRuntimeSources by task<Sync> {
dependsOn(fullRuntimeSources)
from(fullRuntimeSources.outputs.files.singleFile) {
from(fullRuntimeSources.get().outputs.files.singleFile) {
exclude(
listOf(
"libraries/stdlib/unsigned/**",
@@ -161,10 +161,10 @@ fun JavaExec.buildKLib(sources: List<String>, dependencies: List<String>, outPat
val fullRuntimeDir = buildDir.resolve("fullRuntime/klib")
val generateFullRuntimeKLib by task<NoDebugJavaExec> {
val generateFullRuntimeKLib by eagerTask<NoDebugJavaExec> {
dependsOn(fullRuntimeSources)
buildKLib(sources = listOf(fullRuntimeSources.outputs.files.singleFile.path),
buildKLib(sources = listOf(fullRuntimeSources.get().outputs.files.singleFile.path),
dependencies = emptyList(),
outPath = fullRuntimeDir.absolutePath,
commonSources = listOf("common", "src", "unsigned").map { "$buildDir/fullRuntime/src/libraries/stdlib/$it" }
@@ -178,11 +178,11 @@ val packFullRuntimeKLib by tasks.registering(Jar::class) {
archiveFileName.set("full-runtime.klib")
}
val generateReducedRuntimeKLib by task<NoDebugJavaExec> {
val generateReducedRuntimeKLib by eagerTask<NoDebugJavaExec> {
dependsOn(reducedRuntimeSources)
val outPath = buildDir.resolve("reducedRuntime/klib").absolutePath
buildKLib(sources = listOf(reducedRuntimeSources.outputs.files.singleFile.path),
buildKLib(sources = listOf(reducedRuntimeSources.get().outputs.files.singleFile.path),
dependencies = emptyList(),
outPath = outPath,
commonSources = listOf("common", "src", "unsigned").map { "$buildDir/reducedRuntime/src/libraries/stdlib/$it" }
@@ -193,7 +193,7 @@ val kotlinTestCommonSources = listOf(
"$rootDir/libraries/kotlin.test/annotations-common/src/main",
"$rootDir/libraries/kotlin.test/common/src/main"
)
val generateKotlinTestKLib by task<NoDebugJavaExec> {
val generateKotlinTestKLib by eagerTask<NoDebugJavaExec> {
dependsOn(generateFullRuntimeKLib)
buildKLib(
+4 -2
View File
@@ -69,12 +69,14 @@ fun unzipSdkTask(
}
}
}
prepareSdk.dependsOn(unzipTask)
prepareSdk.configure {
dependsOn(unzipTask)
}
additionalConfig?.also {
dependencies.add(it.name, dependency)
}
return unzipTask
}
+9 -9
View File
@@ -123,14 +123,14 @@ val reflectShadowJar by task<ShadowJar> {
}
}
val stripMetadata by tasks.creating {
val stripMetadata by tasks.registering {
dependsOn(reflectShadowJar)
val inputJar = reflectShadowJar.outputs.files.singleFile
val inputJar = provider { reflectShadowJar.get().outputs.files.singleFile }
val outputJar = File("$libsDir/kotlin-reflect-stripped.jar")
inputs.file(inputJar)
outputs.file(outputJar)
doLast {
stripMetadata(logger, "kotlin/reflect/jvm/internal/impl/.*", inputJar, outputJar)
stripMetadata(logger, "kotlin/reflect/jvm/internal/impl/.*", inputJar.get(), outputJar)
}
}
@@ -138,10 +138,10 @@ val proguardOutput = "$libsDir/${property("archivesBaseName")}-proguard.jar"
val proguard by task<ProGuardTask> {
dependsOn(stripMetadata)
inputs.files(stripMetadata.outputs.files)
inputs.files(stripMetadata.get().outputs.files)
outputs.file(proguardOutput)
injars(mapOf("filter" to "!META-INF/versions/**"), stripMetadata.outputs.files)
injars(mapOf("filter" to "!META-INF/versions/**"), stripMetadata.get().outputs.files)
injars(mapOf("filter" to "!META-INF/**,!**/*.kotlin_builtins"), proguardAdditionalInJars)
outjars(proguardOutput)
@@ -198,7 +198,7 @@ val result by task<Jar> {
dependsOn(task)
from {
zipTree(task.outputs.files.singleFile)
zipTree(task.get().outputs.files.singleFile)
}
callGroovy("manifestAttributes", manifest, project, "Main")
@@ -208,7 +208,7 @@ val modularJar by task<Jar> {
dependsOn(proguard)
archiveClassifier.set("modular")
from(zipTree(file(proguardOutput)))
from(zipTree(reflectShadowJar.archivePath)) {
from(zipTree(reflectShadowJar.get().archivePath)) {
include("META-INF/versions/**")
}
callGroovy("manifestAttributes", manifest, project, "Main", true)
@@ -216,14 +216,14 @@ val modularJar by task<Jar> {
val dexMethodCount by task<DexMethodCount> {
dependsOn(result)
jarFile = result.outputs.files.single()
jarFile = result.get().outputs.files.single()
ownPackages = listOf("kotlin.reflect")
}
tasks.getByName("check").dependsOn(dexMethodCount)
artifacts {
listOf(mainJar.name, "runtime", "archives").forEach { configurationName ->
add(configurationName, result.outputs.files.singleFile) {
add(configurationName, result.get().outputs.files.singleFile) {
builtBy(result)
}
}
@@ -73,24 +73,24 @@ val proguard by task<ProGuardTask> {
dependsOn(packJar)
configuration("main-kts.pro")
injars(mapOf("filter" to "!META-INF/versions/**"), packJar.outputs.files)
injars(mapOf("filter" to "!META-INF/versions/**"), packJar.get().outputs.files)
val outputJar = fileFrom(buildDir, "libs", "$jarBaseName-$version-after-proguard.jar")
outjars(outputJar)
inputs.files(packJar.outputs.files.singleFile)
inputs.files(packJar.get().outputs.files.singleFile)
outputs.file(outputJar)
libraryjars(mapOf("filter" to "!META-INF/versions/**"), proguardLibraryJars)
}
val resultJar = tasks.register<Jar>("resultJar") {
val resultJar by task<Jar> {
val pack = if (kotlinBuildProperties.proguard) proguard else packJar
dependsOn(pack)
setupPublicJar(jarBaseName)
from {
zipTree(pack.outputs.files.singleFile)
zipTree(pack.get().outputs.files.singleFile)
}
}
+3 -3
View File
@@ -246,7 +246,7 @@ val proguard by task<ProGuardTask> {
val outputJar = fileFrom(buildDir, "libs", "$compilerBaseName-after-proguard.jar")
inputs.files(packCompiler.outputs.files.singleFile)
inputs.files(packCompiler.get().outputs.files.singleFile)
outputs.file(outputJar)
libraryjars(mapOf("filter" to "!META-INF/versions/**"), proguardLibraries)
@@ -255,7 +255,7 @@ val proguard by task<ProGuardTask> {
// This properties are used by proguard config compiler.pro
doFirst {
System.setProperty("kotlin-compiler-jar-before-shrink", packCompiler.outputs.files.singleFile.canonicalPath)
System.setProperty("kotlin-compiler-jar-before-shrink", packCompiler.get().outputs.files.singleFile.canonicalPath)
System.setProperty("kotlin-compiler-jar", outputJar.canonicalPath)
}
}
@@ -267,7 +267,7 @@ val jar = runtimeJar {
dependsOn(pack)
from {
zipTree(pack.outputs.files.singleFile)
zipTree(pack.get().outputs.files.singleFile)
}
manifest.attributes["Class-Path"] = compilerManifestClassPath