src/Pure/System/isabelle_platform.scala
author wenzelm
Tue, 29 Sep 2020 19:54:59 +0200
changeset 72339 626920749f5d
parent 72338 54871a086193
child 72340 676066aa4798
permissions -rw-r--r--
tuned signature;
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
72339
626920749f5d tuned signature;
wenzelm
parents: 72338
diff changeset
    29
    new Isabelle_Platform(
72338
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))
72339
626920749f5d tuned signature;
wenzelm
parents: 72338
diff changeset
    34
        }))
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
}
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    37
72339
626920749f5d tuned signature;
wenzelm
parents: 72338
diff changeset
    38
class Isabelle_Platform private(val settings: List[(String, String)])
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    39
{
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    40
  private def get(name: String): String =
72339
626920749f5d tuned signature;
wenzelm
parents: 72338
diff changeset
    41
    settings.collectFirst({ case (a, b) if a == name => b }).
72338
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    42
      getOrElse(error("Bad platform settings variable: " + quote(name)))
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    43
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    44
  val ISABELLE_PLATFORM_FAMILY: String = get("ISABELLE_PLATFORM_FAMILY")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    45
  val ISABELLE_PLATFORM32: String = get("ISABELLE_PLATFORM32")
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_PLATFORM32: String = get("ISABELLE_WINDOWS_PLATFORM32")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    48
  val ISABELLE_WINDOWS_PLATFORM64: String = get("ISABELLE_WINDOWS_PLATFORM64")
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    49
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    50
  val is_linux: Boolean = ISABELLE_PLATFORM_FAMILY == "linux"
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    51
  val is_macos: Boolean = ISABELLE_PLATFORM_FAMILY == "macos"
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    52
  val is_windows: Boolean = ISABELLE_PLATFORM_FAMILY == "windows"
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    53
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    54
  override def toString: String = ISABELLE_PLATFORM_FAMILY
54871a086193 formal platform information, notably for ssh;
wenzelm
parents:
diff changeset
    55
}