| author | wenzelm | 
| Fri, 24 Sep 2021 22:23:26 +0200 | |
| changeset 74362 | 0135a0c77b64 | 
| parent 73906 | f627ffab387b | 
| child 75083 | 35a5c4b16024 | 
| permissions | -rw-r--r-- | 
| 31825 | 1 | /* Title: Pure/System/platform.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 69112 | 4 | System platform identification. | 
| 31825 | 5 | */ | 
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 31828 | 9 | |
| 31825 | 10 | object Platform | 
| 11 | {
 | |
| 69112 | 12 | /* platform family */ | 
| 31828 | 13 | |
| 73906 | 14 | val is_windows: Boolean = isabelle.setup.Environment.is_windows() | 
| 71383 | 15 |   val is_linux: Boolean = System.getProperty("os.name", "") == "Linux"
 | 
| 16 |   val is_macos: Boolean = System.getProperty("os.name", "") == "Mac OS X"
 | |
| 73602 
37243ad3ecb6
fast approximation of test for process group (NB: initial process might already be terminated, while background processes are still running);
 wenzelm parents: 
73193diff
changeset | 17 | val is_unix: Boolean = is_linux || is_macos | 
| 31825 | 18 | |
| 73637 | 19 |   def is_arm: Boolean = cpu_arch.startsWith("arm")
 | 
| 20 | ||
| 69410 | 21 | def family: Family.Value = | 
| 73637 | 22 | if (is_linux && is_arm) Family.linux_arm | 
| 23 | else if (is_linux) Family.linux | |
| 69410 | 24 | else if (is_macos) Family.macos | 
| 25 | else if (is_windows) Family.windows | |
| 26 |     else error("Failed to determine current platform family")
 | |
| 27 | ||
| 28 | object Family extends Enumeration | |
| 29 |   {
 | |
| 73637 | 30 | val linux_arm, linux, macos, windows = Value | 
| 73642 | 31 | val list0: List[Value] = List(linux, windows, macos) | 
| 73637 | 32 | val list: List[Value] = List(linux_arm, linux, windows, macos) | 
| 69410 | 33 | |
| 34 | def unapply(name: String): Option[Value] = | |
| 35 |       try { Some(withName(name)) }
 | |
| 36 |       catch { case _: NoSuchElementException => None }
 | |
| 37 | ||
| 38 | def parse(name: String): Value = | |
| 39 |       unapply(name) getOrElse error("Bad platform family: " + quote(name))
 | |
| 73637 | 40 | |
| 41 | def standard(platform: Value): String = | |
| 42 | if (platform == linux_arm) "arm64-linux" | |
| 43 | else if (platform == linux) "x86_64-linux" | |
| 44 | else if (platform == macos) "x86_64-darwin" | |
| 45 | else if (platform == windows) "x86_64-cygwin" | |
| 73638 | 46 |       else error("Bad platform family: " + quote(platform.toString))
 | 
| 69410 | 47 | } | 
| 48 | ||
| 31828 | 49 | |
| 69112 | 50 | /* platform identifiers */ | 
| 31828 | 51 | |
| 69112 | 52 | private val X86_64 = """amd64|x86_64""".r | 
| 72344 | 53 | private val Arm64 = """arm64|aarch64""".r | 
| 31825 | 54 | |
| 69726 | 55 | def cpu_arch: String = | 
| 56 |     System.getProperty("os.arch", "") match {
 | |
| 57 | case X86_64() => "x86_64" | |
| 72344 | 58 | case Arm64() => "arm64" | 
| 69726 | 59 |       case _ => error("Failed to determine CPU architecture")
 | 
| 60 | } | |
| 61 | ||
| 62 | def os_name: String = | |
| 63 |     family match {
 | |
| 73639 
e1432539df35
proper jvm_platform, notably for org.sqlite.lib.path;
 wenzelm parents: 
73638diff
changeset | 64 | case Family.linux_arm => "linux" | 
| 69726 | 65 | case Family.macos => "darwin" | 
| 66 | case _ => family.toString | |
| 67 | } | |
| 68 | ||
| 69 | lazy val jvm_platform: String = cpu_arch + "-" + os_name | |
| 31828 | 70 | |
| 71 | ||
| 61001 | 72 | /* JVM version */ | 
| 73 | ||
| 69112 | 74 | private val Version = """1\.(\d+)\.0_(\d+)""".r | 
| 71383 | 75 | lazy val jvm_version: String = | 
| 61001 | 76 |     System.getProperty("java.version") match {
 | 
| 77 | case Version(a, b) => a + "u" + b | |
| 78 | case a => a | |
| 79 | } | |
| 80 | ||
| 81 | ||
| 41381 | 82 | /* JVM name */ | 
| 83 | ||
| 53582 | 84 |   val jvm_name: String = System.getProperty("java.vm.name", "")
 | 
| 31825 | 85 | } |