Browse Source

Build: Use official gradle strings instead of hard-coding them.

pull/245/head
weisj 4 years ago
parent
commit
e9a9eeeb11
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 31
      buildSrc/src/main/kotlin/JniUtils.kt

31
buildSrc/src/main/kotlin/JniUtils.kt

@ -1,4 +1,5 @@
import dev.nokee.platform.jni.JniLibraryDependencies import dev.nokee.platform.jni.JniLibraryDependencies
import org.gradle.nativeplatform.MachineArchitecture
import dev.nokee.runtime.nativebase.OperatingSystemFamily import dev.nokee.runtime.nativebase.OperatingSystemFamily
import dev.nokee.runtime.nativebase.TargetMachine import dev.nokee.runtime.nativebase.TargetMachine
import org.gradle.api.Action import org.gradle.api.Action
@ -9,6 +10,8 @@ import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.ModuleDependencyCapabilitiesHandler import org.gradle.api.artifacts.ModuleDependencyCapabilitiesHandler
import org.gradle.api.provider.Provider import org.gradle.api.provider.Provider
typealias OSFamily = org.gradle.nativeplatform.OperatingSystemFamily
fun MinimalExternalModuleDependency.dependencyNotation() = fun MinimalExternalModuleDependency.dependencyNotation() =
"${module.group}:${module.name}:${versionConstraint.requiredVersion}" "${module.group}:${module.name}:${versionConstraint.requiredVersion}"
@ -32,31 +35,31 @@ fun ModuleDependencyCapabilitiesHandler.requireLibCapability(notation: Provider<
} }
val TargetMachine.variantName: String val TargetMachine.variantName: String
get() { get() = "$osFamily-$architectureString"
val osFamily = when {
operatingSystemFamily.isWindows -> "windows" val TargetMachine.osFamily: String
operatingSystemFamily.isLinux -> "linux" get() = when {
operatingSystemFamily.isMacOS -> "macos" operatingSystemFamily.isWindows -> OSFamily.WINDOWS
else -> GradleException("Unknown operating system family '${operatingSystemFamily}'.") operatingSystemFamily.isLinux -> OSFamily.LINUX
} operatingSystemFamily.isMacOS -> OSFamily.MACOS
return "$osFamily-$architectureString" else -> throw GradleException("Unknown operating system family '${operatingSystemFamily}'.")
} }
val TargetMachine.architectureString: String
get() = if (architecture.is32Bit) MachineArchitecture.X86 else MachineArchitecture.X86_64
val TargetMachine.targetsHost: Boolean val TargetMachine.targetsHost: Boolean
get() { get() {
val osName = System.getProperty("os.name").toLowerCase().replace(" ", "") val osName = System.getProperty("os.name").toLowerCase().replace(" ", "")
val osFamily = operatingSystemFamily val osFamily = operatingSystemFamily
return when { return when {
osFamily.isWindows && osName.contains("windows") -> true osFamily.isWindows && osName.contains(OSFamily.WINDOWS) -> true
osFamily.isLinux && osName.contains("linux") -> true osFamily.isLinux && osName.contains(OSFamily.LINUX) -> true
osFamily.isMacOS && osName.contains("macos") -> true osFamily.isMacOS && osName.contains(OSFamily.MACOS) -> true
else -> false else -> false
} }
} }
val TargetMachine.architectureString: String
get() = if (architecture.is32Bit) "x86" else "x86-64"
fun libraryFileNameFor(project: Project, osFamily: OperatingSystemFamily): String = when { fun libraryFileNameFor(project: Project, osFamily: OperatingSystemFamily): String = when {
osFamily.isWindows -> "${project.name}.dll" osFamily.isWindows -> "${project.name}.dll"
osFamily.isLinux -> "lib${project.name}.so" osFamily.isLinux -> "lib${project.name}.so"

Loading…
Cancel
Save