author | wenzelm |
Mon, 17 May 2021 14:54:03 +0200 | |
changeset 73716 | 00ef0f401a29 |
parent 73671 | 7404f2e1d092 |
child 75393 | 87ebf5a50283 |
permissions | -rw-r--r-- |
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_PLATFORM64", |
|
16 |
"ISABELLE_WINDOWS_PLATFORM32", |
|
73667 | 17 |
"ISABELLE_WINDOWS_PLATFORM64", |
18 |
"ISABELLE_APPLE_PLATFORM64") |
|
72338 | 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 => |
|
73716
00ef0f401a29
more uniform use of Properties.Eq.unapply, with slightly changed semantics in boundary cases;
wenzelm
parents:
73671
diff
changeset
|
32 |
Properties.Eq.unapply(line) getOrElse error("Bad output: " + quote(result.out)))) |
72340 | 33 |
} |
72338 | 34 |
} |
72349 | 35 |
|
36 |
lazy val self: Isabelle_Platform = apply() |
|
72338 | 37 |
} |
38 |
||
72339 | 39 |
class Isabelle_Platform private(val settings: List[(String, String)]) |
72338 | 40 |
{ |
41 |
private def get(name: String): String = |
|
72339 | 42 |
settings.collectFirst({ case (a, b) if a == name => b }). |
72338 | 43 |
getOrElse(error("Bad platform settings variable: " + quote(name))) |
44 |
||
45 |
val ISABELLE_PLATFORM_FAMILY: String = get("ISABELLE_PLATFORM_FAMILY") |
|
46 |
val ISABELLE_PLATFORM64: String = get("ISABELLE_PLATFORM64") |
|
47 |
val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64") |
|
73667 | 48 |
val ISABELLE_APPLE_PLATFORM64: String = get("ISABELLE_APPLE_PLATFORM64") |
72349 | 49 |
|
50 |
def is_arm: Boolean = |
|
73667 | 51 |
ISABELLE_PLATFORM64.startsWith("arm64-") || |
52 |
ISABELLE_APPLE_PLATFORM64.startsWith("arm64-") |
|
72349 | 53 |
|
54 |
def is_linux: Boolean = ISABELLE_PLATFORM_FAMILY == "linux" |
|
55 |
def is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos" |
|
56 |
def is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows" |
|
72338 | 57 |
|
72352
f4bd6f123fdf
more systematic platform support, including arm64-linux;
wenzelm
parents:
72349
diff
changeset
|
58 |
def arch_64: String = if (is_arm) "arm64" else "x86_64" |
73667 | 59 |
def arch_64_32: String = if (is_arm) "arm64_32" else "x86_64_32" |
60 |
||
72352
f4bd6f123fdf
more systematic platform support, including arm64-linux;
wenzelm
parents:
72349
diff
changeset
|
61 |
def os_name: String = if (is_macos) "darwin" else ISABELLE_PLATFORM_FAMILY |
f4bd6f123fdf
more systematic platform support, including arm64-linux;
wenzelm
parents:
72349
diff
changeset
|
62 |
|
72338 | 63 |
override def toString: String = ISABELLE_PLATFORM_FAMILY |
64 |
} |