author | wenzelm |
Tue, 30 Jan 2024 21:20:19 +0100 | |
changeset 79548 | a33a6e541cbb |
parent 77328 | f30e050d4ac6 |
child 79556 | 0631dfc0db07 |
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 |
||
75393 | 10 |
object Isabelle_Platform { |
72338 | 11 |
val settings: List[String] = |
12 |
List( |
|
13 |
"ISABELLE_PLATFORM_FAMILY", |
|
14 |
"ISABELLE_PLATFORM64", |
|
15 |
"ISABELLE_WINDOWS_PLATFORM32", |
|
73667 | 16 |
"ISABELLE_WINDOWS_PLATFORM64", |
17 |
"ISABELLE_APPLE_PLATFORM64") |
|
72338 | 18 |
|
75393 | 19 |
def apply(ssh: Option[SSH.Session] = None): Isabelle_Platform = { |
72340 | 20 |
ssh match { |
21 |
case None => |
|
22 |
new Isabelle_Platform(settings.map(a => (a, Isabelle_System.getenv(a)))) |
|
23 |
case Some(ssh) => |
|
24 |
val script = |
|
25 |
File.read(Path.explode("~~/lib/scripts/isabelle-platform")) + "\n" + |
|
26 |
settings.map(a => "echo \"" + Bash.string(a) + "=$" + Bash.string(a) + "\"").mkString("\n") |
|
27 |
val result = ssh.execute("bash -c " + Bash.string(script)).check |
|
28 |
new Isabelle_Platform( |
|
29 |
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
|
30 |
Properties.Eq.unapply(line) getOrElse error("Bad output: " + quote(result.out)))) |
72340 | 31 |
} |
72338 | 32 |
} |
72349 | 33 |
|
34 |
lazy val self: Isabelle_Platform = apply() |
|
72338 | 35 |
} |
36 |
||
75393 | 37 |
class Isabelle_Platform private(val settings: List[(String, String)]) { |
72338 | 38 |
private def get(name: String): String = |
72339 | 39 |
settings.collectFirst({ case (a, b) if a == name => b }). |
72338 | 40 |
getOrElse(error("Bad platform settings variable: " + quote(name))) |
41 |
||
42 |
val ISABELLE_PLATFORM64: String = get("ISABELLE_PLATFORM64") |
|
43 |
val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64") |
|
73667 | 44 |
val ISABELLE_APPLE_PLATFORM64: String = get("ISABELLE_APPLE_PLATFORM64") |
72349 | 45 |
|
46 |
def is_arm: Boolean = |
|
73667 | 47 |
ISABELLE_PLATFORM64.startsWith("arm64-") || |
48 |
ISABELLE_APPLE_PLATFORM64.startsWith("arm64-") |
|
72349 | 49 |
|
79548
a33a6e541cbb
proper ISABELLE_PLATFORM_FAMILY within Isabelle/Scala, in contrast to historic settings;
wenzelm
parents:
77328
diff
changeset
|
50 |
val ISABELLE_PLATFORM_FAMILY: String = { |
a33a6e541cbb
proper ISABELLE_PLATFORM_FAMILY within Isabelle/Scala, in contrast to historic settings;
wenzelm
parents:
77328
diff
changeset
|
51 |
val family0 = get("ISABELLE_PLATFORM_FAMILY") |
a33a6e541cbb
proper ISABELLE_PLATFORM_FAMILY within Isabelle/Scala, in contrast to historic settings;
wenzelm
parents:
77328
diff
changeset
|
52 |
if (family0 == "linux" && is_arm) "linux_arm" else family0 |
a33a6e541cbb
proper ISABELLE_PLATFORM_FAMILY within Isabelle/Scala, in contrast to historic settings;
wenzelm
parents:
77328
diff
changeset
|
53 |
} |
a33a6e541cbb
proper ISABELLE_PLATFORM_FAMILY within Isabelle/Scala, in contrast to historic settings;
wenzelm
parents:
77328
diff
changeset
|
54 |
|
77328 | 55 |
def is_linux: Boolean = |
56 |
ISABELLE_PLATFORM_FAMILY == "linux" || |
|
57 |
ISABELLE_PLATFORM_FAMILY == "linux_arm" |
|
72349 | 58 |
def is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos" |
59 |
def is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows" |
|
72338 | 60 |
|
72352
f4bd6f123fdf
more systematic platform support, including arm64-linux;
wenzelm
parents:
72349
diff
changeset
|
61 |
def arch_64: String = if (is_arm) "arm64" else "x86_64" |
73667 | 62 |
def arch_64_32: String = if (is_arm) "arm64_32" else "x86_64_32" |
63 |
||
72352
f4bd6f123fdf
more systematic platform support, including arm64-linux;
wenzelm
parents:
72349
diff
changeset
|
64 |
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
|
65 |
|
72338 | 66 |
override def toString: String = ISABELLE_PLATFORM_FAMILY |
67 |
} |