[gradle] Use more fine grained directory for K/N incremental compilation
Otherwise, two or more link tasks being executed in parallel will use the same directory for IC caches which might lead to races during compilation #KT-63471 Fixed
This commit is contained in:
+17
-8
@@ -93,7 +93,7 @@ class NativeIncrementalCompilationIT : KGPBaseTest() {
|
||||
nativeProject("native-incremental-simple", gradleVersion) {
|
||||
build("linkDebugExecutableHost") {
|
||||
assertDirectoryExists(
|
||||
getFileCache("native-incremental-simple", "src/hostMain/kotlin/main.kt", "")
|
||||
getFileCache("native-incremental-simple", "src/hostMain/kotlin/main.kt")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -105,8 +105,8 @@ class NativeIncrementalCompilationIT : KGPBaseTest() {
|
||||
nativeProject("native-incremental-multifile", gradleVersion) {
|
||||
var mainKtCacheModified = 0L
|
||||
var fooKtCacheModified = 0L
|
||||
val mainKtCache = getFileCache("native-incremental-multifile", "src/hostMain/kotlin/main.kt", "")
|
||||
val fooKtCache = getFileCache("native-incremental-multifile", "src/hostMain/kotlin/foo.kt", "")
|
||||
val mainKtCache = getFileCache("native-incremental-multifile", "src/hostMain/kotlin/main.kt")
|
||||
val fooKtCache = getFileCache("native-incremental-multifile", "src/hostMain/kotlin/foo.kt")
|
||||
build("linkDebugExecutableHost") {
|
||||
assertDirectoryExists(mainKtCache)
|
||||
assertDirectoryExists(fooKtCache)
|
||||
@@ -138,8 +138,8 @@ class NativeIncrementalCompilationIT : KGPBaseTest() {
|
||||
nativeProject("native-incremental-multifile", gradleVersion) {
|
||||
var mainKtCacheModified = 0L
|
||||
var fooKtCacheModified = 0L
|
||||
val mainKtCache = getFileCache("native-incremental-multifile", "src/hostMain/kotlin/main.kt", "")
|
||||
val fooKtCache = getFileCache("native-incremental-multifile", "src/hostMain/kotlin/foo.kt", "")
|
||||
val mainKtCache = getFileCache("native-incremental-multifile", "src/hostMain/kotlin/main.kt")
|
||||
val fooKtCache = getFileCache("native-incremental-multifile", "src/hostMain/kotlin/foo.kt")
|
||||
build("linkDebugExecutableHost") {
|
||||
assertDirectoryExists(mainKtCache)
|
||||
assertDirectoryExists(fooKtCache)
|
||||
@@ -172,9 +172,18 @@ class NativeIncrementalCompilationIT : KGPBaseTest() {
|
||||
var fooKtCacheModified = 0L
|
||||
var barKtCacheModified = 0L
|
||||
var mainKtCacheModified = 0L
|
||||
val fooKtCache = getFileCache("program", "MultiProject:library", "library/src/hostMain/kotlin/foo.kt", "")
|
||||
val barKtCache = getFileCache("program", "MultiProject:program", "program/src/hostMain/kotlin/bar.kt", "")
|
||||
val mainKtCache = getFileCache("program", "MultiProject:program", "program/src/hostMain/kotlin/main.kt", "")
|
||||
val fooKtCache = getFileCache(
|
||||
"MultiProject:library", "library/src/hostMain/kotlin/foo.kt",
|
||||
executableProjectName = "program"
|
||||
)
|
||||
val barKtCache = getFileCache(
|
||||
"MultiProject:program", "program/src/hostMain/kotlin/bar.kt",
|
||||
executableProjectName = "program"
|
||||
)
|
||||
val mainKtCache = getFileCache(
|
||||
"MultiProject:program", "program/src/hostMain/kotlin/main.kt",
|
||||
executableProjectName = "program"
|
||||
)
|
||||
build("linkDebugExecutableHost") {
|
||||
assertDirectoryExists(fooKtCache)
|
||||
assertDirectoryExists(barKtCache)
|
||||
|
||||
+6
-8
@@ -99,24 +99,22 @@ fun computeCacheDirName(
|
||||
partialLinkageEnabled: Boolean
|
||||
) = "$testTarget${if (debuggable) "-g" else ""}$cacheKind${if (partialLinkageEnabled) "-pl" else ""}"
|
||||
|
||||
fun TestProject.getFileCache(fileProjectName: String, fileRelativePath: String, fqName: String) =
|
||||
getFileCache("", fileProjectName, fileRelativePath, fqName)
|
||||
|
||||
fun TestProject.getFileCache(
|
||||
executableProjectName: String,
|
||||
fileProjectName: String,
|
||||
fileRelativePath: String,
|
||||
fqName: String,
|
||||
fqName: String = "",
|
||||
executableProjectName: String = "",
|
||||
executableName: String = "debugExecutable",
|
||||
): Path {
|
||||
val cacheFlavor = computeCacheDirName(HostManager.host, NativeCacheKind.STATIC.name, true, true)
|
||||
val libCacheDir = getICCacheDir(executableProjectName).resolve(cacheFlavor).resolve("$fileProjectName-per-file-cache")
|
||||
val libCacheDir = getICCacheDir(executableName, executableProjectName).resolve(cacheFlavor).resolve("$fileProjectName-per-file-cache")
|
||||
val fileId = cacheFileId(fqName, projectPath.resolve(fileRelativePath).toFile().canonicalPath)
|
||||
return libCacheDir.resolve(fileId)
|
||||
}
|
||||
|
||||
private fun TestProject.getICCacheDir(projectName: String = "") =
|
||||
private fun TestProject.getICCacheDir(executableName: String, projectName: String = "") =
|
||||
(if (projectName == "") projectPath else projectPath.resolve(projectName))
|
||||
.resolve("build/kotlin-native-ic-cache")
|
||||
.resolve("build/kotlin-native-ic-cache/$executableName")
|
||||
|
||||
private fun cacheFileId(fqName: String, filePath: String) =
|
||||
"${if (fqName == "") "ROOT" else fqName}.${filePath.hashCode().toString(Character.MAX_RADIX)}"
|
||||
|
||||
+3
-1
@@ -378,7 +378,9 @@ constructor(
|
||||
add("-Xauto-cache-from=${cacheSettings.gradleUserHomeDir}")
|
||||
add("-Xbackend-threads=${cacheSettings.threads}")
|
||||
if (cacheSettings.icEnabled) {
|
||||
val icCacheDir = cacheSettings.gradleBuildDir.resolve("kotlin-native-ic-cache")
|
||||
val icCacheDir = cacheSettings.gradleBuildDir
|
||||
.resolve("kotlin-native-ic-cache")
|
||||
.resolve(binaryName)
|
||||
icCacheDir.mkdirs()
|
||||
add("-Xenable-incremental-compilation")
|
||||
add("-Xic-cache-dir=$icCacheDir")
|
||||
|
||||
Reference in New Issue
Block a user