yshrsmz / BuildKonfig

BuildConfig for Kotlin Multiplatform Project
Apache License 2.0
729 stars 33 forks source link

Unable to detect shared ios SourceSet created by KMP plugin #146

Open yshrsmz opened 4 months ago

yshrsmz commented 4 months ago

Discussed in https://github.com/yshrsmz/BuildKonfig/discussions/145

Originally posted by **ronjunevaldoz** April 23, 2024 In the below config, only the android package contains `adMobBannerId` ``` kotlin buildkonfig { packageName = "com.example.app" defaultConfigs { buildConfigField(STRING, "oAuthServerId", "test") } defaultConfigs("dev") { buildConfigField(STRING, "oAuthServerId", "test") } targetConfigs { create("android") { buildConfigField(STRING, "adMobBannerId", "valueAndroid") } create("ios") { buildConfigField(STRING, "adMobBannerId", "valueIos") } } // flavor is passed as a first argument of targetConfigs targetConfigs("dev") { create("ios") { buildConfigField(STRING, "adMobBannerId", "ca") } create("android") { buildConfigField(STRING, "adMobBannerId", "ca") } } } ```
yshrsmz commented 4 months ago
afterEvaluate {
    println("afterEvaluate")
    val kmpExt = (this.kotlinExtension as KotlinMultiplatformExtension)
    kmpExt.targets.forEach {target->
        println("-------$target-------")
        target.compilations.filter { !it.name.endsWith(suffix = "Test", ignoreCase = true) }
            .filter { it.platformType == KotlinPlatformType.native }
            .forEach {compilation ->
                println("-------defaultSourceSet-------")
                println(compilation.defaultSourceSet.kotlin.sourceDirectories.forEach { println(it) })
                println("-------allKotlinSourceSets-------")
                println(compilation.allKotlinSourceSets.forEach { a -> a.kotlin.sourceDirectories.forEach { b-> println(b) } })
            }
    }
}

Above snippet prints the output below

afterEvaluate
-------target android (androidJvm)-------
-------target iosArm64 (native)-------
-------defaultSourceSet-------
/Users/yshrsmz/repos/buildkonfig-145/shared/src/iosArm64Main/kotlin
kotlin.Unit
-------allKotlinSourceSets-------
/Users/yshrsmz/repos/buildkonfig-145/shared/src/iosArm64Main/kotlin
kotlin.Unit
-------target iosSimulatorArm64 (native)-------
-------defaultSourceSet-------
/Users/yshrsmz/repos/buildkonfig-145/shared/src/iosSimulatorArm64Main/kotlin
kotlin.Unit
-------allKotlinSourceSets-------
/Users/yshrsmz/repos/buildkonfig-145/shared/src/iosSimulatorArm64Main/kotlin
kotlin.Unit
-------target iosX64 (native)-------
-------defaultSourceSet-------
/Users/yshrsmz/repos/buildkonfig-145/shared/src/iosX64Main/kotlin
kotlin.Unit
-------allKotlinSourceSets-------
/Users/yshrsmz/repos/buildkonfig-145/shared/src/iosX64Main/kotlin
kotlin.Unit
-------target metadata (common)-------

what is this kotlin.Unit ?