Skip to content

Commit

Permalink
Add common native source set
Browse files Browse the repository at this point in the history
  • Loading branch information
mrapplexz committed May 17, 2020
1 parent 32ad676 commit 677a6d5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package net.pearx.multigradle.plugin

import net.pearx.multigradle.util.MultiGradleExtension
import net.pearx.multigradle.util.asBoolean
import net.pearx.multigradle.util.configureDokka
import net.pearx.multigradle.util.kotlinMpp
import net.pearx.multigradle.util.platform.PLATFORMS
Expand Down Expand Up @@ -87,7 +88,7 @@ private fun Project.postInit() {
}
}

if ((project.properties["multigradle.publishHostExclusivesOnly"] as? String)?.toBoolean() == true) {
if (project.properties["multigradle.publishHostExclusivesOnly"].asBoolean) {
kotlinMpp.targets.configureEach {
mavenPublication {
tasks.withType<AbstractPublishToMaven> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright © 2019-2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package net.pearx.multigradle.util

val ideaActive
get() = System.getProperty("idea.active") == "true"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright © 2019-2020, PearX Team
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package net.pearx.multigradle.util

val Any?.asBoolean
get() = (this as? String)?.toBoolean() == true
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

package net.pearx.multigradle.util.platform

import net.pearx.multigradle.util.ideaActive
import net.pearx.multigradle.util.kotlinMpp
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.konan.target.HostManager

val LinuxX64Platform = nativePlatform("linuxX64", true)
val LinuxArm64Platform = nativePlatform("linuxArm64")
val LinuxArm32HfpPlatform = nativePlatform("linuxArm32Hfp")
Expand All @@ -25,4 +31,36 @@ val WatchOsX86Platform = nativePlatform("watchosX86", true)
val MacOsX64Platform = nativePlatform("macosX64", true)
val MingwX64Platform = nativePlatform("mingwX64", true)
val MingwX86Platform = nativePlatform("mingwX86")
val Wasm32Platform = nativePlatform("wasm32")
val Wasm32Platform = nativePlatform("wasm32")

fun Project.setupNative() {
if (!extra.has("mgnative")) {
extra["mgnative"] = true

kotlinMpp {
if (ideaActive) { // hack. idea doesn't go well with common native source sets as good as gradle does.
targetFromPreset(presets[when {
HostManager.hostIsLinux -> "linuxX64"
HostManager.hostIsMac -> "macosX64"
HostManager.hostIsMingw -> "mingwX64"
else -> throw IllegalStateException("The host platform differs from Linux/macOS/Windows")
}], "native")
}
else {
sourceSets {
create("nativeMain")
create("nativeTest")
}
}
}
}
}

fun nativePlatform(name: String, test: Boolean = false) = platform(name, if (test) listOf("${name}Test") else listOf(), { PlatformConfig(it) }) {
kotlinMpp {
targetFromPreset(presets[name])
setupNative()
sourceSets["${name}Main"].dependsOn(sourceSets["nativeMain"])
sourceSets["${name}Test"].dependsOn(sourceSets["nativeTest"])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package net.pearx.multigradle.util.platform

import net.pearx.multigradle.util.MultiGradleExtension
import net.pearx.multigradle.util.kotlinMpp
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*

Expand Down Expand Up @@ -47,12 +46,6 @@ inline fun <T : PlatformConfig> platform(name: String, testTasks: List<String>,
}
}

fun nativePlatform(name: String, test: Boolean = false) = platform(name, if(test) listOf("${name}Test") else listOf(), { PlatformConfig(it) }) {
kotlinMpp {
targetFromPreset(presets[name])
}
}

val PLATFORMS = setOf(
JsPlatform,
JvmPlatform,
Expand Down

0 comments on commit 677a6d5

Please sign in to comment.