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 org.gradle.nativeplatform.MachineArchitecture
import dev.nokee.runtime.nativebase.OperatingSystemFamily
import dev.nokee.runtime.nativebase.TargetMachine
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.provider.Provider
typealias OSFamily = org.gradle.nativeplatform.OperatingSystemFamily
fun MinimalExternalModuleDependency.dependencyNotation() =
"${module.group}:${module.name}:${versionConstraint.requiredVersion}"
@ -32,31 +35,31 @@ fun ModuleDependencyCapabilitiesHandler.requireLibCapability(notation: Provider<
}
val TargetMachine.variantName: String
get() {
val osFamily = when {
operatingSystemFamily.isWindows -> "windows"
operatingSystemFamily.isLinux -> "linux"
operatingSystemFamily.isMacOS -> "macos"
else -> GradleException("Unknown operating system family '${operatingSystemFamily}'.")
}
return "$osFamily-$architectureString"
get() = "$osFamily-$architectureString"
val TargetMachine.osFamily: String
get() = when {
operatingSystemFamily.isWindows -> OSFamily.WINDOWS
operatingSystemFamily.isLinux -> OSFamily.LINUX
operatingSystemFamily.isMacOS -> OSFamily.MACOS
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
get() {
val osName = System.getProperty("os.name").toLowerCase().replace(" ", "")
val osFamily = operatingSystemFamily
return when {
osFamily.isWindows && osName.contains("windows") -> true
osFamily.isLinux && osName.contains("linux") -> true
osFamily.isMacOS && osName.contains("macos") -> true
osFamily.isWindows && osName.contains(OSFamily.WINDOWS) -> true
osFamily.isLinux && osName.contains(OSFamily.LINUX) -> true
osFamily.isMacOS && osName.contains(OSFamily.MACOS) -> true
else -> false
}
}
val TargetMachine.architectureString: String
get() = if (architecture.is32Bit) "x86" else "x86-64"
fun libraryFileNameFor(project: Project, osFamily: OperatingSystemFamily): String = when {
osFamily.isWindows -> "${project.name}.dll"
osFamily.isLinux -> "lib${project.name}.so"

Loading…
Cancel
Save