src/Pure/Admin/other_isabelle.scala
author wenzelm
Thu Oct 13 12:13:43 2016 +0200 (2016-10-13)
changeset 64188 f88bae1922c4
child 64189 dfb63036c4f6
permissions -rw-r--r--
clarified modules;
     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 copy_dir(dir1: Path, dir2: Path): Unit =
    25     bash("cp -a " + File.bash_path(dir1) + " " + File.bash_path(dir2)).check
    26 
    27   def apply(cmdline: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
    28     bash("bin/isabelle " + cmdline, redirect, echo)
    29 
    30   def resolve_components(echo: Boolean): Unit =
    31     other_isabelle("components -a", redirect = true, echo = echo).check
    32 
    33   val isabelle_home_user: Path =
    34     Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
    35 
    36   val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
    37 
    38 
    39   /* init settings */
    40 
    41   def init_settings(components_base: String, nonfree: Boolean)
    42   {
    43     if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
    44       error("Cannot proceed with existing user settings file: " + etc_settings)
    45 
    46     Isabelle_System.mkdirs(etc_settings.dir)
    47     File.write(etc_settings,
    48       "# generated by Isabelle " + Date.now() + "\n" +
    49       "#-*- shell-script -*- :mode=shellscript:\n")
    50 
    51     val component_settings =
    52     {
    53       val components_base_path =
    54         if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
    55         else Path.explode(components_base).expand
    56 
    57       val catalogs =
    58         if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
    59 
    60       catalogs.map(catalog =>
    61         "init_components " + File.bash_path(components_base_path) +
    62           " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
    63     }
    64     File.append(etc_settings, "\n" + terminate_lines(component_settings))
    65   }
    66 }