src/Pure/System/isabelle_platform.scala
author wenzelm
Mon, 17 May 2021 14:54:03 +0200
changeset 73716 00ef0f401a29
parent 73671 7404f2e1d092
child 75393 87ebf5a50283
permissions -rw-r--r--
more uniform use of Properties.Eq.unapply, with slightly changed semantics in boundary cases;
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
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    10
object Isabelle_Platform
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    11
{
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    12
  val settings: List[String] =
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    13
    List(
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    14
      "ISABELLE_PLATFORM_FAMILY",
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    15
      "ISABELLE_PLATFORM64",
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    16
      "ISABELLE_WINDOWS_PLATFORM32",
73667
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    17
      "ISABELLE_WINDOWS_PLATFORM64",
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    18
      "ISABELLE_APPLE_PLATFORM64")
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    19
72340
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    20
  def apply(ssh: Option[SSH.Session] = None): Isabelle_Platform =
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    21
  {
72340
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    22
    ssh match {
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    23
      case None =>
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    24
        new Isabelle_Platform(settings.map(a => (a, Isabelle_System.getenv(a))))
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    25
      case Some(ssh) =>
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    26
        val script =
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    27
          File.read(Path.explode("~~/lib/scripts/isabelle-platform")) + "\n" +
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    28
            settings.map(a => "echo \"" + Bash.string(a) + "=$" + Bash.string(a) + "\"").mkString("\n")
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    29
        val result = ssh.execute("bash -c " + Bash.string(script)).check
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    30
        new Isabelle_Platform(
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    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
676066aa4798 clarified signature;
wenzelm
parents: 72339
diff changeset
    33
    }
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    34
  }
72349
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    35
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    36
  lazy val self: Isabelle_Platform = apply()
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    37
}
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    38
72339
626920749f5d tuned signature;
wenzelm
parents: 72338
diff changeset
    39
class Isabelle_Platform private(val settings: List[(String, String)])
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    40
{
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    41
  private def get(name: String): String =
72339
626920749f5d tuned signature;
wenzelm
parents: 72338
diff changeset
    42
    settings.collectFirst({ case (a, b) if a == name => b }).
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    43
      getOrElse(error("Bad platform settings variable: " + quote(name)))
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    44
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    45
  val ISABELLE_PLATFORM_FAMILY: String = get("ISABELLE_PLATFORM_FAMILY")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    46
  val ISABELLE_PLATFORM64: String = get("ISABELLE_PLATFORM64")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    47
  val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64")
73667
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    48
  val ISABELLE_APPLE_PLATFORM64: String = get("ISABELLE_APPLE_PLATFORM64")
72349
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    49
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    50
  def is_arm: Boolean =
73667
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    51
    ISABELLE_PLATFORM64.startsWith("arm64-") ||
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    52
    ISABELLE_APPLE_PLATFORM64.startsWith("arm64-")
72349
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    53
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    54
  def is_linux: Boolean = ISABELLE_PLATFORM_FAMILY == "linux"
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    55
  def is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos"
e7284278796b clarified signature;
wenzelm
parents: 72340
diff changeset
    56
  def is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows"
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    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
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    59
  def arch_64_32: String = if (is_arm) "arm64_32" else "x86_64_32"
442460fba2a4 clarified platforms;
wenzelm
parents: 72352
diff changeset
    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
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    63
  override def toString: String = ISABELLE_PLATFORM_FAMILY
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    64
}