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")
|
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 |
|
73193
|
36 |
def standard_platform(platform: Family.Value): String =
|
|
37 |
platform match {
|
|
38 |
case Platform.Family.linux => "x86_64-linux"
|
|
39 |
case Platform.Family.macos => "x86_64-darwin"
|
|
40 |
case Platform.Family.windows => "x86_64-cygwin"
|
|
41 |
}
|
|
42 |
|
31828
|
43 |
|
69112
|
44 |
/* platform identifiers */
|
31828
|
45 |
|
69112
|
46 |
private val X86 = """i.86|x86""".r
|
|
47 |
private val X86_64 = """amd64|x86_64""".r
|
72344
|
48 |
private val Arm64 = """arm64|aarch64""".r
|
72370
|
49 |
private val Arm32 = """arm""".r
|
31825
|
50 |
|
69726
|
51 |
def cpu_arch: String =
|
|
52 |
System.getProperty("os.arch", "") match {
|
|
53 |
case X86() => "x86"
|
|
54 |
case X86_64() => "x86_64"
|
72344
|
55 |
case Arm64() => "arm64"
|
72370
|
56 |
case Arm32() => "arm32"
|
69726
|
57 |
case _ => error("Failed to determine CPU architecture")
|
|
58 |
}
|
|
59 |
|
|
60 |
def os_name: String =
|
|
61 |
family match {
|
|
62 |
case Family.macos => "darwin"
|
|
63 |
case _ => family.toString
|
|
64 |
}
|
|
65 |
|
|
66 |
lazy val jvm_platform: String = cpu_arch + "-" + os_name
|
31828
|
67 |
|
|
68 |
|
61001
|
69 |
/* JVM version */
|
|
70 |
|
69112
|
71 |
private val Version = """1\.(\d+)\.0_(\d+)""".r
|
71383
|
72 |
lazy val jvm_version: String =
|
61001
|
73 |
System.getProperty("java.version") match {
|
|
74 |
case Version(a, b) => a + "u" + b
|
|
75 |
case a => a
|
|
76 |
}
|
|
77 |
|
|
78 |
|
41381
|
79 |
/* JVM name */
|
|
80 |
|
53582
|
81 |
val jvm_name: String = System.getProperty("java.vm.name", "")
|
31825
|
82 |
}
|