src/Pure/Admin/other_isabelle.scala
author wenzelm
Tue Oct 18 10:05:38 2016 +0200 (2016-10-18)
changeset 64294 303976a45afe
parent 64201 c3edc64e219d
child 64304 96bc94c87a81
permissions -rw-r--r--
shared_home is default for classic isatest home setup;
distinct ISABELLE_IDENTIFIER for all tasks;
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@64188
    10
private class Other_Isabelle(progress: Progress, isabelle_home: Path, 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@64188
    17
  def bash(script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
wenzelm@64201
    18
    progress.bash(
wenzelm@64188
    19
      "export ISABELLE_IDENTIFIER=" + File.bash_string(isabelle_identifier) + "\n" + script,
wenzelm@64201
    20
      env = null, cwd = isabelle_home.file, redirect = redirect)
wenzelm@64188
    21
wenzelm@64188
    22
  def apply(cmdline: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
wenzelm@64188
    23
    bash("bin/isabelle " + cmdline, redirect, echo)
wenzelm@64188
    24
wenzelm@64188
    25
  def resolve_components(echo: Boolean): Unit =
wenzelm@64188
    26
    other_isabelle("components -a", redirect = true, echo = echo).check
wenzelm@64188
    27
wenzelm@64188
    28
  val isabelle_home_user: Path =
wenzelm@64188
    29
    Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
wenzelm@64188
    30
wenzelm@64188
    31
  val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
wenzelm@64188
    32
wenzelm@64188
    33
wenzelm@64188
    34
  /* init settings */
wenzelm@64188
    35
wenzelm@64188
    36
  def init_settings(components_base: String, nonfree: Boolean)
wenzelm@64188
    37
  {
wenzelm@64188
    38
    if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
wenzelm@64188
    39
      error("Cannot proceed with existing user settings file: " + etc_settings)
wenzelm@64188
    40
wenzelm@64188
    41
    Isabelle_System.mkdirs(etc_settings.dir)
wenzelm@64188
    42
    File.write(etc_settings,
wenzelm@64188
    43
      "# generated by Isabelle " + Date.now() + "\n" +
wenzelm@64188
    44
      "#-*- shell-script -*- :mode=shellscript:\n")
wenzelm@64188
    45
wenzelm@64188
    46
    val component_settings =
wenzelm@64188
    47
    {
wenzelm@64188
    48
      val components_base_path =
wenzelm@64188
    49
        if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
wenzelm@64188
    50
        else Path.explode(components_base).expand
wenzelm@64188
    51
wenzelm@64188
    52
      val catalogs =
wenzelm@64188
    53
        if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
wenzelm@64188
    54
wenzelm@64188
    55
      catalogs.map(catalog =>
wenzelm@64188
    56
        "init_components " + File.bash_path(components_base_path) +
wenzelm@64188
    57
          " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
wenzelm@64188
    58
    }
wenzelm@64188
    59
    File.append(etc_settings, "\n" + terminate_lines(component_settings))
wenzelm@64188
    60
  }
wenzelm@64188
    61
}