Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for composite builds #19

Merged
merged 5 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies {
compileOnly(libs.gradle.android)
}

signing {
useGpgCmd()
if (!findProperty("VERSION_NAME")!!.toString().endsWith("SNAPSHOT")) {
signing {
useGpgCmd()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public class CommonContainer internal constructor(): Container.ConfigurableTarge
@JvmSynthetic
internal override fun setup(kotlin: KotlinMultiplatformExtension) {
with(kotlin.sourceSets) {
lazySourceSetMain?.execute(getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME))
lazySourceSetTest?.execute(getByName(KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME))
val commonMain = getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)
lazySourceSetMain.forEach { action -> action.execute(commonMain) }

val commonTest = getByName(KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME)
lazySourceSetTest.forEach { action -> action.execute(commonTest) }
}

// setup is only ever called if there is at least 1 target enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ public sealed class Container {
private val pluginIds: MutableSet<String> = mutableSetOf()
public fun pluginIds(vararg ids: String) { pluginIds += ids.toSet() }

protected var lazySourceSetMain: Action<KotlinSourceSet>? = null
private set
public fun sourceSetMain(action: Action<KotlinSourceSet>) { lazySourceSetMain = action }
protected val lazySourceSetMain: MutableList<Action<KotlinSourceSet>> = mutableListOf()
public fun sourceSetMain(action: Action<KotlinSourceSet>) { lazySourceSetMain.add(action) }

protected var lazySourceSetTest: Action<KotlinSourceSet>? = null
private set
public fun sourceSetTest(action: Action<KotlinSourceSet>) { lazySourceSetTest = action }
protected val lazySourceSetTest: MutableList<Action<KotlinSourceSet>> = mutableListOf()
public fun sourceSetTest(action: Action<KotlinSourceSet>) { lazySourceSetTest.add(action) }

protected fun applyPlugins(project: Project) {
for (id in pluginIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public class ContainerHolder private constructor(
}
}

@JvmSynthetic
internal fun findCommonContainer(): CommonContainer? {
return containers.filterIsInstance<CommonContainer>().firstOrNull()
}

@JvmSynthetic
internal fun findKotlinContainer(): KotlinExtensionActionContainer? {
return containers.filterIsInstance<KotlinExtensionActionContainer>().firstOrNull()
}

@JvmSynthetic
internal inline fun <reified T: KmpTarget<*>> find(targetName: String): T? {
return containers.filterIsInstance<T>().find { targetName == it.targetName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

internal class KotlinExtensionActionContainer internal constructor(): Container() {

private var lazyKotlin: Action<KotlinMultiplatformExtension>? = null
private val lazyKotlin = mutableListOf<Action<KotlinMultiplatformExtension>>()

@JvmSynthetic
internal fun kotlin(action: Action<KotlinMultiplatformExtension>) { lazyKotlin = action }
internal fun kotlin(action: Action<KotlinMultiplatformExtension>) { lazyKotlin.add(action) }

@JvmSynthetic
internal override fun setup(kotlin: KotlinMultiplatformExtension) {
lazyKotlin?.execute(kotlin)
lazyKotlin.forEach { action ->
action.execute(kotlin)
}
}

@JvmSynthetic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public class KmpConfigurationContainerDsl private constructor(
{

public fun common(action: Action<CommonContainer>) {
val container = CommonContainer()
val container = holder.findCommonContainer() ?: CommonContainer()
action.execute(container)
holder.add(container)
}

public fun kotlin(action: Action<KotlinMultiplatformExtension>) {
val container = KotlinExtensionActionContainer()
val container = holder.findKotlinContainer() ?: KotlinExtensionActionContainer()
container.kotlin(action)
holder.add(container)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ public sealed class KmpTarget<T: KotlinTarget> private constructor(
internal val targetName: String
): Container.ConfigurableTarget() {

protected var lazyTarget: Action<T>? = null
private set
public fun target(action: Action<T>) { lazyTarget = action }
protected val lazyTarget: MutableList<Action<T>> = mutableListOf()
public fun target(action: Action<T>) { lazyTarget.add(action) }

public sealed class Jvm<T: KotlinTarget>(targetName: String): KmpTarget<T>(targetName) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ public sealed class TargetAndroidContainer<T: TestedExtension> private construct
}
}

protected var lazyAndroid: Action<T>? = null
private set
public fun android(action: Action<T>) { lazyAndroid = action }
protected val lazyAndroid: MutableList<Action<T>> = mutableListOf()
public fun android(action: Action<T>) { lazyAndroid.add(action) }

private var lazySourceSetTestInstrumented: Action<KotlinSourceSet>? = null
public fun sourceSetTestInstrumented(action: Action<KotlinSourceSet>) { lazySourceSetTestInstrumented = action }
private val lazySourceSetTestInstrumented: MutableList<Action<KotlinSourceSet>> = mutableListOf()
public fun sourceSetTestInstrumented(action: Action<KotlinSourceSet>) { lazySourceSetTestInstrumented.add(action) }

@KmpConfigurationDsl
public class App internal constructor(
Expand All @@ -70,21 +69,19 @@ public sealed class TargetAndroidContainer<T: TestedExtension> private construct
): TargetAndroidContainer<BaseAppModuleExtension>(targetName, kotlinPluginVersion) {

protected override fun setupAndroid(project: Project) {
lazyAndroid?.let { action ->
project.extensions.configure(BaseAppModuleExtension::class.java) { extension ->
// Set before executing action so that they may be
// overridden if desired
extension.compileOptions {
compileSourceCompatibility?.let { compatibility ->
sourceCompatibility = compatibility
}
compileTargetCompatibility?.let { compatibility ->
targetCompatibility = compatibility
}
project.extensions.configure(BaseAppModuleExtension::class.java) { extension ->
// Set before executing action so that they may be
// overridden if desired
extension.compileOptions {
compileSourceCompatibility?.let { compatibility ->
sourceCompatibility = compatibility
}
compileTargetCompatibility?.let { compatibility ->
targetCompatibility = compatibility
}

action.execute(extension)
}

lazyAndroid.forEach { action -> action.execute(extension) }
}
}
}
Expand All @@ -96,21 +93,19 @@ public sealed class TargetAndroidContainer<T: TestedExtension> private construct
): TargetAndroidContainer<LibraryExtension>(targetName, kotlinPluginVersion) {

protected override fun setupAndroid(project: Project) {
lazyAndroid?.let { action ->
project.extensions.configure(LibraryExtension::class.java) { extension ->
// Set before executing action so that they may be
// overridden if desired
extension.compileOptions {
compileSourceCompatibility?.let { compatibility ->
sourceCompatibility = compatibility
}
compileTargetCompatibility?.let { compatibility ->
targetCompatibility = compatibility
}
project.extensions.configure(LibraryExtension::class.java) { extension ->
// Set before executing action so that they may be
// overridden if desired
extension.compileOptions {
compileSourceCompatibility?.let { compatibility ->
sourceCompatibility = compatibility
}
compileTargetCompatibility?.let { compatibility ->
targetCompatibility = compatibility
}

action.execute(extension)
}

lazyAndroid.forEach { action -> action.execute(extension) }
}
}
}
Expand All @@ -128,15 +123,15 @@ public sealed class TargetAndroidContainer<T: TestedExtension> private construct
}
}

lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})

applyPlugins(target.project)

with(sourceSets) {
getByName("${targetName}Main") { ss ->
ss.dependsOn(getByName("${JVM_ANDROID}Main"))
lazySourceSetMain?.execute(ss)
lazySourceSetMain.forEach { action -> action.execute(ss) }
}

val layoutVersion = if (kotlinPluginVersion.isAtLeast(1, 8)) {
Expand All @@ -161,11 +156,11 @@ public sealed class TargetAndroidContainer<T: TestedExtension> private construct

getByName(test) { ss ->
ss.dependsOn(jvmAndroidTest)
lazySourceSetTest?.execute(ss)
lazySourceSetTest.forEach { action -> action.execute(ss) }
}
getByName(instrumented) { ss ->
ss.dependsOn(jvmAndroidTest)
lazySourceSetTestInstrumented?.execute(ss)
lazySourceSetTestInstrumented.forEach { action -> action.execute(ss) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,22 @@ public sealed class TargetAndroidNativeContainer<T: KotlinNativeTarget> private
val target = when (this@TargetAndroidNativeContainer) {
is Arm32 -> {
androidNativeArm32(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
}
is Arm64 -> {
androidNativeArm64(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
}
is X64 -> {
androidNativeX64(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
}
is X86 -> {
androidNativeX86(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
}
}
Expand All @@ -136,11 +136,11 @@ public sealed class TargetAndroidNativeContainer<T: KotlinNativeTarget> private
with(sourceSets) {
getByName("${targetName}Main") { ss ->
ss.dependsOn(getByName("${ANDROID_NATIVE}Main"))
lazySourceSetMain?.execute(ss)
lazySourceSetMain.forEach { action -> action.execute(ss) }
}
getByName("${targetName}Test") { ss ->
ss.dependsOn(getByName("${ANDROID_NATIVE}Test"))
lazySourceSetTest?.execute(ss)
lazySourceSetTest.forEach { action -> action.execute(ss) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ public sealed class TargetIosContainer<T: KotlinNativeTarget> private constructo
val target = when (this@TargetIosContainer) {
is Arm32 -> {
iosArm32(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
}
is Arm64 -> {
iosArm64(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
}
is SimulatorArm64 -> {
iosSimulatorArm64(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
}
is X64 -> {
iosX64(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
}
}
Expand All @@ -137,11 +137,11 @@ public sealed class TargetIosContainer<T: KotlinNativeTarget> private constructo
with(sourceSets) {
getByName("${targetName}Main") { ss ->
ss.dependsOn(getByName("${IOS}Main"))
lazySourceSetMain?.execute(ss)
lazySourceSetMain.forEach { action -> action.execute(ss) }
}
getByName("${targetName}Test") { ss ->
ss.dependsOn(getByName("${IOS}Test"))
lazySourceSetTest?.execute(ss)
lazySourceSetTest.forEach { action -> action.execute(ss) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ public class TargetJsContainer internal constructor(
@Suppress("RedundantSamConstructor")
val target = compilerType?.let { type ->
js(targetName, type, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})
} ?: js(targetName, Action { t ->
lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }
})

applyPlugins(target.project)

with(sourceSets) {
getByName("${targetName}Main") { ss ->
ss.dependsOn(getByName("${NON_JVM}Main"))
lazySourceSetMain?.execute(ss)
lazySourceSetMain.forEach { action -> action.execute(ss) }
}
getByName("${targetName}Test") { ss ->
ss.dependsOn(getByName("${NON_JVM}Test"))
lazySourceSetTest?.execute(ss)
lazySourceSetTest.forEach { action -> action.execute(ss) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class TargetJvmContainer internal constructor(
}
}

lazyTarget?.execute(t)
lazyTarget.forEach { action -> action.execute(t) }

if (!t.withJavaEnabled) return@Action

Expand All @@ -77,11 +77,11 @@ public class TargetJvmContainer internal constructor(
with(sourceSets) {
getByName("${targetName}Main") { ss ->
ss.dependsOn(getByName("${JVM_ANDROID}Main"))
lazySourceSetMain?.execute(ss)
lazySourceSetMain.forEach { action -> action.execute(ss) }
}
getByName("${targetName}Test") { ss ->
ss.dependsOn(getByName("${JVM_ANDROID}Test"))
lazySourceSetTest?.execute(ss)
lazySourceSetTest.forEach { action -> action.execute(ss) }
}
}
}
Expand Down
Loading