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