[Gradle, K/N] Configuration cache support for compile & link with warns
#KT-43151 Fixed
This commit is contained in:
+3
-4
@@ -29,11 +29,10 @@ abstract class AbstractKotlinNativeCompilation(
|
||||
compilationName: String
|
||||
) : AbstractKotlinCompilation<KotlinCommonOptions>(target, compilationName) {
|
||||
|
||||
override val kotlinOptions: KotlinCommonOptions = NativeCompileOptions()
|
||||
override val kotlinOptions: KotlinCommonOptions = NativeCompileOptions { defaultSourceSet.languageSettings }
|
||||
|
||||
private inner class NativeCompileOptions : KotlinCommonOptions {
|
||||
private val languageSettings: LanguageSettingsBuilder
|
||||
get() = defaultSourceSet.languageSettings
|
||||
private class NativeCompileOptions(languageSettingsProvider: () -> LanguageSettingsBuilder) : KotlinCommonOptions {
|
||||
private val languageSettings: LanguageSettingsBuilder by lazy(languageSettingsProvider)
|
||||
|
||||
override var apiVersion: String?
|
||||
get() = languageSettings.apiVersion
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ sealed class NativeBinary(
|
||||
private val name: String,
|
||||
baseNameProvided: String,
|
||||
val buildType: NativeBuildType,
|
||||
@Transient
|
||||
var compilation: KotlinNativeCompilation
|
||||
) : Named {
|
||||
open var baseName: String
|
||||
|
||||
+41
-23
@@ -116,6 +116,11 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Abst
|
||||
@get:Internal
|
||||
abstract val compilation: Provider<K>
|
||||
|
||||
@get:Internal
|
||||
internal val compilationIsShared by lazy {
|
||||
compilation.get() is KotlinSharedNativeCompilation
|
||||
}
|
||||
|
||||
// region inputs/outputs
|
||||
@get:Input
|
||||
abstract val outputKind: CompilerOutputKind
|
||||
@@ -129,6 +134,14 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Abst
|
||||
@get:Internal
|
||||
abstract val baseName: String
|
||||
|
||||
@get:Internal
|
||||
internal val objects = project.objects
|
||||
|
||||
@get:Internal
|
||||
internal val konanTarget by lazy {
|
||||
compilation.get().konanTarget
|
||||
}
|
||||
|
||||
// Inputs and outputs
|
||||
@InputFiles
|
||||
@SkipWhenEmpty
|
||||
@@ -140,9 +153,9 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Abst
|
||||
@get:Classpath
|
||||
val libraries: FileCollection by project.provider {
|
||||
// Avoid resolving these dependencies during task graph construction when we can't build the target:
|
||||
if (compilation.get().konanTarget.enabledOnCurrentHost)
|
||||
if (konanTarget.enabledOnCurrentHost)
|
||||
compilation.get().compileDependencyFiles.filterOutPublishableInteropLibs(project)
|
||||
else project.files()
|
||||
else objects.fileCollection()
|
||||
}
|
||||
|
||||
@Deprecated("For native tasks use 'libraries' instead", ReplaceWith("libraries"))
|
||||
@@ -182,8 +195,6 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Abst
|
||||
|
||||
@Internal
|
||||
open val outputFile: Provider<File> = project.provider {
|
||||
val konanTarget = compilation.get().konanTarget
|
||||
|
||||
val prefix = outputKind.prefix(konanTarget)
|
||||
val suffix = outputKind.suffix(konanTarget)
|
||||
val filename = "$prefix${baseName}$suffix".let {
|
||||
@@ -221,6 +232,11 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Abst
|
||||
val defaultSerializedCompilerArguments: List<String>
|
||||
get() = buildCommonArgs(true)
|
||||
|
||||
@get:Internal
|
||||
internal val languageSettingsBuilder by lazy {
|
||||
compilation.get().defaultSourceSet.languageSettings
|
||||
}
|
||||
|
||||
// Args used by both the compiler and IDEA.
|
||||
protected open fun buildCommonArgs(defaultsOnly: Boolean = false): List<String> = mutableListOf<String>().apply {
|
||||
add("-Xmulti-platform")
|
||||
@@ -250,7 +266,7 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Abst
|
||||
addAll(additionalCompilerOptions.get())
|
||||
}
|
||||
|
||||
(compilation.get().defaultSourceSet.languageSettings as? DefaultLanguageSettingsBuilder)?.run {
|
||||
(languageSettingsBuilder as? DefaultLanguageSettingsBuilder)?.run {
|
||||
addAll(freeCompilerArgs)
|
||||
}
|
||||
}
|
||||
@@ -277,10 +293,10 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Abst
|
||||
addKey("-g", debuggable)
|
||||
addKey("-ea", debuggable)
|
||||
|
||||
addArg("-target", target)
|
||||
addArg("-target", konanTarget.name)
|
||||
addArg("-p", outputKind.name.toLowerCase())
|
||||
|
||||
if (compilation.get() is KotlinSharedNativeCompilation) {
|
||||
if (compilationIsShared) {
|
||||
add("-Xexpect-actual-linker")
|
||||
add("-Xmetadata-klib")
|
||||
addArg("-manifest", manifestFile.get().absolutePath)
|
||||
@@ -307,7 +323,7 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Abst
|
||||
val output = outputFile.get()
|
||||
output.parentFile.mkdirs()
|
||||
|
||||
if (compilation.get() is KotlinSharedNativeCompilation) {
|
||||
if (compilationIsShared) {
|
||||
val manifestFile: File = manifestFile.get()
|
||||
manifestFile.ensureParentDirsCreated()
|
||||
val properties = java.util.Properties()
|
||||
@@ -396,8 +412,9 @@ open class KotlinNativeCompile : AbstractKotlinNativeCompile<KotlinCommonOptions
|
||||
// endregion.
|
||||
|
||||
// region Kotlin options.
|
||||
override val kotlinOptions: KotlinCommonOptions
|
||||
get() = compilation.get().kotlinOptions
|
||||
override val kotlinOptions: KotlinCommonOptions by lazy {
|
||||
compilation.get().kotlinOptions
|
||||
}
|
||||
|
||||
@get:Input
|
||||
override val additionalCompilerOptions: Provider<Collection<String>> = project.provider {
|
||||
@@ -468,7 +485,6 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
}
|
||||
|
||||
@Internal
|
||||
@Transient
|
||||
lateinit var binary: NativeBinary
|
||||
|
||||
@Internal // Taken into account by getSources().
|
||||
@@ -479,7 +495,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
@InputFiles
|
||||
@SkipWhenEmpty
|
||||
override fun getSource(): FileTree =
|
||||
project.files(intermediateLibrary.get()).asFileTree
|
||||
objects.fileCollection().from(intermediateLibrary.get()).asFileTree
|
||||
|
||||
@OutputDirectory
|
||||
override fun getDestinationDir(): File {
|
||||
@@ -503,8 +519,9 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
@Input get() = binary.baseName
|
||||
|
||||
@get:Input
|
||||
protected val konanCacheKind: NativeCacheKind
|
||||
get() = project.konanCacheKind
|
||||
protected val konanCacheKind: NativeCacheKind by lazy {
|
||||
project.konanCacheKind
|
||||
}
|
||||
|
||||
inner class NativeLinkOptions : KotlinCommonToolOptions {
|
||||
override var allWarningsAsErrors: Boolean = false
|
||||
@@ -543,14 +560,15 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
@Input get() = binary is TestExecutable
|
||||
|
||||
@get:Classpath
|
||||
val exportLibraries: FileCollection
|
||||
get() = binary.let {
|
||||
val exportLibraries: FileCollection by lazy {
|
||||
binary.let {
|
||||
if (it is AbstractNativeLibrary) {
|
||||
project.configurations.getByName(it.exportConfigurationName)
|
||||
} else {
|
||||
project.files()
|
||||
objects.fileCollection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@get:Input
|
||||
val isStaticFramework: Boolean by project.provider {
|
||||
@@ -565,7 +583,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
override fun buildCompilerArgs(): List<String> = mutableListOf<String>().apply {
|
||||
addAll(super.buildCompilerArgs())
|
||||
|
||||
addAll(CacheBuilder(project, binary).buildCompilerArgs())
|
||||
addAll(CacheBuilder(project, binary, konanTarget).buildCompilerArgs())
|
||||
|
||||
addKey("-tr", processTests)
|
||||
addArgIfNotNull("-entry", entryPoint)
|
||||
@@ -643,7 +661,7 @@ open class KotlinNativeLink : AbstractKotlinNativeCompile<KotlinCommonToolOption
|
||||
}
|
||||
}
|
||||
|
||||
internal class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
internal class CacheBuilder(val project: Project, val binary: NativeBinary, val konanTarget: KonanTarget) {
|
||||
|
||||
private val nativeSingleFileResolveStrategy: SingleFileKlibResolveStrategy
|
||||
get() = CompilerSingleFileKlibResolveAllowingIrProvidersStrategy(
|
||||
@@ -666,10 +684,10 @@ internal class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
get() = compilation.compileDependencyFiles.filterOutPublishableInteropLibs(project)
|
||||
|
||||
private val target: String
|
||||
get() = compilation.konanTarget.name
|
||||
get() = konanTarget.name
|
||||
|
||||
private val rootCacheDirectory by lazy {
|
||||
getRootCacheDirectory(File(project.konanHome), compilation.konanTarget, debuggable, konanCacheKind)
|
||||
getRootCacheDirectory(File(project.konanHome), konanTarget, debuggable, konanCacheKind)
|
||||
}
|
||||
|
||||
private fun getAllDependencies(dependency: ResolvedDependency): Set<ResolvedDependency> {
|
||||
@@ -830,7 +848,7 @@ internal class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
|
||||
private fun ensureCompilerProvidedLibsPrecached() {
|
||||
val distribution = Distribution(project.konanHome)
|
||||
val platformLibs = (listOf(File(distribution.stdlib)) + File(distribution.platformLibs(compilation.konanTarget))
|
||||
val platformLibs = (listOf(File(distribution.stdlib)) + File(distribution.platformLibs(konanTarget))
|
||||
.listFiles()).associateBy { it.name }
|
||||
val visitedLibs = mutableSetOf<String>()
|
||||
for (platformLibName in platformLibs.keys)
|
||||
@@ -839,7 +857,7 @@ internal class CacheBuilder(val project: Project, val binary: NativeBinary) {
|
||||
|
||||
|
||||
fun buildCompilerArgs(): List<String> = mutableListOf<String>().apply {
|
||||
if (konanCacheKind != NativeCacheKind.NONE && !optimized && cacheWorksFor(compilation.konanTarget)) {
|
||||
if (konanCacheKind != NativeCacheKind.NONE && !optimized && cacheWorksFor(konanTarget)) {
|
||||
rootCacheDirectory.mkdirs()
|
||||
ensureCompilerProvidedLibsPrecached()
|
||||
add("-Xcache-directory=${rootCacheDirectory.absolutePath}")
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
package org.jetbrains.kotlin.konan.target
|
||||
|
||||
import org.jetbrains.kotlin.konan.util.Named
|
||||
import java.io.Serializable
|
||||
|
||||
sealed class KonanTarget(override val name: String, val family: Family, val architecture: Architecture) : Named {
|
||||
sealed class KonanTarget(override val name: String, val family: Family, val architecture: Architecture) : Named, Serializable {
|
||||
object ANDROID_X64 : KonanTarget("android_x64", Family.ANDROID, Architecture.X64)
|
||||
object ANDROID_X86 : KonanTarget("android_x86", Family.ANDROID, Architecture.X86)
|
||||
object ANDROID_ARM32 : KonanTarget("android_arm32", Family.ANDROID, Architecture.ARM32)
|
||||
|
||||
Reference in New Issue
Block a user