author | wenzelm |
Tue, 11 May 2021 13:06:36 +0200 | |
changeset 73667 | 442460fba2a4 |
parent 72352 | f4bd6f123fdf |
child 73671 | 7404f2e1d092 |
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_PLATFORM32", |
|
16 |
"ISABELLE_PLATFORM64", |
|
17 |
"ISABELLE_WINDOWS_PLATFORM32", |
|
73667 | 18 |
"ISABELLE_WINDOWS_PLATFORM64", |
19 |
"ISABELLE_APPLE_PLATFORM64") |
|
72338 | 20 |
|
72340 | 21 |
def apply(ssh: Option[SSH.Session] = None): Isabelle_Platform = |
72338 | 22 |
{ |
72340 | 23 |
ssh match { |
24 |
case None => |
|
25 |
new Isabelle_Platform(settings.map(a => (a, Isabelle_System.getenv(a)))) |
|
26 |
case Some(ssh) => |
|
27 |
val script = |
|
28 |
File.read(Path.explode("~~/lib/scripts/isabelle-platform")) + "\n" + |
|
29 |
settings.map(a => "echo \"" + Bash.string(a) + "=$" + Bash.string(a) + "\"").mkString("\n") |
|
30 |
val result = ssh.execute("bash -c " + Bash.string(script)).check |
|
31 |
new Isabelle_Platform( |
|
32 |
result.out_lines.map(line => |
|
33 |
space_explode('=', line) match { |
|
34 |
case List(a, b) => (a, b) |
|
35 |
case _ => error("Bad output: " + quote(result.out)) |
|
36 |
})) |
|
37 |
} |
|
72338 | 38 |
} |
72349 | 39 |
|
40 |
lazy val self: Isabelle_Platform = apply() |
|
72338 | 41 |
} |
42 |
||
72339 | 43 |
class Isabelle_Platform private(val settings: List[(String, String)]) |
72338 | 44 |
{ |
45 |
private def get(name: String): String = |
|
72339 | 46 |
settings.collectFirst({ case (a, b) if a == name => b }). |
72338 | 47 |
getOrElse(error("Bad platform settings variable: " + quote(name))) |
48 |
||
49 |
val ISABELLE_PLATFORM_FAMILY: String = get("ISABELLE_PLATFORM_FAMILY") |
|
50 |
val ISABELLE_PLATFORM64: String = get("ISABELLE_PLATFORM64") |
|
51 |
val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64") |
|
73667 | 52 |
val ISABELLE_APPLE_PLATFORM64: String = get("ISABELLE_APPLE_PLATFORM64") |
72349 | 53 |
|
54 |
def is_arm: Boolean = |
|
73667 | 55 |
ISABELLE_PLATFORM64.startsWith("arm64-") || |
56 |
ISABELLE_APPLE_PLATFORM64.startsWith("arm64-") |
|
72349 | 57 |
|
58 |
def is_linux: Boolean = ISABELLE_PLATFORM_FAMILY == "linux" |
|
59 |
def is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos" |
|
60 |
def is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows" |
|
72338 | 61 |
|
72352
f4bd6f123fdf
more systematic platform support, including arm64-linux;
wenzelm
parents:
72349
diff
changeset
|
62 |
def arch_64: String = if (is_arm) "arm64" else "x86_64" |
73667 | 63 |
def arch_64_32: String = if (is_arm) "arm64_32" else "x86_64_32" |
64 |
||
72352
f4bd6f123fdf
more systematic platform support, including arm64-linux;
wenzelm
parents:
72349
diff
changeset
|
65 |
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
|
66 |
|
72338 | 67 |
override def toString: String = ISABELLE_PLATFORM_FAMILY |
68 |
} |