src/Pure/Admin/other_isabelle.scala
author wenzelm
Sat Nov 11 16:01:02 2017 +0100 (17 months ago)
changeset 67045 6c94f749410a
parent 65930 9a28fc03c3fe
child 67046 897f1ac84aab
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@67045
    10
object Other_Isabelle
wenzelm@67045
    11
{
wenzelm@67045
    12
  def apply(isabelle_home: Path,
wenzelm@67045
    13
      isabelle_identifier: String,
wenzelm@67045
    14
      progress: Progress = No_Progress): Other_Isabelle =
wenzelm@67045
    15
    new Other_Isabelle(isabelle_home, isabelle_identifier, progress)
wenzelm@67045
    16
}
wenzelm@67045
    17
wenzelm@67045
    18
class Other_Isabelle(
wenzelm@67045
    19
  val isabelle_home: Path,
wenzelm@67045
    20
  val isabelle_identifier: String,
wenzelm@67045
    21
  progress: Progress)
wenzelm@64188
    22
{
wenzelm@64188
    23
  other_isabelle =>
wenzelm@64188
    24
wenzelm@64188
    25
wenzelm@64188
    26
  /* static system */
wenzelm@64188
    27
wenzelm@65930
    28
  def bash(
wenzelm@65930
    29
      script: String,
wenzelm@65930
    30
      redirect: Boolean = false,
wenzelm@65930
    31
      echo: Boolean = false,
wenzelm@65930
    32
      strict: Boolean = true): Process_Result =
wenzelm@65916
    33
    progress.bash(Isabelle_System.export_isabelle_identifier(isabelle_identifier) + script,
wenzelm@65930
    34
      env = null, cwd = isabelle_home.file, redirect = redirect, echo = echo, strict = strict)
wenzelm@64188
    35
wenzelm@65930
    36
  def apply(
wenzelm@65930
    37
      cmdline: String,
wenzelm@65930
    38
      redirect: Boolean = false,
wenzelm@65930
    39
      echo: Boolean = false,
wenzelm@65930
    40
      strict: Boolean = true): Process_Result =
wenzelm@65930
    41
    bash("bin/isabelle " + cmdline, redirect = redirect, echo = echo, strict = strict)
wenzelm@64188
    42
wenzelm@64188
    43
  def resolve_components(echo: Boolean): Unit =
wenzelm@64188
    44
    other_isabelle("components -a", redirect = true, echo = echo).check
wenzelm@64188
    45
wenzelm@64188
    46
  val isabelle_home_user: Path =
wenzelm@64188
    47
    Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
wenzelm@64188
    48
wenzelm@64188
    49
  val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
wenzelm@64188
    50
wenzelm@64188
    51
wenzelm@64188
    52
  /* init settings */
wenzelm@64188
    53
wenzelm@65845
    54
  def init_settings(components_base: String, nonfree: Boolean, more_settings: List[String])
wenzelm@64188
    55
  {
wenzelm@64188
    56
    if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
wenzelm@64188
    57
      error("Cannot proceed with existing user settings file: " + etc_settings)
wenzelm@64188
    58
wenzelm@64188
    59
    Isabelle_System.mkdirs(etc_settings.dir)
wenzelm@64188
    60
    File.write(etc_settings,
wenzelm@64188
    61
      "# generated by Isabelle " + Date.now() + "\n" +
wenzelm@64188
    62
      "#-*- shell-script -*- :mode=shellscript:\n")
wenzelm@64188
    63
wenzelm@64188
    64
    val component_settings =
wenzelm@64188
    65
    {
wenzelm@64188
    66
      val components_base_path =
wenzelm@64188
    67
        if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
wenzelm@64188
    68
        else Path.explode(components_base).expand
wenzelm@64188
    69
wenzelm@64188
    70
      val catalogs =
wenzelm@64188
    71
        if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
wenzelm@64188
    72
wenzelm@64188
    73
      catalogs.map(catalog =>
wenzelm@64188
    74
        "init_components " + File.bash_path(components_base_path) +
wenzelm@64188
    75
          " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
wenzelm@64188
    76
    }
wenzelm@65845
    77
wenzelm@65845
    78
    val settings =
wenzelm@65845
    79
      List(component_settings) :::
wenzelm@65845
    80
      (if (more_settings.isEmpty) Nil else List(more_settings))
wenzelm@65845
    81
wenzelm@65845
    82
    File.append(etc_settings, "\n" + cat_lines(settings.map(terminate_lines(_))))
wenzelm@64188
    83
  }
wenzelm@64188
    84
}