src/Pure/Admin/other_isabelle.scala
author wenzelm
Thu Oct 13 15:17:10 2016 +0200 (2016-10-13)
changeset 64189 dfb63036c4f6
parent 64188 f88bae1922c4
child 64201 c3edc64e219d
permissions -rw-r--r--
tuned signature;
copy_dir using *this* Isabelle_System: note that File.bash_path is already expanded, but no variables are used here;
     1 /*  Title:      Pure/Admin/other_isabelle.scala
     2     Author:     Makarius
     3 
     4 Manage other Isabelle distributions.
     5 */
     6 
     7 package isabelle
     8 
     9 
    10 private class Other_Isabelle(progress: Progress, isabelle_home: Path, 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     Isabelle_System.bash(
    19       "export ISABELLE_IDENTIFIER=" + File.bash_string(isabelle_identifier) + "\n" + script,
    20       env = null, cwd = isabelle_home.file, redirect = redirect,
    21       progress_stdout = progress.echo_if(echo, _),
    22       progress_stderr = progress.echo_if(echo, _))
    23 
    24   def apply(cmdline: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
    25     bash("bin/isabelle " + cmdline, redirect, echo)
    26 
    27   def resolve_components(echo: Boolean): Unit =
    28     other_isabelle("components -a", redirect = true, echo = echo).check
    29 
    30   val isabelle_home_user: Path =
    31     Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
    32 
    33   val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
    34 
    35 
    36   /* init settings */
    37 
    38   def init_settings(components_base: String, nonfree: Boolean)
    39   {
    40     if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
    41       error("Cannot proceed with existing user settings file: " + etc_settings)
    42 
    43     Isabelle_System.mkdirs(etc_settings.dir)
    44     File.write(etc_settings,
    45       "# generated by Isabelle " + Date.now() + "\n" +
    46       "#-*- shell-script -*- :mode=shellscript:\n")
    47 
    48     val component_settings =
    49     {
    50       val components_base_path =
    51         if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
    52         else Path.explode(components_base).expand
    53 
    54       val catalogs =
    55         if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
    56 
    57       catalogs.map(catalog =>
    58         "init_components " + File.bash_path(components_base_path) +
    59           " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
    60     }
    61     File.append(etc_settings, "\n" + terminate_lines(component_settings))
    62   }
    63 }