src/Pure/Admin/other_isabelle.scala
author wenzelm
Fri May 26 11:09:16 2017 +0200 (23 months ago)
changeset 65930 9a28fc03c3fe
parent 65916 5b8ed310b31d
child 67045 6c94f749410a
permissions -rw-r--r--
tuned signature;
wenzelm@64188
     1
/*  Title:      Pure/Admin/other_isabelle.scala
wenzelm@64188
     2
    Author:     Makarius
wenzelm@64188
     3
wenzelm@64188
     4
Manage other Isabelle distributions.
wenzelm@64188
     5
*/
wenzelm@64188
     6
wenzelm@64188
     7
package isabelle
wenzelm@64188
     8
wenzelm@64188
     9
wenzelm@64315
    10
class Other_Isabelle(progress: Progress, val isabelle_home: Path, val isabelle_identifier: String)
wenzelm@64188
    11
{
wenzelm@64188
    12
  other_isabelle =>
wenzelm@64188
    13
wenzelm@64188
    14
wenzelm@64188
    15
  /* static system */
wenzelm@64188
    16
wenzelm@65930
    17
  def bash(
wenzelm@65930
    18
      script: String,
wenzelm@65930
    19
      redirect: Boolean = false,
wenzelm@65930
    20
      echo: Boolean = false,
wenzelm@65930
    21
      strict: Boolean = true): Process_Result =
wenzelm@65916
    22
    progress.bash(Isabelle_System.export_isabelle_identifier(isabelle_identifier) + script,
wenzelm@65930
    23
      env = null, cwd = isabelle_home.file, redirect = redirect, echo = echo, strict = strict)
wenzelm@64188
    24
wenzelm@65930
    25
  def apply(
wenzelm@65930
    26
      cmdline: String,
wenzelm@65930
    27
      redirect: Boolean = false,
wenzelm@65930
    28
      echo: Boolean = false,
wenzelm@65930
    29
      strict: Boolean = true): Process_Result =
wenzelm@65930
    30
    bash("bin/isabelle " + cmdline, redirect = redirect, echo = echo, strict = strict)
wenzelm@64188
    31
wenzelm@64188
    32
  def resolve_components(echo: Boolean): Unit =
wenzelm@64188
    33
    other_isabelle("components -a", redirect = true, echo = echo).check
wenzelm@64188
    34
wenzelm@64188
    35
  val isabelle_home_user: Path =
wenzelm@64188
    36
    Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
wenzelm@64188
    37
wenzelm@64188
    38
  val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
wenzelm@64188
    39
wenzelm@64188
    40
wenzelm@64188
    41
  /* init settings */
wenzelm@64188
    42
wenzelm@65845
    43
  def init_settings(components_base: String, nonfree: Boolean, more_settings: List[String])
wenzelm@64188
    44
  {
wenzelm@64188
    45
    if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
wenzelm@64188
    46
      error("Cannot proceed with existing user settings file: " + etc_settings)
wenzelm@64188
    47
wenzelm@64188
    48
    Isabelle_System.mkdirs(etc_settings.dir)
wenzelm@64188
    49
    File.write(etc_settings,
wenzelm@64188
    50
      "# generated by Isabelle " + Date.now() + "\n" +
wenzelm@64188
    51
      "#-*- shell-script -*- :mode=shellscript:\n")
wenzelm@64188
    52
wenzelm@64188
    53
    val component_settings =
wenzelm@64188
    54
    {
wenzelm@64188
    55
      val components_base_path =
wenzelm@64188
    56
        if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
wenzelm@64188
    57
        else Path.explode(components_base).expand
wenzelm@64188
    58
wenzelm@64188
    59
      val catalogs =
wenzelm@64188
    60
        if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
wenzelm@64188
    61
wenzelm@64188
    62
      catalogs.map(catalog =>
wenzelm@64188
    63
        "init_components " + File.bash_path(components_base_path) +
wenzelm@64188
    64
          " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
wenzelm@64188
    65
    }
wenzelm@65845
    66
wenzelm@65845
    67
    val settings =
wenzelm@65845
    68
      List(component_settings) :::
wenzelm@65845
    69
      (if (more_settings.isEmpty) Nil else List(more_settings))
wenzelm@65845
    70
wenzelm@65845
    71
    File.append(etc_settings, "\n" + cat_lines(settings.map(terminate_lines(_))))
wenzelm@64188
    72
  }
wenzelm@64188
    73
}