[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:
committed by
Space Team
parent
b784544f8d
commit
a19bd2ed2e
@@ -80,15 +80,16 @@ fun Project.configureCommonPublicationSettingsForGradle(
|
||||
.configureEach {
|
||||
configureKotlinPomAttributes(project)
|
||||
if (sbom && project.name !in internalPlugins) {
|
||||
val buildDirectory = project.layout.buildDirectory
|
||||
if (name == "pluginMaven") {
|
||||
val sbomTask = configureSbom(target = "PluginMaven")
|
||||
artifact("$buildDir/spdx/PluginMaven/PluginMaven.spdx.json") {
|
||||
artifact(buildDirectory.file("spdx/PluginMaven/PluginMaven.spdx.json")) {
|
||||
extension = "spdx.json"
|
||||
builtBy(sbomTask)
|
||||
}
|
||||
} else if (name == "Main") {
|
||||
val sbomTask = configureSbom()
|
||||
artifact("$buildDir/spdx/MainPublication/MainPublication.spdx.json") {
|
||||
artifact(buildDirectory.file("spdx/MainPublication/MainPublication.spdx.json")) {
|
||||
extension = "spdx.json"
|
||||
builtBy(sbomTask)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class InstrumentJava(@Transient val javaInstrumentator: Configuration) : Action<
|
||||
// Javac.execute() - https://github.com/apache/ant/blob/9943641/src/main/org/apache/tools/ant/taskdefs/Javac.java#L1086
|
||||
// InstrumentIdeaExtensions - https://github.com/JetBrains/intellij-community/blob/9c40bdd/java/compiler/javac2/src/com/intellij/ant/InstrumentIdeaExtensions.java
|
||||
// Javac2.compile() - https://github.com/JetBrains/intellij-community/blob/9c40bdd/java/compiler/javac2/src/com/intellij/ant/Javac2.java#L237
|
||||
val dummyInstrumentSrcDir = File(task.project.buildDir, "instrument_dummy_src")
|
||||
val dummyInstrumentSrcDir = task.project.layout.buildDirectory.dir("instrument_dummy_src").get().asFile
|
||||
val dummyInstrumentSrcRelativePath = dummyInstrumentSrcDir.relativeTo(task.project.projectDir).path.replace("\\", "/")
|
||||
|
||||
task.doLast {
|
||||
|
||||
+5
-6
@@ -163,15 +163,14 @@ fun Project.configureKotlinCompilationOptions() {
|
||||
}
|
||||
}
|
||||
|
||||
val relativePathBaseArg: String? =
|
||||
"-Xklib-relative-path-base=$buildDir,$projectDir,$rootDir".takeIf {
|
||||
!kotlinBuildProperties.getBoolean("kotlin.build.use.absolute.paths.in.klib")
|
||||
}
|
||||
val layout = project.layout
|
||||
val rootDir = rootDir
|
||||
val useAbsolutePathsInKlib = kotlinBuildProperties.getBoolean("kotlin.build.use.absolute.paths.in.klib")
|
||||
|
||||
// Workaround to avoid remote build cache misses due to absolute paths in relativePathBaseArg
|
||||
doFirst {
|
||||
if (relativePathBaseArg != null) {
|
||||
kotlinOptions.freeCompilerArgs += relativePathBaseArg
|
||||
if (!useAbsolutePathsInKlib) {
|
||||
kotlinOptions.freeCompilerArgs += "-Xklib-relative-path-base=${layout.buildDirectory.get().asFile},${layout.projectDirectory.asFile},$rootDir"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ private fun Project.compilerShadowJar(taskName: String, body: ShadowJar.() -> Un
|
||||
dependencies.add(compilerJar.name, dependencies.project(":kotlin-compiler")) { isTransitive = false }
|
||||
|
||||
return tasks.register<ShadowJar>(taskName) {
|
||||
destinationDirectory.set(project.file(File(buildDir, "libs")))
|
||||
destinationDirectory.set(project.layout.buildDirectory.dir("libs"))
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
from(compilerJar)
|
||||
body()
|
||||
@@ -136,7 +136,7 @@ fun Project.embeddableCompilerDummyForDependenciesRewriting(
|
||||
)
|
||||
|
||||
return tasks.register<ShadowJar>(taskName) {
|
||||
destinationDirectory.set(project.file(File(buildDir, "libs")))
|
||||
destinationDirectory.set(project.layout.buildDirectory.dir("libs"))
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
from(compilerDummyJar)
|
||||
configureEmbeddableCompilerRelocation(withJavaxInject = false)
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.ideaExt.*
|
||||
|
||||
|
||||
val ideaSdkPath: String
|
||||
get() = rootProject.ideaHomePathForTests().absolutePath
|
||||
get() = rootProject.ideaHomePathForTests().get().asFile.absolutePath
|
||||
val distDir by extra("$rootDir/dist")
|
||||
val distKotlinHomeDir by extra("$distDir/kotlinc")
|
||||
|
||||
|
||||
@@ -126,11 +126,11 @@ object IntellijRootUtils {
|
||||
}
|
||||
}
|
||||
|
||||
fun Project.ideaHomePathForTests() = rootProject.buildDir.resolve("ideaHomeForTests")
|
||||
fun Project.ideaHomePathForTests() = rootProject.layout.buildDirectory.dir("ideaHomeForTests")
|
||||
|
||||
fun Project.ideaBuildNumberFileForTests() = File(ideaHomePathForTests(), "build.txt")
|
||||
fun Project.ideaBuildNumberFileForTests() = objects.directoryProperty().value(ideaHomePathForTests()).file("build.txt")
|
||||
|
||||
fun Project.writeIdeaBuildNumberForTests() {
|
||||
ideaHomePathForTests().mkdirs()
|
||||
ideaBuildNumberFileForTests().writeText("IC-${rootProject.extra["versions.intellijSdk"]}")
|
||||
ideaHomePathForTests().get().asFile.mkdirs()
|
||||
ideaBuildNumberFileForTests().get().asFile.writeText("IC-${rootProject.extra["versions.intellijSdk"]}")
|
||||
}
|
||||
+1
-8
@@ -1,17 +1,10 @@
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.jetbrains.gradle.ext.ActionDelegationConfig
|
||||
import org.jetbrains.gradle.ext.JUnit
|
||||
import org.jetbrains.gradle.ext.RecursiveArtifact
|
||||
import org.jetbrains.gradle.ext.TopLevelArtifact
|
||||
import org.jetbrains.kotlin.ideaExt.*
|
||||
|
||||
|
||||
val distDir: String by extra
|
||||
val ideaSandboxDir: File by extra
|
||||
val ideaSdkPath: String
|
||||
get() = rootProject.ideaHomePathForTests().absolutePath
|
||||
get() = rootProject.ideaHomePathForTests().get().asFile.absolutePath
|
||||
|
||||
fun MutableList<String>.addModularizedTestArgs(prefix: String, path: String, additionalParameters: Map<String, String>, benchFilter: String?) {
|
||||
add("-${prefix}fir.bench.prefix=$path")
|
||||
|
||||
@@ -23,7 +23,11 @@ fun Project.preparePublication() {
|
||||
|
||||
val sonatypeSnapshotsUrl = "https://oss.sonatype.org/content/repositories/snapshots/".takeIf { repo == "sonatype-nexus-snapshots" }
|
||||
|
||||
val repoUrl: String by extra((deployRepoUrl ?: sonatypeSnapshotsUrl ?: "file://${rootProject.buildDir}/repo").toString())
|
||||
val repoUrl: String by extra(
|
||||
(deployRepoUrl ?: sonatypeSnapshotsUrl ?: "file://${
|
||||
rootProject.layout.buildDirectory.dir("repo").get().asFile
|
||||
}").toString()
|
||||
)
|
||||
|
||||
val username: String? by extra(
|
||||
properties["kotlin.build.deploy-username"]?.toString() ?: properties["kotlin.${repoProvider}.user"]?.toString()
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
import org.gradle.api.file.Directory
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
|
||||
fun Test.useJsIrBoxTests(
|
||||
version: Any,
|
||||
buildDir: String = "",
|
||||
buildDir: Provider<Directory>,
|
||||
fullStdLib: String = "libraries/stdlib/build/classes/kotlin/js/main",
|
||||
reducedStdlibPath: String = "libraries/stdlib/js-ir-minimal-for-test/build/classes/kotlin/js/main",
|
||||
kotlinJsTestPath: String = "libraries/kotlin.test/js-ir/build/classes/kotlin/js/main",
|
||||
@@ -20,7 +22,7 @@ fun Test.useJsIrBoxTests(
|
||||
dependsOn(":kotlin-stdlib-js-ir-minimal-for-test:compileKotlinJs")
|
||||
dependsOn(":kotlin-dom-api-compat:compileKotlinJs")
|
||||
|
||||
systemProperty("kotlin.js.test.root.out.dir", buildDir)
|
||||
systemProperty("kotlin.js.test.root.out.dir", "${buildDir.get().asFile}/")
|
||||
systemProperty("kotlin.js.full.stdlib.path", fullStdLib)
|
||||
systemProperty("kotlin.js.reduced.stdlib.path", reducedStdlibPath)
|
||||
systemProperty("kotlin.js.kotlin.test.path", kotlinJsTestPath)
|
||||
|
||||
@@ -206,12 +206,12 @@ fun Project.projectTest(
|
||||
}
|
||||
|
||||
systemProperty("idea.is.unit.test", "true")
|
||||
systemProperty("idea.home.path", project.ideaHomePathForTests().canonicalPath)
|
||||
systemProperty("idea.home.path", project.ideaHomePathForTests().get().asFile.canonicalPath)
|
||||
systemProperty("idea.use.native.fs.for.win", false)
|
||||
systemProperty("java.awt.headless", "true")
|
||||
environment("NO_FS_ROOTS_ACCESS_CHECK", "true")
|
||||
environment("PROJECT_CLASSES_DIRS", project.testSourceSet.output.classesDirs.asPath)
|
||||
environment("PROJECT_BUILD_DIR", project.buildDir)
|
||||
environment("PROJECT_BUILD_DIR", project.layout.buildDirectory.get().asFile)
|
||||
systemProperty("jps.kotlin.home", project.rootProject.extra["distKotlinHomeDir"]!!)
|
||||
systemProperty("org.jetbrains.kotlin.skip.muted.tests", if (project.rootProject.hasProperty("skipMutedTests")) "true" else "false")
|
||||
systemProperty("cacheRedirectorEnabled", project.rootProject.findProperty("cacheRedirectorEnabled")?.toString() ?: "false")
|
||||
|
||||
+2
-2
@@ -19,13 +19,13 @@ private fun Project.createCommonMainSources() = tasks.register("commonMainSource
|
||||
"$rootDir/libraries/kotlin.test/common/src/main/kotlin",
|
||||
"$rootDir/libraries/kotlin.test/annotations-common/src/main/kotlin",
|
||||
)
|
||||
into("$buildDir/commonMainSources")
|
||||
into(layout.buildDirectory.dir("commonMainSources"))
|
||||
}
|
||||
private fun Project.createCommonWasmSources() = tasks.register<Sync>("commonWasmSources") {
|
||||
from(
|
||||
"$rootDir/libraries/kotlin.test/wasm/src/main/kotlin"
|
||||
)
|
||||
into("$buildDir/commonWasmSources")
|
||||
into(layout.buildDirectory.dir("commonWasmSources"))
|
||||
}
|
||||
|
||||
fun Project.configureWasmKotlinTest(
|
||||
|
||||
Reference in New Issue
Block a user