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