Common iOS: Store konanTarget in KotlinNativeCompilation
This commit is contained in:
+2
@@ -20,10 +20,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import java.util.concurrent.Callable
|
||||
|
||||
class KotlinNativeCompilation(
|
||||
override val target: KotlinNativeTarget,
|
||||
val konanTarget: KonanTarget,
|
||||
name: String
|
||||
) : AbstractKotlinCompilation<KotlinCommonOptions>(target, name), KotlinCompilationWithResources<KotlinCommonOptions> {
|
||||
|
||||
|
||||
+1
-4
@@ -7,9 +7,6 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.whenEvaluated
|
||||
import org.jetbrains.kotlin.gradle.targets.native.CompilationFreeArgsValidator
|
||||
|
||||
class KotlinNativeCompilationFactory(
|
||||
val project: Project,
|
||||
@@ -24,5 +21,5 @@ class KotlinNativeCompilationFactory(
|
||||
// when the compilation and the link args are separated (see KT-33717).
|
||||
// Note: such validation should be done in the whenEvaluate block because
|
||||
// a user can change args during project configuration.
|
||||
KotlinNativeCompilation(target, name)
|
||||
KotlinNativeCompilation(target, target.konanTarget, name)
|
||||
}
|
||||
+5
-5
@@ -59,7 +59,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
|
||||
producingTask: Task,
|
||||
copy: Boolean = false
|
||||
) {
|
||||
if (!compilation.target.konanTarget.enabledOnCurrentHost) {
|
||||
if (!compilation.konanTarget.enabledOnCurrentHost) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
|
||||
this.binary = binary
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Links ${binary.outputKind.description} '${binary.name}' for a target '${target.name}'."
|
||||
enabled = target.konanTarget.enabledOnCurrentHost
|
||||
enabled = binary.konanTarget.enabledOnCurrentHost
|
||||
destinationDir = binary.outputDirectory
|
||||
addCompilerPlugins()
|
||||
|
||||
@@ -135,7 +135,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
|
||||
group = RUN_GROUP
|
||||
description = "Executes Kotlin/Native executable ${binary.name} for target ${binary.target.name}"
|
||||
|
||||
enabled = binary.target.konanTarget.isCurrentHost
|
||||
enabled = binary.konanTarget.isCurrentHost
|
||||
|
||||
executable = binary.outputFile.absolutePath
|
||||
workingDir = project.projectDir
|
||||
@@ -154,7 +154,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Compiles a klibrary from the '${compilation.name}' " +
|
||||
"compilation for target '${compilation.platformType.name}'."
|
||||
enabled = compilation.target.konanTarget.enabledOnCurrentHost
|
||||
enabled = compilation.konanTarget.enabledOnCurrentHost
|
||||
|
||||
destinationDir = klibOutputDirectory(compilation)
|
||||
addCompilerPlugins()
|
||||
@@ -185,7 +185,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget>(
|
||||
description = "Generates Kotlin/Native interop library '${interop.name}' " +
|
||||
"for compilation '${compilation.name}'" +
|
||||
"of target '${konanTarget.name}'."
|
||||
enabled = compilation.target.konanTarget.enabledOnCurrentHost
|
||||
enabled = compilation.konanTarget.enabledOnCurrentHost
|
||||
|
||||
val interopOutput = project.files(outputFileProvider).builtBy(this)
|
||||
with(compilation) {
|
||||
|
||||
+2
-2
@@ -90,8 +90,8 @@ abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
|
||||
// Allow IDE to resolve the libraries provided by the compiler by adding them into dependencies.
|
||||
|
||||
result.compilations.all { compilation ->
|
||||
val target = compilation.target.konanTarget
|
||||
compilation.target.project.whenEvaluated {
|
||||
val target = compilation.konanTarget
|
||||
project.whenEvaluated {
|
||||
// First, put common libs:
|
||||
defaultLibs(!compilation.enableEndorsedLibs).forEach {
|
||||
project.dependencies.add(compilation.compileDependencyConfigurationName, it)
|
||||
|
||||
+5
-2
@@ -32,6 +32,9 @@ sealed class NativeBinary(
|
||||
var compilation: KotlinNativeCompilation
|
||||
) : Named {
|
||||
|
||||
internal val konanTarget: KonanTarget
|
||||
get() = compilation.konanTarget
|
||||
|
||||
val target: KotlinNativeTarget
|
||||
get() = compilation.target
|
||||
|
||||
@@ -120,7 +123,7 @@ class Executable constructor(
|
||||
* Returns null if the executables's target is not a host one (macosX64, linuxX64 or mingw64).
|
||||
*/
|
||||
val runTaskName: String?
|
||||
get() = if (target.konanTarget in listOf(KonanTarget.MACOS_X64, KonanTarget.LINUX_X64, KonanTarget.MINGW_X64)) {
|
||||
get() = if (konanTarget in listOf(KonanTarget.MACOS_X64, KonanTarget.LINUX_X64, KonanTarget.MINGW_X64)) {
|
||||
lowerCamelCaseName("run", name, compilation.target.targetName)
|
||||
} else {
|
||||
null
|
||||
@@ -215,7 +218,7 @@ class Framework(
|
||||
/**
|
||||
* Embed bitcode for the framework or not. See [BitcodeEmbeddingMode].
|
||||
*/
|
||||
var embedBitcode: BitcodeEmbeddingMode = buildType.embedBitcode(target.konanTarget)
|
||||
var embedBitcode: BitcodeEmbeddingMode = buildType.embedBitcode(konanTarget)
|
||||
|
||||
/**
|
||||
* Enable or disable embedding bitcode for the framework. See [BitcodeEmbeddingMode].
|
||||
|
||||
+3
-3
@@ -130,7 +130,7 @@ open class FatFrameworkTask: DefaultTask() {
|
||||
*/
|
||||
fun from(frameworks: Iterable<Framework>) {
|
||||
frameworks.forEach {
|
||||
val konanTarget = it.target.konanTarget
|
||||
val konanTarget = it.konanTarget
|
||||
val arch = konanTarget.architecture
|
||||
require(konanTarget.family == Family.IOS) {
|
||||
"Cannot add a framework with target '${konanTarget.visibleName}' to the fat framework: " +
|
||||
@@ -165,14 +165,14 @@ open class FatFrameworkTask: DefaultTask() {
|
||||
}
|
||||
|
||||
private val Framework.plistPlatform: String
|
||||
get() = when(target.konanTarget) {
|
||||
get() = when(konanTarget) {
|
||||
KonanTarget.IOS_ARM32, KonanTarget.IOS_ARM64 -> "iPhoneOS"
|
||||
KonanTarget.IOS_X64 -> "iPhoneSimulator"
|
||||
KonanTarget.TVOS_ARM64 -> "appletvos"
|
||||
KonanTarget.TVOS_X64 -> "appletvsimulator"
|
||||
KonanTarget.WATCHOS_ARM32, KonanTarget.WATCHOS_ARM64 -> "watchos"
|
||||
KonanTarget.WATCHOS_X86, KonanTarget.WATCHOS_X64 -> "watchsimulator"
|
||||
else -> error("Fat frameworks are not supported for target `${target.konanTarget.visibleName}`")
|
||||
else -> error("Fat frameworks are not supported for target `${konanTarget.visibleName}`")
|
||||
}
|
||||
|
||||
// Runs the PlistBuddy utility with the given commands to configure the given plist file.
|
||||
|
||||
+3
-3
@@ -118,7 +118,7 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions> : Abstra
|
||||
}
|
||||
|
||||
val target: String
|
||||
@Input get() = compilation.target.konanTarget.name
|
||||
@Input get() = compilation.konanTarget.name
|
||||
|
||||
// region Compiler options.
|
||||
@get:Internal
|
||||
@@ -148,7 +148,7 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions> : Abstra
|
||||
// OutputFile is located under the destinationDir, so there is no need to register it as a separate output.
|
||||
@Internal
|
||||
val outputFile: Provider<File> = project.provider {
|
||||
val konanTarget = compilation.target.konanTarget
|
||||
val konanTarget = compilation.konanTarget
|
||||
|
||||
val prefix = outputKind.prefix(konanTarget)
|
||||
val suffix = outputKind.suffix(konanTarget)
|
||||
@@ -614,7 +614,7 @@ open class CInteropProcess : DefaultTask() {
|
||||
lateinit var destinationDir: Provider<File>
|
||||
|
||||
val konanTarget: KonanTarget
|
||||
@Internal get() = settings.compilation.target.konanTarget
|
||||
@Internal get() = settings.compilation.konanTarget
|
||||
|
||||
val interopName: String
|
||||
@Internal get() = settings.name
|
||||
|
||||
Reference in New Issue
Block a user