[Build] Migrate most of the build logic from Project.buildDir usage

It's going to be deprecated in Gradle 8.3

There's currently no way to pass a `org.gradle.api.provider.Provider` to the JavaExec.systemProperty or Test.systemProperty. There's a workaround using `org.gradle.process.CommandLineArgumentProvider`, but I intentionally don't rework these calls as Gradle is going to allow passing providers to configure system properties: https://github.com/gradle/gradle/issues/12247#issuecomment-1568427242
^KTI-1473 In Progress
This commit is contained in:
Alexander.Likhachev
2023-10-11 22:42:51 +02:00
committed by Space Team
parent b784544f8d
commit a19bd2ed2e
69 changed files with 328 additions and 306 deletions
@@ -20,9 +20,7 @@ task clean {
subprojects.each {
dependsOn it.getTasksByName('clean', true)[0]
}
doLast {
delete "${buildDir.absolutePath}"
}
delete(layout.buildDirectory)
}
defaultTasks 'konanRun'
+10 -12
View File
@@ -121,9 +121,7 @@ task clean {
dependsOn "${it.path}:clean"
}
}
doLast {
delete "${buildDir.absolutePath}"
}
delete(layout.buildDirectory)
}
defaultTasks 'konanRun'
@@ -166,7 +164,7 @@ private def uploadBenchmarkResultToArtifactory(String fileName) {
buildProperties.load(new FileInputStream(teamcityConfig))
def password = buildProperties.getProperty("artifactory.apikey")
MPPTools.uploadFileToArtifactory("${artifactoryUrl}", "${artifactoryRepo}",
uploadedFile, "${buildDir.absolutePath}/${fileName}", password)
uploadedFile, layout.buildDirectory.file(fileName).get().asFile.toString(), password)
}
}
@@ -176,7 +174,7 @@ task registerExternalBenchmarks {
def reports = externalReports.split(';')
def jsonReports = []
reports.each {
def reportFile = new File(buildDir, it)
def reportFile = layout.buildDirectory.file(it).get().asFile
if (!reportFile.exists())
return
@@ -222,14 +220,14 @@ task registerExternalBenchmarks {
properties += ["codeSize": MPPTools.toCodeSizeBenchmark(codeSize, status, name)]
}
def output = MPPTools.createJsonReport(properties)
def jsonFile = new File(buildDir, it.replace(".txt", ".json"))
def jsonFile = layout.buildDirectory.file(it.replace(".txt", ".json")).get().asFile
jsonFile.write(output)
jsonReports.add(jsonFile)
}
def merged = MPPTools.mergeReports(jsonReports)
if (!merged.isEmpty()) {
mkdir buildDir.absolutePath
new File(buildDir, externalBenchmarksReport).write(merged)
mkdir layout.buildDirectory.get().asFile.absolutePath
layout.buildDirectory.file(externalBenchmarksReport).get().asFile.write(merged)
uploadBenchmarkResultToArtifactory(externalBenchmarksReport)
}
}
@@ -269,14 +267,14 @@ registerExternalBenchmarks.finalizedBy registerExternalBuild
def mergeReports(String fileName) {
def reports = []
subprojects.each {
def reportFile = new File("${it.buildDir.absolutePath}/${fileName}")
def reportFile = it.layout.buildDirectory.file(fileName).get().asFile
if (reportFile.exists()) {
reports.add(reportFile)
}
}
def output = MPPTools.mergeReports(reports)
mkdir buildDir.absolutePath
new File("${buildDir.absolutePath}/${fileName}").write(output)
mkdir layout.buildDirectory.get().asFile.absolutePath
new File("${layout.buildDirectory.get().asFile.absolutePath}/${fileName}").write(output)
}
task mergeNativeReports {
@@ -313,7 +311,7 @@ task teamCityStat(type:Exec) {
"--artifactory-url", "https://repo.labs.intellij.net/kotlin-native-benchmarks",
"--teamcity-url", "http://buildserver.labs.intellij.net",
"--server-url", findProperty("kotlin.native.performance.server.url")?.toString() ?: "http://localhost:3000",
"${buildDir.absolutePath}/${nativeJson}"
"${layout.buildDirectory.file(nativeJson).get().asFile}"
}
task cinterop {
@@ -180,7 +180,7 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
protected open fun Project.configureNativeTask(nativeTarget: KotlinNativeTarget): Task {
val konanRun = createRunTask(this, "konanRun", nativeLinkTask,
nativeExecutable, buildDir.resolve(nativeBenchResults).absolutePath).apply {
nativeExecutable, layout.buildDirectory.file(nativeBenchResults).get().asFile.absolutePath).apply {
group = BENCHMARKING_GROUP
description = "Runs the benchmark for Kotlin/Native."
}
@@ -222,7 +222,7 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
doLast {
val applicationName = benchmark.applicationName
val benchContents = buildDir.resolve(nativeBenchResults).readText()
val benchContents = layout.buildDirectory.file(nativeBenchResults).get().asFile.readText()
val nativeCompileTasks = if (benchmark.compileTasks.isEmpty()) {
listOf("linkBenchmark${benchmark.buildType.name.lowercase().replaceFirstChar { it.uppercase() }}ExecutableNative")
} else benchmark.compileTasks
@@ -239,7 +239,7 @@ abstract class BenchmarkingPlugin: Plugin<Project> {
)
val output = createJsonReport(properties)
buildDir.resolve(nativeJson).writeText(output)
layout.buildDirectory.file(nativeJson).get().asFile.writeText(output)
}
}
}
@@ -40,11 +40,11 @@ open class CompileBenchmarkingPlugin : Plugin<Project> {
private fun Project.configureUtilityTasks() {
tasks.create("configureBuild") {
doLast { mkdir(buildDir) }
doLast { mkdir(layout.buildDirectory.get().asFile) }
}
tasks.create("clean", Delete::class.java) {
delete(buildDir)
delete(layout.buildDirectory)
}
}
@@ -90,7 +90,7 @@ open class CompileBenchmarkingPlugin : Plugin<Project> {
repeatNumber,
exitCodes
)
val nativeExecutable = buildDir.resolve("program${getNativeProgramExtension()}")
val nativeExecutable = layout.buildDirectory.file("program${getNativeProgramExtension()}").get().asFile
val properties = commonBenchmarkProperties + mapOf(
"type" to "native",
"compilerVersion" to konanVersion,
@@ -100,7 +100,7 @@ open class CompileBenchmarkingPlugin : Plugin<Project> {
"codeSize" to getCodeSizeBenchmark(applicationName, nativeExecutable.absolutePath)
)
val output = createJsonReport(properties)
buildDir.resolve(nativeJson).writeText(output)
layout.buildDirectory.file(nativeJson).get().asFile.writeText(output)
}
konanRun.finalizedBy(this)
}
@@ -44,7 +44,7 @@ open class KotlinNativeBenchmarkingPlugin: BenchmarkingPlugin() {
val applicationName = benchmark.applicationName
val jarPath = (tasks.getByName("jvmJar") as Jar).archiveFile.get().asFile
val jvmCompileTime = getJvmCompileTime(project, applicationName)
val benchContents = buildDir.resolve(jvmBenchResults).readText()
val benchContents = layout.buildDirectory.file(jvmBenchResults).get().asFile.readText()
val properties: Map<String, Any> = commonBenchmarkProperties + mapOf(
"type" to "jvm",
@@ -55,7 +55,7 @@ open class KotlinNativeBenchmarkingPlugin: BenchmarkingPlugin() {
)
val output = createJsonReport(properties)
buildDir.resolve(jvmJson).writeText(output)
layout.buildDirectory.file(jvmJson).get().asFile.writeText(output)
}
jvmRun.finalizedBy(this)
@@ -78,7 +78,7 @@ open class KotlinNativeBenchmarkingPlugin: BenchmarkingPlugin() {
args("-p", "${benchmark.applicationName}::")
warmupCount = jvmWarmup
repeatCount = attempts
outputFileName = buildDir.resolve(jvmBenchResults).absolutePath
outputFileName = layout.buildDirectory.file(jvmBenchResults).get().asFile.absolutePath
repeatingType = benchmark.repeatingType
}
}
@@ -53,7 +53,7 @@ open class SwiftBenchmarkingPlugin : BenchmarkingPlugin() {
override val benchmarkExtensionName: String = "swiftBenchmark"
override val Project.nativeExecutable: String
get() = Paths.get(buildDir.absolutePath, benchmark.applicationName).toString()
get() = Paths.get(layout.buildDirectory.get().asFile.absolutePath, benchmark.applicationName).toString()
override val Project.nativeLinkTask: Task
get() = tasks.getByName("buildSwift")
@@ -92,7 +92,7 @@ open class SwiftBenchmarkingPlugin : BenchmarkingPlugin() {
val frameworkParentDirPath = framework.outputDirectory.absolutePath
val options = listOf("-O", "-wmo", "-Xlinker", "-rpath", "-Xlinker", frameworkParentDirPath, "-F", frameworkParentDirPath)
compileSwift(project, nativeTarget.konanTarget, benchmark.swiftSources, options,
Paths.get(buildDir.absolutePath, benchmark.applicationName), false)
Paths.get(layout.buildDirectory.get().asFile.absolutePath, benchmark.applicationName), false)
}
}
}
@@ -1,6 +1,5 @@
import org.jetbrains.kotlin.MPPTools
import org.jetbrains.kotlin.PlatformInfo
import org.jetbrains.kotlin.RunJvmTask
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
buildscript {
@@ -106,7 +105,7 @@ task konanJsonReport {
'compileTime' : [nativeCompileTime],
'codeSize' : MPPTools.getCodeSizeBenchmark(applicationName, nativeExecutable)]
def output = MPPTools.createJsonReport(properties)
new File("${buildDir.absolutePath}/${nativeJson}").write(output)
layout.buildDirectory.file(nativeJson).get().asFile.write(output)
}
}
}
@@ -16,7 +16,7 @@ task konanRun {
task configureBuild {
doLast {
mkdir "${buildDir.absolutePath}"
mkdir "${layout.buildDirectory.get().asFile.absolutePath}"
}
}
@@ -33,23 +33,21 @@ task configureBuild {
}
task clean {
doLast {
delete "${buildDir.absolutePath}"
}
delete(layout.buildDirectory)
}
task konanJsonReport {
doLast {
def nativeCompileTime = MPPTools.getCompileBenchmarkTime(project.ext.applicationName, project.ext.buildSteps.keySet(),
project.ext.repeatNumber, exitCodes)
def nativeExecutable = "${buildDir.absolutePath}/program${MPPTools.getNativeProgramExtension()}"
def nativeExecutable = layout.buildDirectory.file("program${MPPTools.getNativeProgramExtension()}").get().asFile.toString()
def properties = getCommonProperties() + ['type': 'native',
'compilerVersion': "${konanVersion}".toString(),
'benchmarks': "[]",
'compileTime': nativeCompileTime,
'codeSize': MPPTools.getCodeSizeBenchmark(project.ext.applicationName, nativeExecutable) ]
def output = MPPTools.createJsonReport(properties)
new File("${buildDir.absolutePath}/${nativeJson}").write(output)
layout.buildDirectory.file(nativeJson).get().asFile.write(output)
}
}
task jvmRun {
@@ -77,7 +77,7 @@ compileBenchmark {
command = listOf(
"$dist/bin/konanc$toolSuffix",
"-ea", "-p", "program",
"-o", "${buildDir.absolutePath}/program$binarySuffix",
"-o", layout.buildDirectory.file("program$binarySuffix").get().asFile.toString(),
"-l", "$videoplayerDir/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-ffmpeg.klib",
"-l", "$videoplayerDir/build/classes/kotlin/videoPlayer/main/videoplayer-cinterop-sdl.klib",
"-Xmulti-platform", "$videoplayerDir/src/videoPlayerMain/kotlin",