author | wenzelm |
Thu, 22 Apr 2021 23:40:22 +0200 | |
changeset 73602 | 37243ad3ecb6 |
parent 73193 | b8e12e94cfca |
child 73637 | f3a356c64193 |
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 |
|
71383 | 14 |
val is_linux: Boolean = System.getProperty("os.name", "") == "Linux" |
15 |
val is_macos: Boolean = System.getProperty("os.name", "") == "Mac OS X" |
|
16 |
val is_windows: Boolean = System.getProperty("os.name", "").startsWith("Windows") |
|
73602
37243ad3ecb6
fast approximation of test for process group (NB: initial process might already be terminated, while background processes are still running);
wenzelm
parents:
73193
diff
changeset
|
17 |
val is_unix: Boolean = is_linux || is_macos |
31825 | 18 |
|
69410 | 19 |
def family: Family.Value = |
20 |
if (is_linux) Family.linux |
|
21 |
else if (is_macos) Family.macos |
|
22 |
else if (is_windows) Family.windows |
|
23 |
else error("Failed to determine current platform family") |
|
24 |
||
25 |
object Family extends Enumeration |
|
26 |
{ |
|
27 |
val linux, macos, windows = Value |
|
28 |
||
29 |
def unapply(name: String): Option[Value] = |
|
30 |
try { Some(withName(name)) } |
|
31 |
catch { case _: NoSuchElementException => None } |
|
32 |
||
33 |
def parse(name: String): Value = |
|
34 |
unapply(name) getOrElse error("Bad platform family: " + quote(name)) |
|
35 |
} |
|
36 |
||
73193 | 37 |
def standard_platform(platform: Family.Value): String = |
38 |
platform match { |
|
39 |
case Platform.Family.linux => "x86_64-linux" |
|
40 |
case Platform.Family.macos => "x86_64-darwin" |
|
41 |
case Platform.Family.windows => "x86_64-cygwin" |
|
42 |
} |
|
43 |
||
31828 | 44 |
|
69112 | 45 |
/* platform identifiers */ |
31828 | 46 |
|
69112 | 47 |
private val X86 = """i.86|x86""".r |
48 |
private val X86_64 = """amd64|x86_64""".r |
|
72344 | 49 |
private val Arm64 = """arm64|aarch64""".r |
72370 | 50 |
private val Arm32 = """arm""".r |
31825 | 51 |
|
69726 | 52 |
def cpu_arch: String = |
53 |
System.getProperty("os.arch", "") match { |
|
54 |
case X86() => "x86" |
|
55 |
case X86_64() => "x86_64" |
|
72344 | 56 |
case Arm64() => "arm64" |
72370 | 57 |
case Arm32() => "arm32" |
69726 | 58 |
case _ => error("Failed to determine CPU architecture") |
59 |
} |
|
60 |
||
61 |
def os_name: String = |
|
62 |
family match { |
|
63 |
case Family.macos => "darwin" |
|
64 |
case _ => family.toString |
|
65 |
} |
|
66 |
||
67 |
lazy val jvm_platform: String = cpu_arch + "-" + os_name |
|
31828 | 68 |
|
69 |
||
61001 | 70 |
/* JVM version */ |
71 |
||
69112 | 72 |
private val Version = """1\.(\d+)\.0_(\d+)""".r |
71383 | 73 |
lazy val jvm_version: String = |
61001 | 74 |
System.getProperty("java.version") match { |
75 |
case Version(a, b) => a + "u" + b |
|
76 |
case a => a |
|
77 |
} |
|
78 |
||
79 |
||
41381 | 80 |
/* JVM name */ |
81 |
||
53582 | 82 |
val jvm_name: String = System.getProperty("java.vm.name", "") |
31825 | 83 |
} |