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

Support intermediate SourceSets #38

Closed
yshrsmz opened this issue Aug 24, 2020 · 2 comments · Fixed by #61
Closed

Support intermediate SourceSets #38

yshrsmz opened this issue Aug 24, 2020 · 2 comments · Fixed by #61
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@yshrsmz
Copy link
Owner

yshrsmz commented Aug 24, 2020

blocked by #36

related: #56

Kotlin 1.4.0 adds support for the hierarchical project structure.

So how can we support this?

kotlin {
  jvm()
  ios()
}

buildkonfig {

  defaultConfigs {
    buildConfigField 'STRING', 'commonField', 'commonValue'
  }

  targetConfigs {
    ios {
      buildConfigField 'STRING', 'iosField', 'iosValue'
    }
  }
}

Say I have a configuration above.
Currently, BuildKonfig does not generate an object for iosMain, simply ignore it as there's no target named ios. We need to declare iosX64 and iosArm64 in targetConfigs.

To generate objects for intermediate SourceSets, we need to check SourceSets' dependencies.

In BuildKonfigPlugin,

targets.filter { it.name != "metadata" }.forEach { target ->
    val name = "${target.name}Main"
    val sourceSetMain = sourceSets.getByName(name)

    // !!!!
    val dependentSourceSets = sourceSetMain.dependsOn.filter { it.name != "commonMain" }
    println(dependentSourceSets)

    val outDirMain = File(outputDirectory, name).also { it.mkdirs() }
    sourceSetMain.kotlin.srcDirs(outDirMain.toRelativeString(project.projectDir))
    outputDirectoryMap[TargetName(target.name, target.platformType.toKgqlPlatformType())] = outDirMain
}

If target is iosX64 and that is defined via ios(), this dependentSourceSets should have a iosMain SourceSets.

@yshrsmz yshrsmz added enhancement New feature or request help wanted Extra attention is needed labels Aug 24, 2020
@yshrsmz
Copy link
Owner Author

yshrsmz commented Aug 24, 2020

As it may take some time to resolve the issue, I am planning to release a version for Kotlin 1.4 without supporting this.

@yshrsmz
Copy link
Owner Author

yshrsmz commented Oct 9, 2021

