src/Pure/Admin/other_isabelle.scala
author wenzelm
Wed May 24 11:39:00 2017 +0200 (23 months ago)
changeset 65916 5b8ed310b31d
parent 65845 b8ff63149256
child 65930 9a28fc03c3fe
permissions -rw-r--r--
tuned;
     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(script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
    18     progress.bash(Isabelle_System.export_isabelle_identifier(isabelle_identifier) + script,
    19       env = null, cwd = isabelle_home.file, redirect = redirect, echo = echo)
    20 
    21   def apply(cmdline: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
    22     bash("bin/isabelle " + cmdline, redirect, echo)
    23 
    24   def resolve_components(echo: Boolean): Unit =
    25     other_isabelle("components -a", redirect = true, echo = echo).check
    26 
    27   val isabelle_home_user: Path =
    28     Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
    29 
    30   val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
    31 
    32 
    33   /* init settings */
    34 
    35   def init_settings(components_base: String, nonfree: Boolean, more_settings: List[String])
    36   {
    37     if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
    38       error("Cannot proceed with existing user settings file: " + etc_settings)
    39 
    40     Isabelle_System.mkdirs(etc_settings.dir)
    41     File.write(etc_settings,
    42       "# generated by Isabelle " + Date.now() + "\n" +
    43       "#-*- shell-script -*- :mode=shellscript:\n")
    44 
    45     val component_settings =
    46     {
    47       val components_base_path =
    48         if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
    49         else Path.explode(components_base).expand
    50 
    51       val catalogs =
    52         if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
    53 
    54       catalogs.map(catalog =>
    55         "init_components " + File.bash_path(components_base_path) +
    56           " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
    57     }
    58 
    59     val settings =
    60       List(component_settings) :::
    61       (if (more_settings.isEmpty) Nil else List(more_settings))
    62 
    63     File.append(etc_settings, "\n" + cat_lines(settings.map(terminate_lines(_))))
    64   }
    65 }