Skip to content

Commit

Permalink
refactor: make kmp target configuration reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
aajtodd committed Aug 16, 2023
1 parent 9b5a3b7 commit 57640c4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,83 +58,80 @@ fun Project.configureKmpTargets() {
return
}

subprojects {
val subproject = this
subproject.pluginManager.withPlugin("kotlin-multiplatform") {
val kmpExt = subproject.extensions.findByType(kmpExtensionClass)
if (kmpExt == null) {
logger.info("$name: skipping KMP configuration because multiplatform plugin has not been configured properly")
return@withPlugin
}
pluginManager.withPlugin("kotlin-multiplatform") {
val kmpExt = extensions.findByType(kmpExtensionClass)
if (kmpExt == null) {
logger.info("$name: skipping KMP configuration because multiplatform plugin has not been configured properly")
return@withPlugin
}

// configure the target hierarchy, this does not actually enable the targets, just their relationships
// see https://kotlinlang.org/docs/multiplatform-hierarchy.html#see-the-full-hierarchy-template
kmpExt.targetHierarchy.default {
if (hasJvmAndNative) {
group("jvmAndNative") {
withJvm()
withNative()
}
// configure the target hierarchy, this does not actually enable the targets, just their relationships
// see https://kotlinlang.org/docs/multiplatform-hierarchy.html#see-the-full-hierarchy-template
kmpExt.targetHierarchy.default {
if (hasJvmAndNative) {
group("jvmAndNative") {
withJvm()
withNative()
}
}

if (hasWindows) {
group("windows") {
withMingw()
}
if (hasWindows) {
group("windows") {
withMingw()
}
}

if (hasDesktop) {
group("desktop") {
withLinux()
withMingw()
withMacos()
}
if (hasDesktop) {
group("desktop") {
withLinux()
withMingw()
withMacos()
}
}
}

// enable targets
configureCommon()

if (hasJvm) {
configureJvm()
}
// enable targets
configureCommon()

withIf(!COMMON_JVM_ONLY, kmpExt) {
if (hasJs) {
// FIXME - configure JS
js(KotlinJsCompilerType.IR) {
nodejs()
}
}
if (hasJvm) {
configureJvm()
}

if (hasApple) {
macosX64()
macosArm64()
ios()
watchos()
tvos()
withIf(!COMMON_JVM_ONLY, kmpExt) {
if (hasJs) {
// FIXME - configure JS
js(KotlinJsCompilerType.IR) {
nodejs()
}
}

if (hasLinux) {
linuxX64()
linuxArm64()
}
if (hasApple) {
macosX64()
macosArm64()
ios()
watchos()
tvos()
}

if (hasWindows) {
mingwX64()
}
if (hasLinux) {
linuxX64()
linuxArm64()
}

if (hasDesktop) {
linuxX64()
linuxArm64()
mingwX64()
macosX64()
macosArm64()
}
if (hasWindows) {
mingwX64()
}

kmpExt.configureSourceSetsConvention()
if (hasDesktop) {
linuxX64()
linuxArm64()
mingwX64()
macosX64()
macosArm64()
}
}

kmpExt.configureSourceSetsConvention()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class KmpDefaultsPlugin : Plugin<Project> {
with(target) {
logger.info("applying kmp defaults plugin to $target")
verifyRootProject { "AWS SDK KmpDefaultsPlugin requires installation into root project" }
configureKmpTargets()
subprojects {
val subproject = this
subproject.configureKmpTargets()
}
}
}
}

0 comments on commit 57640c4

Please sign in to comment.