From 5a1513ad59c01adb9f2ba02928daf28eba470cc9 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Sat, 5 Mar 2022 15:17:43 +0300 Subject: [PATCH] Native build: make distCompiler no-op when using custom dist Custom dist is already in place and has the compiler, so we don't have to build and copy the compiler to dist. Moreover, if we do copy it, it might overwrite the compiler files already loaded by this Gradle process (including the jar loaded to the custom classloader), causing hard-to-debug errors. To workaround this, we disable the distCompiler task and don't add any dependencies to it when custom dist is used. --- kotlin-native/build.gradle | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kotlin-native/build.gradle b/kotlin-native/build.gradle index 6ede46195b2..2f2baeedf08 100644 --- a/kotlin-native/build.gradle +++ b/kotlin-native/build.gradle @@ -246,9 +246,19 @@ task shadowJar(type: ShadowJar) { } task distCompiler(type: Copy) { - dependsOn ":kotlin-native:dependencies:update" - dependsOn ':kotlin-native:shadowJar' - dependsOn ":kotlin-native-compiler-embeddable:kotlin-native-compiler-embeddable" + // Workaround: make distCompiler no-op if we are using custom dist: + // the dist is already in place and has the compiler, so we don't have to + // build and copy the compiler to dist. + // Moreover, if we do copy it, it might overwrite the compiler files already loaded + // by this Gradle process (including the jar loaded to the custom classloader), + // causing hard-to-debug errors. + if (!UtilsKt.isDefaultNativeHome(project)) { + enabled = false + } else { + dependsOn ":kotlin-native:dependencies:update" + dependsOn ':kotlin-native:shadowJar' + dependsOn ":kotlin-native-compiler-embeddable:kotlin-native-compiler-embeddable" + } destinationDir distDir