author | wenzelm |
Thu, 06 Dec 2018 14:25:27 +0100 | |
changeset 69410 | c071fcec4323 |
parent 69112 | 5b749aa452c6 |
child 69726 | 461f0615faa3 |
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 |
|
64493 | 14 |
val is_linux = System.getProperty("os.name", "") == "Linux" |
53582 | 15 |
val is_macos = System.getProperty("os.name", "") == "Mac OS X" |
16 |
val is_windows = System.getProperty("os.name", "").startsWith("Windows") |
|
31825 | 17 |
|
69410 | 18 |
def family: Family.Value = |
19 |
if (is_linux) Family.linux |
|
20 |
else if (is_macos) Family.macos |
|
21 |
else if (is_windows) Family.windows |
|
22 |
else error("Failed to determine current platform family") |
|
23 |
||
24 |
object Family extends Enumeration |
|
25 |
{ |
|
26 |
val linux, macos, windows = Value |
|
27 |
||
28 |
def unapply(name: String): Option[Value] = |
|
29 |
try { Some(withName(name)) } |
|
30 |
catch { case _: NoSuchElementException => None } |
|
31 |
||
32 |
def parse(name: String): Value = |
|
33 |
unapply(name) getOrElse error("Bad platform family: " + quote(name)) |
|
34 |
} |
|
35 |
||
31828 | 36 |
|
69112 | 37 |
/* platform identifiers */ |
31828 | 38 |
|
69112 | 39 |
private val Linux = """Linux""".r |
40 |
private val Darwin = """Mac OS X""".r |
|
41 |
private val Windows = """Windows.*""".r |
|
31825 | 42 |
|
69112 | 43 |
private val X86 = """i.86|x86""".r |
44 |
private val X86_64 = """amd64|x86_64""".r |
|
31825 | 45 |
|
36205
e86d9a10e982
check JVM platform at most once -- still non-strict to prevent potential failure during initialization of object Platform;
wenzelm
parents:
36195
diff
changeset
|
46 |
lazy val jvm_platform: String = |
31825 | 47 |
{ |
36195
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
48 |
val arch = |
53582 | 49 |
System.getProperty("os.arch", "") match { |
36195
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
50 |
case X86() => "x86" |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
51 |
case X86_64() => "x86_64" |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
52 |
case _ => error("Failed to determine CPU architecture") |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
53 |
} |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
54 |
val os = |
53582 | 55 |
System.getProperty("os.name", "") match { |
36195
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
56 |
case Linux() => "linux" |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
57 |
case Darwin() => "darwin" |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
58 |
case Windows() => "windows" |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
59 |
case _ => error("Failed to determine operating system platform") |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
60 |
} |
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
wenzelm
parents:
35002
diff
changeset
|
61 |
arch + "-" + os |
31825 | 62 |
} |
31828 | 63 |
|
64 |
||
61001 | 65 |
/* JVM version */ |
66 |
||
69112 | 67 |
private val Version = """1\.(\d+)\.0_(\d+)""".r |
61001 | 68 |
lazy val jvm_version = |
69 |
System.getProperty("java.version") match { |
|
70 |
case Version(a, b) => a + "u" + b |
|
71 |
case a => a |
|
72 |
} |
|
73 |
||
74 |
||
41381 | 75 |
/* JVM name */ |
76 |
||
53582 | 77 |
val jvm_name: String = System.getProperty("java.vm.name", "") |
31825 | 78 |
} |