[gradle] Gradle property to switch between caching orchestration machineries
This is needed only for the translation period between old (Gradle) machinery and the one (implemented directly in the K/N compiler)
This commit is contained in:
+4
@@ -236,6 +236,7 @@ class CachedLibraries(
|
||||
fun computeVersionedCacheDirectory(baseCacheDirectory: File, library: KotlinLibrary, allLibraries: List<KotlinLibrary>): File {
|
||||
val dependencies = getAllDependencies(library, allLibraries)
|
||||
val messageDigest = MessageDigest.getInstance("SHA-256")
|
||||
messageDigest.update(compilerMarker)
|
||||
messageDigest.digestLibrary(library)
|
||||
dependencies.sortedBy { it.uniqueName }.forEach { messageDigest.digestLibrary(it) }
|
||||
|
||||
@@ -252,5 +253,8 @@ class CachedLibraries(
|
||||
const val INLINE_FUNCTION_BODIES_FILE_NAME = "inline_bodies"
|
||||
const val CLASS_FIELDS_FILE_NAME = "class_fields"
|
||||
const val EAGER_INITIALIZED_PROPERTIES_FILE_NAME = "eager_init"
|
||||
|
||||
// TODO: Remove after dropping Gradle cache orchestration.
|
||||
private val compilerMarker = "K/N orchestration".encodeToByteArray()
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -10,6 +10,7 @@ import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheOrchestration
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.isAtLeast
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.nativeUseEmbeddableCompilerJar
|
||||
@@ -48,6 +49,10 @@ internal fun Project.getKonanCacheKind(target: KonanTarget): NativeCacheKind {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Project.getKonanCacheOrchestration(): NativeCacheOrchestration {
|
||||
return PropertiesProvider(this).nativeCacheOrchestration ?: NativeCacheOrchestration.Compiler
|
||||
}
|
||||
|
||||
private val Project.kotlinNativeCompilerJar: String
|
||||
get() = if (nativeUseEmbeddableCompilerJar)
|
||||
"$konanHome/konan/lib/kotlin-native-compiler-embeddable.jar"
|
||||
|
||||
+11
@@ -409,3 +409,14 @@ enum class NativeCacheKind(val produce: String?, val outputKind: CompilerOutputK
|
||||
NativeCacheKind.values().firstOrNull { it.name.equals(argument, ignoreCase = true) }
|
||||
}
|
||||
}
|
||||
|
||||
// This is a temporary parameter for the translation period.
|
||||
enum class NativeCacheOrchestration {
|
||||
Gradle,
|
||||
Compiler;
|
||||
|
||||
companion object {
|
||||
fun byCompilerArgument(argument: String): NativeCacheOrchestration? =
|
||||
NativeCacheOrchestration.values().firstOrNull { it.name.equals(argument, ignoreCase = true) }
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -10,6 +10,7 @@ import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||
import org.jetbrains.kotlin.cli.common.toBooleanLenient
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheOrchestration
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessageOutputStreamHandler.Companion.IGNORE_TCSM_OVERFLOW
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.Companion.jsCompilerProperty
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_ABI_SNAPSHOT
|
||||
@@ -396,6 +397,12 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
fun nativeCacheKindForTarget(target: KonanTarget): NativeCacheKind? =
|
||||
this.property("kotlin.native.cacheKind.${target.presetName}")?.let { NativeCacheKind.byCompilerArgument(it) }
|
||||
|
||||
/**
|
||||
* Dependencies caching orchestration machinery.
|
||||
*/
|
||||
val nativeCacheOrchestration: NativeCacheOrchestration?
|
||||
get() = this.property(PropertyNames.KOTLIN_NATIVE_CACHE_ORCHESTRATION)?.let { NativeCacheOrchestration.byCompilerArgument(it) }
|
||||
|
||||
/**
|
||||
* Ignore overflow in [org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessageOutputStreamHandler]
|
||||
*/
|
||||
@@ -530,6 +537,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
||||
const val KOTLIN_MPP_ANDROID_SOURCE_SET_LAYOUT_ANDROID_STYLE_NO_WARN = "kotlin.mpp.androidSourceSetLayoutV2AndroidStyleDirs.nowarn"
|
||||
const val KOTLIN_MPP_IMPORT_ENABLE_SLOW_SOURCES_JAR_RESOLVER = "kotlin.mpp.import.enableSlowSourcesJarResolver"
|
||||
const val KOTLIN_NATIVE_DEPENDENCY_PROPAGATION = "kotlin.native.enableDependencyPropagation"
|
||||
const val KOTLIN_NATIVE_CACHE_ORCHESTRATION = "kotlin.native.cacheOrchestration"
|
||||
const val KOTLIN_MPP_ENABLE_OPTIMISTIC_NUMBER_COMMONIZATION = "kotlin.mpp.enableOptimisticNumberCommonization"
|
||||
const val KOTLIN_MPP_ENABLE_PLATFORM_INTEGER_COMMONIZATION = "kotlin.mpp.enablePlatformIntegerCommonization"
|
||||
const val KOTLIN_ABI_SNAPSHOT = "kotlin.incremental.classpath.snapshot.enabled"
|
||||
|
||||
+25
-6
@@ -21,6 +21,7 @@ import org.gradle.process.ExecOperations
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinNativeCompilerRunner
|
||||
import org.jetbrains.kotlin.compilerRunner.KotlinToolRunner
|
||||
import org.jetbrains.kotlin.compilerRunner.getKonanCacheKind
|
||||
import org.jetbrains.kotlin.compilerRunner.getKonanCacheOrchestration
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
|
||||
@@ -192,6 +193,12 @@ constructor(
|
||||
CacheBuilder.Settings.createWithProject(project, binary, konanTarget, toolOptions, externalDependenciesArgs)
|
||||
}
|
||||
|
||||
private class CacheSettings(val orchestration: NativeCacheOrchestration, val kind: NativeCacheKind, val gradleUserHomeDir: File)
|
||||
|
||||
private val cacheSettings by lazy {
|
||||
CacheSettings(project.getKonanCacheOrchestration(), project.getKonanCacheKind(konanTarget), project.gradle.gradleUserHomeDir)
|
||||
}
|
||||
|
||||
override fun createCompilerArgs(): StubK2NativeCompilerArguments = StubK2NativeCompilerArguments()
|
||||
|
||||
override fun setupCompilerArgs(
|
||||
@@ -297,11 +304,23 @@ constructor(
|
||||
)
|
||||
|
||||
val executionContext = KotlinToolRunner.GradleExecutionContext.fromTaskContext(objectFactory, execOperations, logger)
|
||||
val cacheArgs = CacheBuilder(
|
||||
executionContext = executionContext,
|
||||
settings = cacheBuilderSettings,
|
||||
konanPropertiesService = konanPropertiesService.get()
|
||||
).buildCompilerArgs(resolvedDependencyGraph)
|
||||
val additionalOptions = mutableListOf<String>().apply {
|
||||
addAll(externalDependenciesArgs)
|
||||
when (cacheSettings.orchestration) {
|
||||
NativeCacheOrchestration.Compiler -> {
|
||||
if (cacheSettings.kind != NativeCacheKind.NONE && konanPropertiesService.get().cacheWorksFor(konanTarget))
|
||||
add("-Xauto-cache-from=${cacheSettings.gradleUserHomeDir}")
|
||||
}
|
||||
NativeCacheOrchestration.Gradle -> {
|
||||
val cacheBuilder = CacheBuilder(
|
||||
executionContext = executionContext,
|
||||
settings = cacheBuilderSettings,
|
||||
konanPropertiesService = konanPropertiesService.get()
|
||||
)
|
||||
addAll(cacheBuilder.buildCompilerArgs(resolvedDependencyGraph))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION") val enableEndorsedLibs = this.enableEndorsedLibs // TODO: remove before 1.9.0, see KT-54098
|
||||
|
||||
@@ -324,7 +343,7 @@ constructor(
|
||||
isStaticFramework,
|
||||
exportLibraries.files.filterKlibsPassedToCompiler(),
|
||||
sources.asFileTree.files.toList(),
|
||||
externalDependenciesArgs + cacheArgs
|
||||
additionalOptions
|
||||
)
|
||||
|
||||
KotlinNativeCompilerRunner(
|
||||
|
||||
Reference in New Issue
Block a user