| author | wenzelm | 
| Fri, 20 Jan 2023 19:52:52 +0100 | |
| changeset 77028 | f5896dea6fce | 
| parent 75393 | 87ebf5a50283 | 
| child 77328 | f30e050d4ac6 | 
| 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: 
73671diff
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_PLATFORM_FAMILY: String = get("ISABELLE_PLATFORM_FAMILY")
 | |
| 43 |   val ISABELLE_PLATFORM64: String = get("ISABELLE_PLATFORM64")
 | |
| 44 |   val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64")
 | |
| 73667 | 45 |   val ISABELLE_APPLE_PLATFORM64: String = get("ISABELLE_APPLE_PLATFORM64")
 | 
| 72349 | 46 | |
| 47 | def is_arm: Boolean = | |
| 73667 | 48 |     ISABELLE_PLATFORM64.startsWith("arm64-") ||
 | 
| 49 |     ISABELLE_APPLE_PLATFORM64.startsWith("arm64-")
 | |
| 72349 | 50 | |
| 51 | def is_linux: Boolean = ISABELLE_PLATFORM_FAMILY == "linux" | |
| 52 | def is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos" | |
| 53 | def is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows" | |
| 72338 | 54 | |
| 72352 
f4bd6f123fdf
more systematic platform support, including arm64-linux;
 wenzelm parents: 
72349diff
changeset | 55 | def arch_64: String = if (is_arm) "arm64" else "x86_64" | 
| 73667 | 56 | def arch_64_32: String = if (is_arm) "arm64_32" else "x86_64_32" | 
| 57 | ||
| 72352 
f4bd6f123fdf
more systematic platform support, including arm64-linux;
 wenzelm parents: 
72349diff
changeset | 58 | def os_name: String = if (is_macos) "darwin" else ISABELLE_PLATFORM_FAMILY | 
| 
f4bd6f123fdf
more systematic platform support, including arm64-linux;
 wenzelm parents: 
72349diff
changeset | 59 | |
| 72338 | 60 | override def toString: String = ISABELLE_PLATFORM_FAMILY | 
| 61 | } |