72338
|
1 |
/* Title: Pure/System/isabelle_platform.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
General hardware and operating system type for Isabelle system tools.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
object Isabelle_Platform
|
|
11 |
{
|
|
12 |
val settings: List[String] =
|
|
13 |
List(
|
|
14 |
"ISABELLE_PLATFORM_FAMILY",
|
|
15 |
"ISABELLE_PLATFORM32",
|
|
16 |
"ISABELLE_PLATFORM64",
|
|
17 |
"ISABELLE_WINDOWS_PLATFORM32",
|
|
18 |
"ISABELLE_WINDOWS_PLATFORM64")
|
|
19 |
|
72340
|
20 |
def apply(ssh: Option[SSH.Session] = None): Isabelle_Platform =
|
72338
|
21 |
{
|
72340
|
22 |
ssh match {
|
|
23 |
case None =>
|
|
24 |
new Isabelle_Platform(settings.map(a => (a, Isabelle_System.getenv(a))))
|
|
25 |
case Some(ssh) =>
|
|
26 |
val script =
|
|
27 |
File.read(Path.explode("~~/lib/scripts/isabelle-platform")) + "\n" +
|
|
28 |
settings.map(a => "echo \"" + Bash.string(a) + "=$" + Bash.string(a) + "\"").mkString("\n")
|
|
29 |
val result = ssh.execute("bash -c " + Bash.string(script)).check
|
|
30 |
new Isabelle_Platform(
|
|
31 |
result.out_lines.map(line =>
|
|
32 |
space_explode('=', line) match {
|
|
33 |
case List(a, b) => (a, b)
|
|
34 |
case _ => error("Bad output: " + quote(result.out))
|
|
35 |
}))
|
|
36 |
}
|
72338
|
37 |
}
|
72349
|
38 |
|
|
39 |
lazy val self: Isabelle_Platform = apply()
|
72338
|
40 |
}
|
|
41 |
|
72339
|
42 |
class Isabelle_Platform private(val settings: List[(String, String)])
|
72338
|
43 |
{
|
|
44 |
private def get(name: String): String =
|
72339
|
45 |
settings.collectFirst({ case (a, b) if a == name => b }).
|
72338
|
46 |
getOrElse(error("Bad platform settings variable: " + quote(name)))
|
|
47 |
|
|
48 |
val ISABELLE_PLATFORM_FAMILY: String = get("ISABELLE_PLATFORM_FAMILY")
|
|
49 |
val ISABELLE_PLATFORM32: String = get("ISABELLE_PLATFORM32")
|
|
50 |
val ISABELLE_PLATFORM64: String = get("ISABELLE_PLATFORM64")
|
|
51 |
val ISABELLE_WINDOWS_PLATFORM32: String = get("ISABELLE_WINDOWS_PLATFORM32")
|
|
52 |
val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64")
|
|
53 |
|
72349
|
54 |
def is_intel: Boolean =
|
|
55 |
ISABELLE_PLATFORM32.startsWith("x86-") ||
|
|
56 |
ISABELLE_PLATFORM64.startsWith("x86_64-")
|
|
57 |
|
|
58 |
def is_arm: Boolean =
|
|
59 |
ISABELLE_PLATFORM32.startsWith("arm32-") ||
|
|
60 |
ISABELLE_PLATFORM64.startsWith("arm64-")
|
|
61 |
|
|
62 |
def is_linux: Boolean = ISABELLE_PLATFORM_FAMILY == "linux"
|
|
63 |
def is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos"
|
|
64 |
def is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows"
|
72338
|
65 |
|
|
66 |
override def toString: String = ISABELLE_PLATFORM_FAMILY
|
|
67 |
}
|