src/Pure/Admin/other_isabelle.scala
changeset 64188 f88bae1922c4
child 64189 dfb63036c4f6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/Admin/other_isabelle.scala	Thu Oct 13 12:13:43 2016 +0200
     1.3 @@ -0,0 +1,66 @@
     1.4 +/*  Title:      Pure/Admin/other_isabelle.scala
     1.5 +    Author:     Makarius
     1.6 +
     1.7 +Manage other Isabelle distributions.
     1.8 +*/
     1.9 +
    1.10 +package isabelle
    1.11 +
    1.12 +
    1.13 +private class Other_Isabelle(progress: Progress, isabelle_home: Path, isabelle_identifier: String)
    1.14 +{
    1.15 +  other_isabelle =>
    1.16 +
    1.17 +
    1.18 +  /* static system */
    1.19 +
    1.20 +  def bash(script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
    1.21 +    Isabelle_System.bash(
    1.22 +      "export ISABELLE_IDENTIFIER=" + File.bash_string(isabelle_identifier) + "\n" + script,
    1.23 +      env = null, cwd = isabelle_home.file, redirect = redirect,
    1.24 +      progress_stdout = progress.echo_if(echo, _),
    1.25 +      progress_stderr = progress.echo_if(echo, _))
    1.26 +
    1.27 +  def copy_dir(dir1: Path, dir2: Path): Unit =
    1.28 +    bash("cp -a " + File.bash_path(dir1) + " " + File.bash_path(dir2)).check
    1.29 +
    1.30 +  def apply(cmdline: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
    1.31 +    bash("bin/isabelle " + cmdline, redirect, echo)
    1.32 +
    1.33 +  def resolve_components(echo: Boolean): Unit =
    1.34 +    other_isabelle("components -a", redirect = true, echo = echo).check
    1.35 +
    1.36 +  val isabelle_home_user: Path =
    1.37 +    Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
    1.38 +
    1.39 +  val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
    1.40 +
    1.41 +
    1.42 +  /* init settings */
    1.43 +
    1.44 +  def init_settings(components_base: String, nonfree: Boolean)
    1.45 +  {
    1.46 +    if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
    1.47 +      error("Cannot proceed with existing user settings file: " + etc_settings)
    1.48 +
    1.49 +    Isabelle_System.mkdirs(etc_settings.dir)
    1.50 +    File.write(etc_settings,
    1.51 +      "# generated by Isabelle " + Date.now() + "\n" +
    1.52 +      "#-*- shell-script -*- :mode=shellscript:\n")
    1.53 +
    1.54 +    val component_settings =
    1.55 +    {
    1.56 +      val components_base_path =
    1.57 +        if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
    1.58 +        else Path.explode(components_base).expand
    1.59 +
    1.60 +      val catalogs =
    1.61 +        if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
    1.62 +
    1.63 +      catalogs.map(catalog =>
    1.64 +        "init_components " + File.bash_path(components_base_path) +
    1.65 +          " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
    1.66 +    }
    1.67 +    File.append(etc_settings, "\n" + terminate_lines(component_settings))
    1.68 +  }
    1.69 +}