From e9a9eeeb11b7efbe5930e284f9f963e70df80646 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Tue, 25 May 2021 23:23:38 +0200 Subject: [PATCH] Build: Use official gradle strings instead of hard-coding them. --- buildSrc/src/main/kotlin/JniUtils.kt | 31 +++++++++++++++------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/buildSrc/src/main/kotlin/JniUtils.kt b/buildSrc/src/main/kotlin/JniUtils.kt index 63e89b97..2933811a 100644 --- a/buildSrc/src/main/kotlin/JniUtils.kt +++ b/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"