Gradle, native: Support reinstalling K/N compiler
Sometimes a user may need to invalidate all precompiled caches and regenerate all platform libraries. For example this may be necessary after updating Xcode since platform libraries are generated on basis of Xcode frameworks. This patch provides a simple setting allowing a user to manually reinstall a K/N compiler.
This commit is contained in:
+18
@@ -138,4 +138,22 @@ class NativePlatformLibsIT : BaseGradleIT() {
|
||||
assertContainsRegex("Run tool: \"generatePlatformLibraries\" with args: .* -mode metadata".toRegex())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompilerReinstallation() = with(platformLibrariesProject("linuxX64")) {
|
||||
deleteInstalledCompilers()
|
||||
|
||||
// Install the compiler at the first time. Don't build to reduce execution time.
|
||||
build("tasks") {
|
||||
assertSuccessful()
|
||||
assertContains("Generate platform libraries for linux_x64")
|
||||
}
|
||||
|
||||
// Reinstall the compiler.
|
||||
build("tasks", "-Pkotlin.native.reinstall=true") {
|
||||
assertSuccessful()
|
||||
assertContains("Unpack Kotlin/Native compiler to ")
|
||||
assertContains("Generate platform libraries for linux_x64")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -163,6 +163,18 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
val nativeVersion: String?
|
||||
get() = propertyWithDeprecatedVariant("kotlin.native.version", "org.jetbrains.kotlin.native.version")
|
||||
|
||||
/**
|
||||
* Forces reinstalling a K/N distribution.
|
||||
*
|
||||
* The current distribution directory will be removed along with generated platform libraries and precompiled dependencies.
|
||||
* After that a fresh distribution with the same version will be installed. Platform libraries and precompiled dependencies will
|
||||
* be built in a regular way.
|
||||
*
|
||||
* Ignored if kotlin.native.home is specified.
|
||||
*/
|
||||
val nativeReinstall: Boolean
|
||||
get() = booleanProperty("kotlin.native.reinstall") ?: false
|
||||
|
||||
/**
|
||||
* Allows a user to specify additional arguments of a JVM executing a K/N compiler.
|
||||
*/
|
||||
|
||||
+11
-4
@@ -13,7 +13,6 @@ import org.gradle.api.Project
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.jetbrains.kotlin.compilerRunner.konanHome
|
||||
import org.jetbrains.kotlin.compilerRunner.konanVersion
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeDistributionType
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeDistributionType.REGULAR
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
@@ -25,7 +24,6 @@ import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import org.jetbrains.kotlin.konan.CompilerVersion
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
|
||||
private val name: String,
|
||||
@@ -46,12 +44,21 @@ abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
|
||||
extensions.extraProperties.set(KOTLIN_NATIVE_HOME_PRIVATE_PROPERTY, konanHome)
|
||||
}
|
||||
|
||||
private val propertiesProvider = PropertiesProvider(project)
|
||||
|
||||
private val isKonanHomeOverridden: Boolean
|
||||
get() = PropertiesProvider(project).nativeHome != null
|
||||
get() = propertiesProvider.nativeHome != null
|
||||
|
||||
private fun setupNativeCompiler() = with(project) {
|
||||
if (!isKonanHomeOverridden) {
|
||||
NativeCompilerDownloader(this).downloadIfNeeded()
|
||||
val downloader = NativeCompilerDownloader(this)
|
||||
|
||||
if (propertiesProvider.nativeReinstall) {
|
||||
logger.info("Reinstall Kotlin/Native distribution")
|
||||
downloader.compilerDirectory.deleteRecursively()
|
||||
}
|
||||
|
||||
downloader.downloadIfNeeded()
|
||||
logger.info("Kotlin/Native distribution: $konanHome")
|
||||
} else {
|
||||
logger.info("User-provided Kotlin/Native distribution: $konanHome")
|
||||
|
||||
Reference in New Issue
Block a user