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