src/Pure/System/isabelle_platform.scala
author wenzelm
Fri, 01 Apr 2022 17:06:10 +0200
changeset 75393 87ebf5a50283
parent 73716 00ef0f401a29
child 77328 f30e050d4ac6
permissions -rw-r--r--
clarified formatting, for the sake of scala3;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/System/isabelle_platform.scala
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     3
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     4
General hardware and operating system type for Isabelle system tools.
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     5
*/
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     6
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     7
package isabelle
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     8
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
     9
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73716
diff changeset
    10
object Isabelle_Platform {
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    11
  val settings: List[String] =
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    12
    List(
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    13
      "ISABELLE_PLATFORM_FAMILY",
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    14
      "ISABELLE_PLATFORM64",
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    15
      "ISABELLE_WINDOWS_PLATFORM32",
73667
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    16
      "ISABELLE_WINDOWS_PLATFORM64",
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    17
      "ISABELLE_APPLE_PLATFORM64")
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    18
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73716
diff changeset
    19
  def apply(ssh: Option[SSH.Session] = None): Isabelle_Platform = {
72340
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    20
    ssh match {
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    21
      case None =>
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    22
        new Isabelle_Platform(settings.map(a => (a, Isabelle_System.getenv(a))))
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    23
      case Some(ssh) =>
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    24
        val script =
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    25
          File.read(Path.explode("~~/lib/scripts/isabelle-platform")) + "\n" +
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    26
            settings.map(a => "echo \"" + Bash.string(a) + "=$" + Bash.string(a) + "\"").mkString("\n")
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    27
        val result = ssh.execute("bash -c " + Bash.string(script)).check
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    28
        new Isabelle_Platform(
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    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
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    31
    }
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    32
  }
72349
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    33
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    34
  lazy val self: Isabelle_Platform = apply()
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    35
}
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    36
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73716
diff changeset
    37
class Isabelle_Platform private(val settings: List[(String, String)]) {
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    38
  private def get(name: String): String =
72339
626920749f5d tuned signature;
wenzelm
parents: 72338
diff changeset
    39
    settings.collectFirst({ case (a, b) if a == name => b }).
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    40
      getOrElse(error("Bad platform settings variable: " + quote(name)))
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    41
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    42
  val ISABELLE_PLATFORM_FAMILY: String = get("ISABELLE_PLATFORM_FAMILY")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    43
  val ISABELLE_PLATFORM64: String = get("ISABELLE_PLATFORM64")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    44
  val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64")
73667
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    45
  val ISABELLE_APPLE_PLATFORM64: String = get("ISABELLE_APPLE_PLATFORM64")
72349
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    46
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    47
  def is_arm: Boolean =
73667
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    48
    ISABELLE_PLATFORM64.startsWith("arm64-") ||
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    49
    ISABELLE_APPLE_PLATFORM64.startsWith("arm64-")
72349
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    50
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    51
  def is_linux: Boolean = ISABELLE_PLATFORM_FAMILY == "linux"
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    52
  def is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos"
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    53
  def is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows"
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    54
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72349
diff changeset
    55
  def arch_64: String = if (is_arm) "arm64" else "x86_64"
73667
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    56
  def arch_64_32: String = if (is_arm) "arm64_32" else "x86_64_32"
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    57
72352
f4bd6f123fdf more systematic platform support, including arm64-linux;
wenzelm
parents: 72349
diff changeset
    58
  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
    59
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    60
  override def toString: String = ISABELLE_PLATFORM_FAMILY
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    61
}