2024-07-31 12:43:17 +03:00
|
|
|
import sbt.singleFileFinder
|
|
|
|
|
|
|
|
import java.io.File
|
|
|
|
|
2020-10-02 19:17:21 +03:00
|
|
|
object Platform {
|
|
|
|
|
2020-10-22 17:12:28 +03:00
|
|
|
/** Returns true if the build system is running on Windows.
|
2020-10-02 19:17:21 +03:00
|
|
|
*/
|
|
|
|
def isWindows: Boolean =
|
|
|
|
sys.props("os.name").toLowerCase().contains("windows")
|
|
|
|
|
2020-10-22 17:12:28 +03:00
|
|
|
/** Returns true if the build system is running on Linux.
|
2020-10-02 19:17:21 +03:00
|
|
|
*/
|
|
|
|
def isLinux: Boolean =
|
|
|
|
sys.props("os.name").toLowerCase().contains("linux")
|
|
|
|
|
2020-10-22 17:12:28 +03:00
|
|
|
/** Returns true if the build system is running on macOS.
|
2020-10-02 19:17:21 +03:00
|
|
|
*/
|
|
|
|
def isMacOS: Boolean =
|
|
|
|
sys.props("os.name").toLowerCase().contains("mac")
|
2023-03-01 11:53:29 +03:00
|
|
|
|
2023-12-05 13:24:02 +03:00
|
|
|
def isAmd64: Boolean = {
|
|
|
|
val arch = sys.props("os.arch").toLowerCase()
|
|
|
|
arch.contains("amd64") || arch.contains("x86_64")
|
|
|
|
}
|
|
|
|
|
|
|
|
def isArm64: Boolean =
|
|
|
|
sys.props("os.arch").toLowerCase().contains("aarch64")
|
|
|
|
|
2023-03-01 11:53:29 +03:00
|
|
|
/** Returns the dynamic library file name on the current platform.
|
|
|
|
*
|
|
|
|
* @param libraryName the library name
|
|
|
|
* @return the file name of provided library on the current platform
|
|
|
|
*/
|
|
|
|
def dynamicLibraryFileName(libraryName: String): String = {
|
|
|
|
if (isMacOS) s"lib$libraryName.dylib"
|
|
|
|
else if (isWindows) s"$libraryName.dll"
|
|
|
|
else if (isLinux) s"lib$libraryName.so"
|
|
|
|
else {
|
|
|
|
throw new RuntimeException(s"Unknown platform [${sys.props("os.name")}].")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns the executable file name on the current platform.
|
|
|
|
*
|
|
|
|
* @param name the executable name
|
|
|
|
* @return the file name of provided executable on the current platform
|
|
|
|
*/
|
|
|
|
def executableFileName(name: String): String = {
|
|
|
|
if (isWindows) s".\\$name.bat" else name
|
|
|
|
}
|
|
|
|
|
2024-07-31 12:43:17 +03:00
|
|
|
/** Returns the executable file on the current platform.
|
|
|
|
*
|
|
|
|
* @param file the generic executable path
|
|
|
|
* @return the file corresponding to the provided executable on the current platform
|
|
|
|
*/
|
|
|
|
def executableFile(file: File): String =
|
|
|
|
if (isWindows) {
|
|
|
|
val parent = file.getParentFile
|
|
|
|
if (parent == null) s".\\${file.getName}.bat"
|
|
|
|
else if (parent.isAbsolute)
|
|
|
|
new File(parent, s"${file.getName}.bat").getPath
|
|
|
|
else s".\\${parent.getPath}${file.getPath}.bat"
|
|
|
|
} else file.getPath
|
2020-10-02 19:17:21 +03:00
|
|
|
}
|