author | wenzelm |
Sat, 27 Jan 2024 22:15:40 +0100 | |
changeset 79536 | d39976404aa7 |
parent 78610 | fd1fec53665b |
child 79981 | bdea4eccd8d5 |
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 |
|
75393 | 10 |
object Platform { |
69112 | 11 |
/* platform family */ |
31828 | 12 |
|
73906 | 13 |
val is_windows: Boolean = isabelle.setup.Environment.is_windows() |
71383 | 14 |
val is_linux: Boolean = System.getProperty("os.name", "") == "Linux" |
15 |
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:
73193
diff
changeset
|
16 |
val is_unix: Boolean = is_linux || is_macos |
31825 | 17 |
|
73637 | 18 |
def is_arm: Boolean = cpu_arch.startsWith("arm") |
19 |
||
78610 | 20 |
def family: Family = |
73637 | 21 |
if (is_linux && is_arm) Family.linux_arm |
22 |
else if (is_linux) Family.linux |
|
69410 | 23 |
else if (is_macos) Family.macos |
24 |
else if (is_windows) Family.windows |
|
25 |
else error("Failed to determine current platform family") |
|
26 |
||
78610 | 27 |
object Family { |
28 |
val list: List[Family] = List(Family.linux, Family.linux_arm, Family.windows, Family.macos) |
|
69410 | 29 |
|
78610 | 30 |
def unapply(name: String): Option[Family] = |
31 |
try { Some(Family.valueOf(name)) } |
|
32 |
catch { case _: IllegalArgumentException => None } |
|
69410 | 33 |
|
78610 | 34 |
def parse(name: String): Family = |
69410 | 35 |
unapply(name) getOrElse error("Bad platform family: " + quote(name)) |
73637 | 36 |
|
78610 | 37 |
val standard: Family => String = |
38 |
{ |
|
39 |
case Family.linux_arm => "arm64-linux" |
|
40 |
case Family.linux => "x86_64-linux" |
|
41 |
case Family.macos => "x86_64-darwin" |
|
42 |
case Family.windows => "x86_64-cygwin" |
|
43 |
} |
|
75083 | 44 |
|
78610 | 45 |
val native: Family => String = |
46 |
{ |
|
47 |
case Family.macos => "arm64-darwin" |
|
48 |
case Family.windows => "x86_64-windows" |
|
49 |
case platform => standard(platform) |
|
50 |
} |
|
69410 | 51 |
} |
52 |
||
78610 | 53 |
enum Family { case linux_arm, linux, macos, windows } |
54 |
||
31828 | 55 |
|
69112 | 56 |
/* platform identifiers */ |
31828 | 57 |
|
69112 | 58 |
private val X86_64 = """amd64|x86_64""".r |
72344 | 59 |
private val Arm64 = """arm64|aarch64""".r |
31825 | 60 |
|
69726 | 61 |
def cpu_arch: String = |
62 |
System.getProperty("os.arch", "") match { |
|
63 |
case X86_64() => "x86_64" |
|
72344 | 64 |
case Arm64() => "arm64" |
69726 | 65 |
case _ => error("Failed to determine CPU architecture") |
66 |
} |
|
67 |
||
68 |
def os_name: String = |
|
69 |
family match { |
|
73639
e1432539df35
proper jvm_platform, notably for org.sqlite.lib.path;
wenzelm
parents:
73638
diff
changeset
|
70 |
case Family.linux_arm => "linux" |
69726 | 71 |
case Family.macos => "darwin" |
72 |
case _ => family.toString |
|
73 |
} |
|
74 |
||
75 |
lazy val jvm_platform: String = cpu_arch + "-" + os_name |
|
31828 | 76 |
|
77 |
||
61001 | 78 |
/* JVM version */ |
79 |
||
69112 | 80 |
private val Version = """1\.(\d+)\.0_(\d+)""".r |
71383 | 81 |
lazy val jvm_version: String = |
61001 | 82 |
System.getProperty("java.version") match { |
83 |
case Version(a, b) => a + "u" + b |
|
84 |
case a => a |
|
85 |
} |
|
86 |
||
87 |
||
41381 | 88 |
/* JVM name */ |
89 |
||
53582 | 90 |
val jvm_name: String = System.getProperty("java.vm.name", "") |
31825 | 91 |
} |