[Gradle] Fixed race condition during k/n bundle downloading
Extended lock bounds. Moved removing an old bundle back to configuration phase. ^KT-65985 Fixed
This commit is contained in:
committed by
Space Team
parent
b7de3709e4
commit
808d4353e5
+40
-18
@@ -38,6 +38,8 @@ internal abstract class KotlinNativeBundleBuildService : BuildService<BuildServi
|
|||||||
@get:Inject
|
@get:Inject
|
||||||
abstract val fso: FileSystemOperations
|
abstract val fso: FileSystemOperations
|
||||||
|
|
||||||
|
private var canBeReinstalled: Boolean = true // we can reinstall a k/n bundle once during the build
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun registerIfAbsent(project: Project): Provider<KotlinNativeBundleBuildService> =
|
fun registerIfAbsent(project: Project): Provider<KotlinNativeBundleBuildService> =
|
||||||
project.gradle.sharedServices.registerIfAbsent(
|
project.gradle.sharedServices.registerIfAbsent(
|
||||||
@@ -62,37 +64,57 @@ internal abstract class KotlinNativeBundleBuildService : BuildService<BuildServi
|
|||||||
konanTargets: Set<KonanTarget>,
|
konanTargets: Set<KonanTarget>,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val lock = NativeDistributionCommonizerLock(bundleDir) { message -> project.logger.info("Kotlin Native Bundle: $message") }
|
val lock =
|
||||||
|
NativeDistributionCommonizerLock(bundleDir) { message -> project.logger.info("Kotlin Native Bundle: $message") }
|
||||||
|
|
||||||
if (reinstallFlag) {
|
lock.withLock {
|
||||||
lock.withLock {
|
|
||||||
bundleDir.deleteRecursively()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!bundleDir.resolve(KONAN_DIRECTORY_NAME_TO_CHECK_EXISTENCE).exists()) {
|
removeBundleIfNeeded(reinstallFlag, bundleDir)
|
||||||
val gradleCachesKotlinNativeDir =
|
|
||||||
kotlinNativeCompilerConfiguration
|
|
||||||
.singleOrNull()
|
|
||||||
?.resolve(kotlinNativeVersion)
|
|
||||||
?: error(
|
|
||||||
"Kotlin Native dependency has not been properly resolved. " +
|
|
||||||
"Please, make sure that you've declared the repository, which contains $kotlinNativeVersion."
|
|
||||||
)
|
|
||||||
|
|
||||||
project.logger.info("Moving Kotlin/Native bundle from tmp directory $gradleCachesKotlinNativeDir to ${bundleDir.absolutePath}")
|
if (!bundleDir.resolve(KONAN_DIRECTORY_NAME_TO_CHECK_EXISTENCE).exists()) {
|
||||||
lock.withLock {
|
val gradleCachesKotlinNativeDir =
|
||||||
|
resolveKotlinNativeConfiguration(kotlinNativeVersion, kotlinNativeCompilerConfiguration)
|
||||||
|
|
||||||
|
project.logger.info("Moving Kotlin/Native bundle from tmp directory $gradleCachesKotlinNativeDir to ${bundleDir.absolutePath}")
|
||||||
fso.copy {
|
fso.copy {
|
||||||
it.from(gradleCachesKotlinNativeDir)
|
it.from(gradleCachesKotlinNativeDir)
|
||||||
it.into(bundleDir)
|
it.into(bundleDir)
|
||||||
}
|
}
|
||||||
|
project.logger.info("Moved Kotlin/Native bundle from $gradleCachesKotlinNativeDir to ${bundleDir.absolutePath}")
|
||||||
}
|
}
|
||||||
project.logger.info("Moved Kotlin/Native bundle from $gradleCachesKotlinNativeDir to ${bundleDir.absolutePath}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
project.setupKotlinNativeDependencies(konanTargets)
|
project.setupKotlinNativeDependencies(konanTargets)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun removeBundleIfNeeded(
|
||||||
|
reinstallFlag: Boolean,
|
||||||
|
bundleDir: File,
|
||||||
|
) {
|
||||||
|
if (reinstallFlag && canBeReinstalled) {
|
||||||
|
bundleDir.deleteRecursively()
|
||||||
|
canBeReinstalled = false // we don't need to reinstall k/n if it was reinstalled once during the same build
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun resolveKotlinNativeConfiguration(
|
||||||
|
kotlinNativeVersion: String,
|
||||||
|
kotlinNativeCompilerConfiguration: ConfigurableFileCollection,
|
||||||
|
): File {
|
||||||
|
val resolutionErrorMessage = "Kotlin Native dependency has not been properly resolved. " +
|
||||||
|
"Please, make sure that you've declared the repository, which contains $kotlinNativeVersion."
|
||||||
|
|
||||||
|
val gradleCachesKotlinNativeDir = kotlinNativeCompilerConfiguration
|
||||||
|
.singleOrNull()
|
||||||
|
?.resolve(kotlinNativeVersion)
|
||||||
|
?: error(resolutionErrorMessage)
|
||||||
|
|
||||||
|
if (!gradleCachesKotlinNativeDir.exists()) {
|
||||||
|
throw IllegalArgumentException(resolutionErrorMessage)
|
||||||
|
}
|
||||||
|
return gradleCachesKotlinNativeDir
|
||||||
|
}
|
||||||
|
|
||||||
private fun Project.setupKotlinNativeDependencies(konanTargets: Set<KonanTarget>) {
|
private fun Project.setupKotlinNativeDependencies(konanTargets: Set<KonanTarget>) {
|
||||||
val distributionType = NativeDistributionTypeProvider(this).getDistributionType()
|
val distributionType = NativeDistributionTypeProvider(this).getDistributionType()
|
||||||
if (distributionType.mustGeneratePlatformLibs) {
|
if (distributionType.mustGeneratePlatformLibs) {
|
||||||
|
|||||||
Reference in New Issue
Block a user