kotlin {
    android()
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        testRuns["test"].executionTask.configure {
            useJUnit()
        }
    }
    js(IR) {
        browser()
    }
    js("node") {
        nodejs()
    }
    macosX64()
    linuxX64()
    mingwX64()
    ios()

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jvmMain by getting
        val jvmTest by getting

        val appMain by creating {
            dependsOn(commonMain)
        }

        val androidMain by getting {
            dependsOn(appMain)
        }

        val jsCommonMain by creating {
            dependsOn(commonMain)
        }
        val jsMain by getting {
            dependsOn(jsCommonMain)
        }
        val nodeMain by getting {
            dependsOn(jsCommonMain)
        }
        val jsTest by getting

        val desktopMain by creating {
            dependsOn(appMain)
        }
        val macosX64Main by getting {
            dependsOn(desktopMain)
        }
        val linuxX64Main by getting {
            dependsOn(desktopMain)
        }
        val mingwX64Main by getting {
            dependsOn(desktopMain)
        }
    }
}
target: android, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
compilation: debug, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation, task ':compileDebugKotlinAndroid', androidDebugClasses
compilation: defaultSourceSet: source set androidDebug, []
compilation: allKotlinSourceSets: [source set androidDebug, source set androidMain, source set commonMain, source set appMain]
------
compilation: release, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation, task ':compileReleaseKotlinAndroid', androidReleaseClasses
compilation: defaultSourceSet: source set androidRelease, []
compilation: allKotlinSourceSets: [source set androidRelease, source set androidMain, source set commonMain, source set appMain]
------
target: iosArm64, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget_Decorated
compilation: main, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation, task ':compileKotlinIosArm64', iosArm64MainKlibrary
compilation: defaultSourceSet: source set iosArm64Main, [source set commonMain, source set iosMain]
compilation: allKotlinSourceSets: [source set iosArm64Main, source set commonMain, source set iosMain]
------
target: iosX64, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTests_Decorated
compilation: main, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation, task ':compileKotlinIosX64', iosX64MainKlibrary
compilation: defaultSourceSet: source set iosX64Main, [source set commonMain, source set iosMain]
compilation: allKotlinSourceSets: [source set iosX64Main, source set commonMain, source set iosMain]
------
target: js, class org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget_Decorated
compilation: main, class org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation, task ':compileKotlinJs', jsMainClasses
compilation: defaultSourceSet: source set jsMain, [source set commonMain, source set jsCommonMain]
compilation: allKotlinSourceSets: [source set jsMain, source set commonMain, source set jsCommonMain]
------
target: jvm, class org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget_Decorated
compilation: main, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation, task ':compileKotlinJvm', jvmMainClasses
compilation: defaultSourceSet: source set jvmMain, [source set commonMain]
compilation: allKotlinSourceSets: [source set jvmMain, source set commonMain]
------
target: linuxX64, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests_Decorated
compilation: main, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation, task ':compileKotlinLinuxX64', linuxX64MainKlibrary
compilation: defaultSourceSet: source set linuxX64Main, [source set commonMain, source set desktopMain]
compilation: allKotlinSourceSets: [source set linuxX64Main, source set commonMain, source set desktopMain, source set appMain]
------
target: macosX64, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests_Decorated
compilation: main, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation, task ':compileKotlinMacosX64', macosX64MainKlibrary
compilation: defaultSourceSet: source set macosX64Main, [source set commonMain, source set desktopMain]
compilation: allKotlinSourceSets: [source set macosX64Main, source set commonMain, source set desktopMain, source set appMain]
------
target: metadata, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget_Decorated
compilation: appMain, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation, task ':compileAppMainKotlinMetadata', metadataAppMainClasses
compilation: defaultSourceSet: source set appMain, [source set commonMain]
compilation: allKotlinSourceSets: []
------
compilation: commonMain, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation, task ':compileCommonMainKotlinMetadata', metadataCommonMainClasses
compilation: defaultSourceSet: source set commonMain, []
compilation: allKotlinSourceSets: []
------
compilation: desktopMain, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation, task ':compileDesktopMainKotlinMetadata', metadataDesktopMainClasses
compilation: defaultSourceSet: source set desktopMain, [source set appMain]
compilation: allKotlinSourceSets: []
------
compilation: iosMain, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation, task ':compileIosMainKotlinMetadata', metadataIosMainClasses
compilation: defaultSourceSet: source set iosMain, [source set commonMain]
compilation: allKotlinSourceSets: []
------
compilation: main, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation, task ':compileKotlinMetadata', metadataMainClasses
compilation: defaultSourceSet: source set commonMain, []
compilation: allKotlinSourceSets: [source set commonMain]
------
target: mingwX64, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests_Decorated
compilation: main, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation, task ':compileKotlinMingwX64', mingwX64MainKlibrary
compilation: defaultSourceSet: source set mingwX64Main, [source set commonMain, source set desktopMain]
compilation: allKotlinSourceSets: [source set mingwX64Main, source set commonMain, source set desktopMain, source set appMain]
------
target: node, class org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget_Decorated
compilation: main, class org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation, task ':compileKotlinNode', nodeMainClasses
compilation: defaultSourceSet: source set nodeMain, [source set commonMain, source set jsCommonMain]
compilation: allKotlinSourceSets: [source set nodeMain, source set commonMain, source set jsCommonMain]
------

In this case, BuildKonfig should be created for each source sets.

Here's the source-set hierarchy.

- common
  - jvm
  - app
    - android
    - desktop
      - macosX64
      - linuxX64
      - mingwX64
  - jsCommon
    - js
    - node
  • Base actual declaration of BuildKonfig is always in common.
  • Expect declarations can be in any source set. but when you configure BuildKonfig for desktop, you can't create specific BuildKonfig for macos/linux/mingw. Upper source set always win.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant