src/Pure/System/isabelle_platform.scala
author wenzelm
Tue, 29 Sep 2020 19:49:25 +0200
changeset 72338 54871a086193
child 72339 626920749f5d
permissions -rw-r--r--
formal platform information, notably for ssh;
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_PLATFORM32",
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    16
      "ISABELLE_PLATFORM64",
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    17
      "ISABELLE_WINDOWS_PLATFORM32",
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    18
      "ISABELLE_WINDOWS_PLATFORM64")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    19
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    20
  def local(): Isabelle_Platform =
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    21
    new Isabelle_Platform(settings.map(a => (a, Isabelle_System.getenv(a))))
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    22
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    23
  def remote(ssh: SSH.Session): Isabelle_Platform =
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    24
  {
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    25
    val script =
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    26
      File.read(Path.explode("~~/lib/scripts/isabelle-platform")) + "\n" +
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    27
      settings.map(a => "echo \"" + Bash.string(a) + "=$" + Bash.string(a) + "\"").mkString("\n")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    28
    val result = ssh.execute("bash -c " + Bash.string(script)).check
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    29
    val values =
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    30
      result.out_lines.map(line =>
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    31
        space_explode('=', line) match {
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    32
          case List(a, b) => (a, b)
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    33
          case _ => error("Bad output: " + quote(result.out))
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    34
        })
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    35
    new Isabelle_Platform(values)
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    36
  }
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    37
}
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    38
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    39
class Isabelle_Platform private(values: List[(String, String)])
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 =
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    42
    values.collectFirst({ case (a, b) if a == name => b }).
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_PLATFORM32: String = get("ISABELLE_PLATFORM32")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    47
  val ISABELLE_PLATFORM64: String = get("ISABELLE_PLATFORM64")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    48
  val ISABELLE_WINDOWS_PLATFORM32: String = get("ISABELLE_WINDOWS_PLATFORM32")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    49
  val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    50
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    51
  val is_linux: Boolean = ISABELLE_PLATFORM_FAMILY == "linux"
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    52
  val is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos"
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    53
  val is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows"
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    54
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    55
  override def toString: String = ISABELLE_PLATFORM_FAMILY
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    56
}