[gradle-plugin] Support frameworks and extra options in the new plugin (#1800)
This commit is contained in:
+3
-3
@@ -48,9 +48,9 @@ interface KotlinNativeBinary: ComponentWithDependencies, BuildableComponent {
|
||||
val kind: CompilerOutputKind
|
||||
|
||||
/**
|
||||
* Additinal command line options passed to the compiler when this binary is compiled.
|
||||
* Additional command line options passed to the compiler when this binary is compiled.
|
||||
*/
|
||||
val additionalCompilerOptions: MutableCollection<String>
|
||||
val additionalCompilerOptions: Collection<String>
|
||||
|
||||
companion object {
|
||||
val KONAN_TARGET_ATTRIBUTE = Attribute.of("org.gradle.native.kotlin.platform", String::class.java)
|
||||
@@ -70,7 +70,7 @@ interface KotlinNativeExecutable : KotlinNativeBinary,
|
||||
* A component representing a klibrary.
|
||||
*/
|
||||
// TODO: Consider implementing ComponentWithLinkFile.
|
||||
interface KotlinNativeKLibrary : KotlinNativeBinary,
|
||||
interface KotlinNativeLibrary : KotlinNativeBinary,
|
||||
ComponentWithOutputs,
|
||||
PublishableComponent,
|
||||
ConfigurableComponentWithLinkUsage
|
||||
|
||||
+6
@@ -37,6 +37,12 @@ interface KotlinNativeComponent: ComponentWithBinaries, ComponentWithDependencie
|
||||
/** Set native targets for this component. */
|
||||
fun target(vararg targets: String)
|
||||
|
||||
/** Set additional compiler options for this component. */
|
||||
val extraOpts: Collection<String>
|
||||
|
||||
fun extraOpts(vararg values: Any)
|
||||
fun extraOpts(values: List<Any>)
|
||||
|
||||
// endregion
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -21,6 +21,7 @@ import org.gradle.nativeplatform.OperatingSystemFamily
|
||||
import org.gradle.nativeplatform.toolchain.NativeToolChain
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.ComponentWithBaseName
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeComponent
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.sourcesets.KotlinNativeSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
@@ -41,7 +42,7 @@ import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
abstract class AbstractKotlinNativeBinary(
|
||||
private val name: String,
|
||||
private val baseName: Provider<String>,
|
||||
val sourceSet: KotlinNativeSourceSet,
|
||||
val component: KotlinNativeComponent,
|
||||
val identity: KotlinNativeVariantIdentity,
|
||||
val projectLayout: ProjectLayout,
|
||||
override val kind: CompilerOutputKind,
|
||||
@@ -66,6 +67,9 @@ abstract class AbstractKotlinNativeBinary(
|
||||
|
||||
override fun getTargetPlatform(): KotlinNativePlatform = identity.targetPlatform
|
||||
|
||||
val sourceSet: KotlinNativeSourceSet
|
||||
get() = component.sources
|
||||
|
||||
open val debuggable: Boolean get() = identity.isDebuggable
|
||||
open val optimized: Boolean get() = identity.isOptimized
|
||||
|
||||
@@ -113,5 +117,6 @@ abstract class AbstractKotlinNativeBinary(
|
||||
private val outputs: ConfigurableFileCollection = fileOperations.files()
|
||||
override fun getOutputs() = outputs
|
||||
|
||||
override val additionalCompilerOptions = mutableListOf<String>()
|
||||
override val additionalCompilerOptions: Collection<String>
|
||||
get() = component.extraOpts
|
||||
}
|
||||
+7
@@ -59,5 +59,12 @@ abstract class AbstractKotlinNativeComponent @Inject constructor(
|
||||
konanTargets.set(targets.map { hostManager.targetByName(it) })
|
||||
}
|
||||
|
||||
override val extraOpts = mutableListOf<String>()
|
||||
|
||||
override fun extraOpts(vararg values: Any) = extraOpts(values.toList())
|
||||
override fun extraOpts(values: List<Any>) {
|
||||
extraOpts.addAll(values.map { it.toString() })
|
||||
}
|
||||
|
||||
// endregion
|
||||
}
|
||||
+2
-2
@@ -24,7 +24,7 @@ open class KotlinNativeExecutableImpl @Inject constructor(
|
||||
name: String,
|
||||
baseName: Provider<String>,
|
||||
componentImplementation: Configuration,
|
||||
sources: KotlinNativeSourceSet,
|
||||
component: KotlinNativeMainComponent,
|
||||
identity: KotlinNativeVariantIdentity,
|
||||
objects: ObjectFactory,
|
||||
projectLayout: ProjectLayout,
|
||||
@@ -32,7 +32,7 @@ open class KotlinNativeExecutableImpl @Inject constructor(
|
||||
fileOperations: FileOperations
|
||||
) : AbstractKotlinNativeBinary(name,
|
||||
baseName,
|
||||
sources,
|
||||
component,
|
||||
identity,
|
||||
projectLayout,
|
||||
CompilerOutputKind.PROGRAM,
|
||||
|
||||
+54
-7
@@ -15,32 +15,33 @@ import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.language.cpp.internal.DefaultUsageContext
|
||||
import org.gradle.nativeplatform.Linkage
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeKLibrary
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeLibrary
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.sourcesets.KotlinNativeSourceSet
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinNativeKLibraryImpl @Inject constructor(
|
||||
abstract class AbstractKotlinNativeLibrary(
|
||||
name: String,
|
||||
baseName: Provider<String>,
|
||||
componentImplementation: Configuration,
|
||||
sources: KotlinNativeSourceSet,
|
||||
component: KotlinNativeMainComponent,
|
||||
identity: KotlinNativeVariantIdentity,
|
||||
objects: ObjectFactory,
|
||||
projectLayout: ProjectLayout,
|
||||
outputKind: CompilerOutputKind,
|
||||
objects: ObjectFactory,
|
||||
configurations: ConfigurationContainer,
|
||||
fileOperations: FileOperations
|
||||
) : AbstractKotlinNativeBinary(name,
|
||||
baseName,
|
||||
sources,
|
||||
component,
|
||||
identity,
|
||||
projectLayout,
|
||||
CompilerOutputKind.LIBRARY,
|
||||
outputKind,
|
||||
objects,
|
||||
componentImplementation,
|
||||
configurations,
|
||||
fileOperations),
|
||||
KotlinNativeKLibrary,
|
||||
KotlinNativeLibrary,
|
||||
SoftwareComponentInternal, // TODO: SoftwareComponentInternal will be replaced with ComponentWithVariants by Gradle
|
||||
PublishableComponent
|
||||
{
|
||||
@@ -68,3 +69,49 @@ open class KotlinNativeKLibraryImpl @Inject constructor(
|
||||
|
||||
override val outputRootName = "lib"
|
||||
}
|
||||
|
||||
open class KotlinNativeLibraryImpl @Inject constructor(
|
||||
name: String,
|
||||
baseName: Provider<String>,
|
||||
componentImplementation: Configuration,
|
||||
component: KotlinNativeMainComponent,
|
||||
identity: KotlinNativeVariantIdentity,
|
||||
projectLayout: ProjectLayout,
|
||||
objects: ObjectFactory,
|
||||
configurations: ConfigurationContainer,
|
||||
fileOperations: FileOperations
|
||||
) : AbstractKotlinNativeLibrary(
|
||||
name,
|
||||
baseName,
|
||||
componentImplementation,
|
||||
component,
|
||||
identity,
|
||||
projectLayout,
|
||||
CompilerOutputKind.LIBRARY,
|
||||
objects,
|
||||
configurations,
|
||||
fileOperations
|
||||
)
|
||||
|
||||
open class KotlinNativeFrameworkImpl @Inject constructor(
|
||||
name: String,
|
||||
baseName: Provider<String>,
|
||||
componentImplementation: Configuration,
|
||||
component: KotlinNativeMainComponent,
|
||||
identity: KotlinNativeVariantIdentity,
|
||||
projectLayout: ProjectLayout,
|
||||
objects: ObjectFactory,
|
||||
configurations: ConfigurationContainer,
|
||||
fileOperations: FileOperations
|
||||
) : AbstractKotlinNativeLibrary(
|
||||
name,
|
||||
baseName,
|
||||
componentImplementation,
|
||||
component,
|
||||
identity,
|
||||
projectLayout,
|
||||
CompilerOutputKind.FRAMEWORK,
|
||||
objects,
|
||||
configurations,
|
||||
fileOperations
|
||||
)
|
||||
+6
-3
@@ -47,7 +47,7 @@ open class KotlinNativeMainComponent @Inject constructor(
|
||||
"$name${identity.name.capitalize()}",
|
||||
baseName,
|
||||
getImplementationDependencies(),
|
||||
sources,
|
||||
this,
|
||||
identity
|
||||
).apply {
|
||||
binaries.add(this)
|
||||
@@ -57,11 +57,11 @@ open class KotlinNativeMainComponent @Inject constructor(
|
||||
addBinary(T::class.java, identity)
|
||||
|
||||
fun addExecutable(identity: NativeVariantIdentity) = addBinary<KotlinNativeExecutableImpl>(identity)
|
||||
fun addKLibrary(identity: NativeVariantIdentity) = addBinary<KotlinNativeKLibraryImpl>(identity)
|
||||
fun addKLibrary(identity: NativeVariantIdentity) = addBinary<KotlinNativeLibraryImpl>(identity)
|
||||
fun addFramework(identity: NativeVariantIdentity) = addBinary<KotlinNativeFrameworkImpl>(identity)
|
||||
|
||||
fun addBinary(kind: OutputKind, identity: NativeVariantIdentity) = addBinary(kind.binaryClass, identity)
|
||||
|
||||
|
||||
// region Kotlin/Native variant
|
||||
// TODO: SoftwareComponentInternal will be replaced with ComponentWithVariants by Gradle
|
||||
inner class KotlinNativeVariant: ComponentWithVariants, SoftwareComponentInternal {
|
||||
@@ -82,5 +82,8 @@ open class KotlinNativeMainComponent @Inject constructor(
|
||||
|
||||
@JvmStatic
|
||||
val KLIBRARY = OutputKind.KLIBRARY
|
||||
|
||||
@JvmStatic
|
||||
val FRAMEWORK = OutputKind.FRAMEWORK
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -9,6 +9,7 @@ import org.gradle.api.internal.file.FileOperations
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeTestComponent
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeTestExecutable
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.sourcesets.KotlinNativeSourceSet
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
@@ -19,7 +20,7 @@ open class KotlinNativeTestExecutableImpl @Inject constructor(
|
||||
name: String,
|
||||
baseName: Provider<String>,
|
||||
componentImplementation: Configuration,
|
||||
testSources: KotlinNativeSourceSet,
|
||||
testComponent: KotlinNativeTestComponent,
|
||||
val mainSources: KotlinNativeSourceSet,
|
||||
identity: KotlinNativeVariantIdentity,
|
||||
objects: ObjectFactory,
|
||||
@@ -28,7 +29,7 @@ open class KotlinNativeTestExecutableImpl @Inject constructor(
|
||||
fileOperations: FileOperations
|
||||
) : AbstractKotlinNativeBinary(name,
|
||||
baseName,
|
||||
testSources,
|
||||
testComponent,
|
||||
identity,
|
||||
projectLayout,
|
||||
CompilerOutputKind.PROGRAM,
|
||||
@@ -38,15 +39,14 @@ open class KotlinNativeTestExecutableImpl @Inject constructor(
|
||||
fileOperations),
|
||||
KotlinNativeTestExecutable {
|
||||
|
||||
init {
|
||||
additionalCompilerOptions.add("-tr")
|
||||
}
|
||||
|
||||
private val runTaskProperty : Property<Task> = objects.property(Task::class.java)
|
||||
override fun getRunTask() = runTaskProperty
|
||||
|
||||
override val sources: FileCollection
|
||||
get() = super.sources + mainSources.getAllSources(konanTarget)
|
||||
|
||||
override val outputRootName: String = "exe"
|
||||
override val outputRootName: String = "test-exe"
|
||||
|
||||
override val additionalCompilerOptions: Collection<String>
|
||||
get() = listOf("-tr") + super.additionalCompilerOptions
|
||||
}
|
||||
+1
-1
@@ -38,7 +38,7 @@ open class KotlinNativeTestSuite @Inject constructor(
|
||||
"$name${identity.name.capitalize()}",
|
||||
getBaseName(),
|
||||
getImplementationDependencies(),
|
||||
sources,
|
||||
this,
|
||||
testedComponent.sources,
|
||||
identity
|
||||
).apply {
|
||||
|
||||
+1
@@ -2,4 +2,5 @@ package org.jetbrains.kotlin.gradle.plugin.experimental.internal
|
||||
|
||||
object KotlinNativeUsage {
|
||||
const val KLIB = "kotlin-native-klib"
|
||||
const val FRAMEWORK = "kotlin-native-framework"
|
||||
}
|
||||
|
||||
+31
-13
@@ -3,28 +3,46 @@ package org.jetbrains.kotlin.gradle.plugin.experimental.internal
|
||||
import org.gradle.api.attributes.Usage
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.KotlinNativeBinary
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
|
||||
enum class OutputKind(
|
||||
val compilerOutputKind: CompilerOutputKind,
|
||||
val binaryClass: Class<out KotlinNativeBinary>,
|
||||
private val developmentBinaryPriority: Int,
|
||||
val runtimeUsageName: String? = null,
|
||||
val linkUsageName: String? = null
|
||||
val linkUsageName: String? = null,
|
||||
val publishable: Boolean = true
|
||||
) {
|
||||
EXECUTABLE(CompilerOutputKind.PROGRAM,
|
||||
KotlinNativeExecutableImpl::class.java,
|
||||
1,
|
||||
Usage.NATIVE_RUNTIME,
|
||||
null
|
||||
EXECUTABLE(
|
||||
CompilerOutputKind.PROGRAM,
|
||||
KotlinNativeExecutableImpl::class.java,
|
||||
0,
|
||||
Usage.NATIVE_RUNTIME,
|
||||
null
|
||||
),
|
||||
KLIBRARY(CompilerOutputKind.LIBRARY,
|
||||
KotlinNativeKLibraryImpl::class.java,
|
||||
0,
|
||||
null,
|
||||
KotlinNativeUsage.KLIB
|
||||
);
|
||||
KLIBRARY(
|
||||
CompilerOutputKind.LIBRARY,
|
||||
KotlinNativeLibraryImpl::class.java,
|
||||
1,
|
||||
null,
|
||||
KotlinNativeUsage.KLIB
|
||||
),
|
||||
FRAMEWORK(
|
||||
CompilerOutputKind.FRAMEWORK,
|
||||
KotlinNativeFrameworkImpl::class.java,
|
||||
2,
|
||||
null,
|
||||
KotlinNativeUsage.FRAMEWORK,
|
||||
false
|
||||
) {
|
||||
override fun availableFor(target: KonanTarget) =
|
||||
target.family == Family.OSX || target.family == Family.IOS
|
||||
};
|
||||
|
||||
open fun availableFor(target: KonanTarget) = true
|
||||
|
||||
companion object {
|
||||
internal fun Collection<OutputKind>.getDevelopmentKind() = maxBy { it.developmentBinaryPriority }
|
||||
internal fun Collection<OutputKind>.getDevelopmentKind() = minBy { it.developmentBinaryPriority }
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -14,10 +14,7 @@ import org.gradle.language.plugins.NativeBasePlugin
|
||||
import org.gradle.nativeplatform.test.tasks.RunTestExecutable
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.KonanPlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.AbstractKotlinNativeBinary
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.KotlinNativeExecutableImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.KotlinNativeKLibraryImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.KotlinNativeTestExecutableImpl
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.internal.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.experimental.tasks.KotlinNativeCompile
|
||||
import org.jetbrains.kotlin.gradle.plugin.hasProperty
|
||||
import org.jetbrains.kotlin.gradle.plugin.konanCompilerDownloadDir
|
||||
@@ -94,7 +91,7 @@ class KotlinNativeBasePlugin: Plugin<ProjectInternal> {
|
||||
|
||||
when(binary) {
|
||||
is KotlinNativeExecutableImpl -> binary.runtimeFile.set(compileTask.outputFile)
|
||||
is KotlinNativeKLibraryImpl -> binary.linkFile.set(compileTask.outputFile)
|
||||
is AbstractKotlinNativeLibrary -> binary.linkFile.set(compileTask.outputFile)
|
||||
}
|
||||
|
||||
if (binary is KotlinNativeTestExecutableImpl) {
|
||||
|
||||
+9
-7
@@ -83,7 +83,7 @@ class KotlinNativePlugin @Inject constructor(val attributesFactory: ImmutableAtt
|
||||
|
||||
for (kind in outputKinds) {
|
||||
for (buildType in KotlinNativeBuildType.DEFAULT_BUILD_TYPES) {
|
||||
for (target in targets) {
|
||||
for (target in targets.filter { kind.availableFor(it) }) {
|
||||
|
||||
val buildTypeSuffix = buildType.name
|
||||
val outputKindSuffix = createDimensionSuffix(kind.name, outputKinds)
|
||||
@@ -112,12 +112,14 @@ class KotlinNativePlugin @Inject constructor(val attributesFactory: ImmutableAtt
|
||||
|
||||
val binary = component.addBinary(kind, variantIdentity)
|
||||
|
||||
if (hostManager.isEnabled(target)) {
|
||||
component.mainPublication.variants.add(binary)
|
||||
} else {
|
||||
// Known but not buildable.
|
||||
// It allows us to publish different parts of a multitarget library from differnt hosts.
|
||||
component.mainPublication.variants.add(variantIdentity)
|
||||
if (kind.publishable) {
|
||||
if (hostManager.isEnabled(target)) {
|
||||
component.mainPublication.variants.add(binary)
|
||||
} else {
|
||||
// Known but not buildable.
|
||||
// It allows us to publish different parts of a multitarget library from differnt hosts.
|
||||
component.mainPublication.variants.add(variantIdentity)
|
||||
}
|
||||
}
|
||||
|
||||
if (kind == developmentKind &&
|
||||
|
||||
+3
-1
@@ -39,6 +39,8 @@ open class KotlinNativeCompile: DefaultTask() {
|
||||
|
||||
val target: String @Input get() = binary.konanTarget.name
|
||||
|
||||
val additionalCompilerOptions: Collection<String> @Input get() = binary.additionalCompilerOptions
|
||||
|
||||
@OutputFile
|
||||
val outputFile: RegularFileProperty = newOutputFile()
|
||||
|
||||
@@ -60,7 +62,7 @@ open class KotlinNativeCompile: DefaultTask() {
|
||||
|
||||
add("-Xmulti-platform")
|
||||
|
||||
addAll(binary.additionalCompilerOptions)
|
||||
addAll(additionalCompilerOptions)
|
||||
|
||||
libraries.files.forEach {library ->
|
||||
library.parent?.let { addArg("-r", it) }
|
||||
|
||||
Reference in New Issue
Block a user