2020-05-30 22:47:01 +02:00
|
|
|
import org.gradle.api.NamedDomainObjectContainer
|
2020-05-31 20:36:06 +02:00
|
|
|
import org.gradle.nativeplatform.platform.internal.Architectures
|
2020-06-07 17:18:41 +02:00
|
|
|
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
|
2020-05-30 22:47:01 +02:00
|
|
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
|
|
|
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
|
|
|
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
2020-06-10 19:09:01 +02:00
|
|
|
import java.io.File
|
2020-05-30 22:47:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Ugljesa Jovanovic
|
|
|
|
* ugljesa.jovanovic@ionspin.com
|
|
|
|
* on 30-May-2020
|
|
|
|
*/
|
|
|
|
fun isInIdea() = System.getProperty("idea.active") == "true"
|
|
|
|
|
|
|
|
fun isInTravis() = System.getenv("TRAVIS") == "true"
|
|
|
|
|
2020-06-10 19:09:01 +02:00
|
|
|
fun getProjectPath() : String {
|
|
|
|
val path = System.getProperty("PROJECT_PATH")
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
2020-05-30 22:47:01 +02:00
|
|
|
fun getHostOsName(): String {
|
|
|
|
val target = System.getProperty("os.name")
|
|
|
|
if (target == "Linux") return "linux"
|
|
|
|
if (target.startsWith("Windows")) return "windows"
|
|
|
|
if (target.startsWith("Mac")) return "macos"
|
|
|
|
return "unknown"
|
|
|
|
}
|
|
|
|
|
2020-05-31 20:36:06 +02:00
|
|
|
fun getHostArchitecture(): String {
|
2020-06-07 17:18:41 +02:00
|
|
|
val architecture = System.getProperty("os.arch")
|
2020-05-31 20:36:06 +02:00
|
|
|
DefaultNativePlatform.getCurrentArchitecture()
|
|
|
|
println("Arch: $architecture")
|
|
|
|
val resolvedArch = Architectures.forInput(architecture).name
|
|
|
|
println("Resolved arch: $resolvedArch")
|
|
|
|
return resolvedArch
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:18:41 +02:00
|
|
|
fun KotlinMultiplatformExtension.isRunningInIdea(block: KotlinMultiplatformExtension.() -> Unit) {
|
2020-05-30 22:47:01 +02:00
|
|
|
if (isInIdea()) {
|
|
|
|
block(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:18:41 +02:00
|
|
|
fun KotlinMultiplatformExtension.isNotRunningInIdea(block: KotlinMultiplatformExtension.() -> Unit) {
|
|
|
|
if (!isInIdea()) {
|
|
|
|
block(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 19:04:23 +02:00
|
|
|
fun KotlinMultiplatformExtension.isRunningInTravis(block: KotlinMultiplatformExtension.() -> Unit) {
|
|
|
|
if (isInTravis()) {
|
|
|
|
block(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:18:41 +02:00
|
|
|
fun KotlinMultiplatformExtension.runningOnLinuxx86_64(block: KotlinMultiplatformExtension.() -> Unit) {
|
2020-05-31 20:36:06 +02:00
|
|
|
if (getHostOsName() == "linux" && getHostArchitecture() == "x86-64") {
|
|
|
|
block(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:18:41 +02:00
|
|
|
fun KotlinMultiplatformExtension.runningOnLinuxArm64(block: KotlinMultiplatformExtension.() -> Unit) {
|
2020-05-31 21:08:35 +02:00
|
|
|
if (getHostOsName() == "linux" && getHostArchitecture() == "aarch64") {
|
2020-05-31 20:36:06 +02:00
|
|
|
block(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:18:41 +02:00
|
|
|
fun KotlinMultiplatformExtension.runningOnLinuxArm32(block: KotlinMultiplatformExtension.() -> Unit) {
|
2020-05-31 20:36:06 +02:00
|
|
|
if (getHostOsName() == "linux" && getHostArchitecture() == "arm-v7") {
|
2020-05-30 22:47:01 +02:00
|
|
|
block(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:18:41 +02:00
|
|
|
fun KotlinMultiplatformExtension.runningOnMacos(block: KotlinMultiplatformExtension.() -> Unit) {
|
2020-05-30 22:47:01 +02:00
|
|
|
if (getHostOsName() == "macos") {
|
|
|
|
block(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-07 17:18:41 +02:00
|
|
|
fun KotlinMultiplatformExtension.runningOnWindows(block: KotlinMultiplatformExtension.() -> Unit) {
|
2020-05-30 22:47:01 +02:00
|
|
|
if (getHostOsName() == "windows") {
|
|
|
|
block(this)
|
|
|
|
}
|
|
|
|
}
|
2020-06-07 17:18:41 +02:00
|
|
|
|
|
|
|
fun independentDependencyBlock(nativeDeps: KotlinDependencyHandler.() -> Unit): KotlinDependencyHandler.() -> Unit {
|
2020-05-30 22:47:01 +02:00
|
|
|
return nativeDeps
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On mac when two targets that have the same parent source set have cinterops defined, gradle creates a "common"
|
|
|
|
* target task for that source set metadata, even though it's a native source set, to work around that, we create
|
|
|
|
* an intermediary source set with the same set of dependancies
|
2020-06-01 13:11:06 +02:00
|
|
|
*
|
2020-05-30 22:47:01 +02:00
|
|
|
*/
|
2020-06-07 17:18:41 +02:00
|
|
|
fun NamedDomainObjectContainer<KotlinSourceSet>.createWorkaroundNativeMainSourceSet(
|
|
|
|
name: String,
|
|
|
|
nativeDeps: KotlinDependencyHandler.() -> Unit
|
|
|
|
): KotlinSourceSet {
|
|
|
|
|
2020-05-30 22:47:01 +02:00
|
|
|
return create("${name}Workaround") {
|
2020-06-07 17:18:41 +02:00
|
|
|
if (!isInIdea()) {
|
|
|
|
kotlin.srcDir("src/nativeMain")
|
|
|
|
dependencies {
|
|
|
|
nativeDeps.invoke(this)
|
|
|
|
}
|
2020-05-30 22:47:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|