[gradle-plugin] Pass main linkerOpts to the test binary
This commit is contained in:
committed by
Ilya Matveev
parent
d6cef7ec21
commit
94e6c2a514
+1
-4
@@ -71,13 +71,10 @@ interface KotlinNativeBinary: ComponentWithDependencies, BuildableComponent {
|
|||||||
*/
|
*/
|
||||||
val additionalCompilerOptions: Collection<String>
|
val additionalCompilerOptions: Collection<String>
|
||||||
|
|
||||||
// DSL.
|
|
||||||
/**
|
/**
|
||||||
* Additional options passed to a linker when this binary is built.
|
* Additional options passed to a linker when this binary is built.
|
||||||
*/
|
*/
|
||||||
val linkerOpts: MutableList<String>
|
val linkerOpts: List<String>
|
||||||
fun linkerOpts(values: List<String>)
|
|
||||||
fun linkerOpts(vararg values: String)
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val KONAN_TARGET_ATTRIBUTE = Attribute.of("org.gradle.native.kotlin.platform", String::class.java)
|
val KONAN_TARGET_ATTRIBUTE = Attribute.of("org.gradle.native.kotlin.platform", String::class.java)
|
||||||
|
|||||||
+17
-3
@@ -39,6 +39,15 @@ interface KotlinNativeDependencies: ComponentDependencies {
|
|||||||
fun cinterop(name: String, action: Action<CInterop>)
|
fun cinterop(name: String, action: Action<CInterop>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TargetSettings {
|
||||||
|
/**
|
||||||
|
* Additional options passed to a linker when a binary is built.
|
||||||
|
*/
|
||||||
|
val linkerOpts: MutableList<String>
|
||||||
|
fun linkerOpts(values: List<String>)
|
||||||
|
fun linkerOpts(vararg values: String)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a Kotlin/Native component: application or library (both klib and dynamic)
|
* Class representing a Kotlin/Native component: application or library (both klib and dynamic)
|
||||||
* built for different targets.
|
* built for different targets.
|
||||||
@@ -77,10 +86,15 @@ interface KotlinNativeComponent: ComponentWithBinaries, ComponentWithDependencie
|
|||||||
@Deprecated("Use the 'targets' property instead. E.g. targets = ['macos_x64', 'linux_x64']")
|
@Deprecated("Use the 'targets' property instead. E.g. targets = ['macos_x64', 'linux_x64']")
|
||||||
fun target(vararg targets: String)
|
fun target(vararg targets: String)
|
||||||
|
|
||||||
/** Provide a way to configure binaries included in this component for a particular target. */
|
/** Allows providing target-specific compiler options. */
|
||||||
fun target(target: String, action: KotlinNativeBinary.() -> Unit)
|
fun target(target: String): TargetSettings
|
||||||
|
fun target(konanTarget: KonanTarget): TargetSettings
|
||||||
|
fun target(target: String, action: TargetSettings.() -> Unit)
|
||||||
fun target(target: String, action: Closure<Unit>)
|
fun target(target: String, action: Closure<Unit>)
|
||||||
fun target(target: String, action: Action<KotlinNativeBinary>)
|
fun target(target: String, action: Action<TargetSettings>)
|
||||||
|
fun allTargets(action: TargetSettings.() -> Unit)
|
||||||
|
fun allTargets(action: Closure<Unit>)
|
||||||
|
fun allTargets(action: Action<TargetSettings>)
|
||||||
|
|
||||||
/** Set additional compiler options for this component. */
|
/** Set additional compiler options for this component. */
|
||||||
val extraOpts: Collection<String>
|
val extraOpts: Collection<String>
|
||||||
|
|||||||
+2
-5
@@ -136,9 +136,6 @@ abstract class AbstractKotlinNativeBinary(
|
|||||||
override val additionalCompilerOptions: Collection<String>
|
override val additionalCompilerOptions: Collection<String>
|
||||||
get() = component.extraOpts
|
get() = component.extraOpts
|
||||||
|
|
||||||
override val linkerOpts = mutableListOf<String>()
|
override val linkerOpts: List<String>
|
||||||
override fun linkerOpts(values: List<String>) = linkerOpts(*values.toTypedArray())
|
get() = component.target(konanTarget).linkerOpts
|
||||||
override fun linkerOpts(vararg values: String) {
|
|
||||||
linkerOpts.addAll(values)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+29
-7
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.gradle.plugin.experimental.internal
|
|||||||
|
|
||||||
import groovy.lang.Closure
|
import groovy.lang.Closure
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
|
import org.gradle.api.Named
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.internal.file.FileOperations
|
import org.gradle.api.internal.file.FileOperations
|
||||||
@@ -33,12 +34,22 @@ import org.gradle.util.ConfigureUtil
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeComponent
|
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeComponent
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeDependencies
|
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeDependencies
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.experimental.TargetSettings
|
||||||
import org.jetbrains.kotlin.gradle.plugin.experimental.sourcesets.KotlinNativeSourceSetImpl
|
import org.jetbrains.kotlin.gradle.plugin.experimental.sourcesets.KotlinNativeSourceSetImpl
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.assertedCast
|
import org.jetbrains.kotlin.utils.addToStdlib.assertedCast
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class TargetSettingsImpl(val konanTarget: KonanTarget) : Named, TargetSettings {
|
||||||
|
override fun getName(): String = konanTarget.name
|
||||||
|
override val linkerOpts = mutableListOf<String>()
|
||||||
|
override fun linkerOpts(values: List<String>) = linkerOpts(*values.toTypedArray())
|
||||||
|
override fun linkerOpts(vararg values: String) {
|
||||||
|
linkerOpts.addAll(values)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abstract class AbstractKotlinNativeComponent @Inject constructor(
|
abstract class AbstractKotlinNativeComponent @Inject constructor(
|
||||||
private val name: String,
|
private val name: String,
|
||||||
override val sources: KotlinNativeSourceSetImpl,
|
override val sources: KotlinNativeSourceSetImpl,
|
||||||
@@ -77,6 +88,11 @@ abstract class AbstractKotlinNativeComponent @Inject constructor(
|
|||||||
|
|
||||||
override fun getImplementationDependencies(): Configuration = dependencies.implementationDependencies
|
override fun getImplementationDependencies(): Configuration = dependencies.implementationDependencies
|
||||||
|
|
||||||
|
val targetSettings =
|
||||||
|
project.container(TargetSettingsImpl::class.java) { name ->
|
||||||
|
TargetSettingsImpl(HostManager().targetByName(name))
|
||||||
|
}
|
||||||
|
|
||||||
// region DSL.
|
// region DSL.
|
||||||
|
|
||||||
override var targets: List<String>
|
override var targets: List<String>
|
||||||
@@ -86,19 +102,25 @@ abstract class AbstractKotlinNativeComponent @Inject constructor(
|
|||||||
konanTargets.set(value.map { hostManager.targetByName(it) })
|
konanTargets.set(value.map { hostManager.targetByName(it) })
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun target(target: String, action: KotlinNativeBinary.() -> Unit) =
|
private val String.canonicalTargetName: String
|
||||||
binaries.whenElementKnown {
|
get() = HostManager().targetByName(this).name
|
||||||
if (it.konanTarget == HostManager().targetByName(target)) {
|
|
||||||
it.action()
|
override fun target(konanTarget: KonanTarget): TargetSettings = targetSettings.maybeCreate(konanTarget.name)
|
||||||
}
|
override fun target(target: String): TargetSettings = targetSettings.maybeCreate(target.canonicalTargetName)
|
||||||
}
|
|
||||||
|
override fun target(target: String, action: TargetSettings.() -> Unit) =
|
||||||
|
targetSettings.maybeCreate(target.canonicalTargetName).action()
|
||||||
|
|
||||||
override fun target(target: String, action: Closure<Unit>) =
|
override fun target(target: String, action: Closure<Unit>) =
|
||||||
target(target, ConfigureUtil.configureUsing(action))
|
target(target, ConfigureUtil.configureUsing(action))
|
||||||
|
|
||||||
override fun target(target: String, action: Action<KotlinNativeBinary>) =
|
override fun target(target: String, action: Action<TargetSettings>) =
|
||||||
target(target) { action.execute(this) }
|
target(target) { action.execute(this) }
|
||||||
|
|
||||||
|
override fun allTargets(action: TargetSettings.() -> Unit) = targetSettings.all(action)
|
||||||
|
override fun allTargets(action: Closure<Unit>) = targetSettings.all(action)
|
||||||
|
override fun allTargets(action: Action<TargetSettings>) = targetSettings.all(action)
|
||||||
|
|
||||||
@Deprecated("Use the 'targets' property instead. E.g. targets = ['macos_x64', 'linux_x64']")
|
@Deprecated("Use the 'targets' property instead. E.g. targets = ['macos_x64', 'linux_x64']")
|
||||||
override fun target(vararg targets: String) {
|
override fun target(vararg targets: String) {
|
||||||
project.logger.warn("""
|
project.logger.warn("""
|
||||||
|
|||||||
+5
-2
@@ -35,7 +35,7 @@ open class KotlinNativeTestExecutableImpl @Inject constructor(
|
|||||||
name: String,
|
name: String,
|
||||||
baseName: Provider<String>,
|
baseName: Provider<String>,
|
||||||
componentImplementation: Configuration,
|
componentImplementation: Configuration,
|
||||||
testComponent: KotlinNativeTestSuite,
|
val testComponent: KotlinNativeTestSuite,
|
||||||
val mainSources: KotlinNativeSourceSet,
|
val mainSources: KotlinNativeSourceSet,
|
||||||
identity: KotlinNativeVariantIdentity,
|
identity: KotlinNativeVariantIdentity,
|
||||||
objects: ObjectFactory,
|
objects: ObjectFactory,
|
||||||
@@ -63,5 +63,8 @@ open class KotlinNativeTestExecutableImpl @Inject constructor(
|
|||||||
override val outputRootName: String = "test-exe"
|
override val outputRootName: String = "test-exe"
|
||||||
|
|
||||||
override val additionalCompilerOptions: Collection<String>
|
override val additionalCompilerOptions: Collection<String>
|
||||||
get() = listOf("-tr") + super.additionalCompilerOptions
|
get() = listOf("-tr") + super.additionalCompilerOptions
|
||||||
|
|
||||||
|
override val linkerOpts: List<String>
|
||||||
|
get() = super.linkerOpts + testComponent.testedComponent.target(konanTarget).linkerOpts
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user