src/Pure/Tools/build_history.scala
author wenzelm
Mon, 03 Oct 2016 20:26:32 +0200
changeset 64025 ff4910ced9ba
parent 64023 41f7e383c19e
child 64026 cbecd26e063f
permissions -rw-r--r--
clarified command-line; init settings and components;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Tools/build_history.scala
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     3
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     4
Build other history versions.
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     5
*/
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     6
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     7
package isabelle
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     8
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
     9
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    10
import java.io.{File => JFile}
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    11
import java.util.Calendar
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    12
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    13
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    14
object Build_History
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    15
{
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    16
  /* build_history */
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    17
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    18
  private val default_rev = "tip"
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    19
  private val default_isabelle_identifier = "build_history"
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    20
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    21
  def build_history(
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    22
    hg: Mercurial.Repository,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    23
    rev: String = default_rev,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    24
    isabelle_identifier: String = default_isabelle_identifier,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    25
    components_base: String = "",
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    26
    nonfree: Boolean = false,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    27
    verbose: Boolean = false)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    28
  {
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    29
    hg.update(rev = rev, clean = true)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    30
    if (verbose) hg.command("log -l1").check.print
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    31
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    32
    def bash(script: String): Process_Result =
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    33
      Isabelle_System.bash("env ISABELLE_IDENTIFIER=" + File.bash_string(isabelle_identifier) +
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    34
        " " + script, cwd = hg.root.file, env = null)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    35
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    36
    def isabelle(cmdline: String): Process_Result = bash("bin/isabelle " + cmdline)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    37
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    38
    val isabelle_home_user: Path = Path.explode(isabelle("getenv -b ISABELLE_HOME_USER").check.out)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    39
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    40
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    41
    /* init settings */
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    42
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    43
    {
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    44
      val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    45
      if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    46
        error("User settings file already exists: " + etc_settings)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    47
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    48
      Isabelle_System.mkdirs(etc_settings.dir)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    49
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    50
      val components_base_path =
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    51
        if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    52
        else Path.explode(components_base).expand
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    53
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    54
      val catalogs =
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    55
        if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    56
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    57
      val settings =
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    58
        catalogs.map(catalog =>
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    59
          "init_components " + File.bash_path(components_base_path) +
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    60
            " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    61
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    62
      File.write(etc_settings,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    63
        "# generated by Isabelle " + Calendar.getInstance.getTime + "\n" +
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    64
        "#-*- shell-script -*- :mode=shellscript:\n\n" +
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    65
        Library.terminate_lines(settings))
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    66
    }
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    67
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    68
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    69
    /* components */
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    70
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    71
    isabelle("components -a").check.print_if(verbose)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    72
    isabelle("jedit -b -f").check.print_if(verbose)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    73
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    74
    isabelle("build -?").print
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    75
  }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    76
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    77
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    78
  /* command line entry point */
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    79
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    80
  def main(args: Array[String])
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    81
  {
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    82
    Command_Line.tool0 {
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    83
      var components_base = ""
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    84
      var isabelle_identifier = default_isabelle_identifier
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    85
      var force = false
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    86
      var nonfree = false
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    87
      var rev = default_rev
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    88
      var verbose = false
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    89
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    90
      val getopts = Getopts("""
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    91
Usage: isabelle build_history [OPTIONS] REPOSITORY
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    92
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    93
  Options are:
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    94
    -C DIR       base directory for Isabelle components (default: $ISABELLE_HOME_USER/../contrib)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    95
    -N NAME      alternative ISABELLE_IDENTIFIER (default: """ + default_isabelle_identifier + """)
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    96
    -f           force -- allow irreversible operations on REPOSITORY clone
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    97
    -n           include nonfree components
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    98
    -r REV       update to revision
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    99
    -v           verbose
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   100
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   101
  Build Isabelle sessions from the history of another REPOSITORY clone,
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   102
  starting at changeset REV (default: """ + default_rev + """).
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   103
""",
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   104
        "C:" -> (arg => components_base = arg),
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   105
        "N:" -> (arg => isabelle_identifier = arg),
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   106
        "f" -> (_ => force = true),
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   107
        "n" -> (_ => nonfree = true),
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   108
        "r:" -> (arg => rev = arg),
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   109
        "v" -> (_ => verbose = true))
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   110
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   111
      val more_args = getopts(args)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   112
      val root = more_args match { case List(root) => (root) case _ => getopts.usage() }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   113
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   114
      using(Mercurial.open_repository(Path.explode(root)))(hg =>
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   115
        {
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   116
          if (!force)
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   117
            error("Repository " + hg + " will be cleaned by force!\n" +
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   118
              "Need to provide option -f to confirm this.")
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   119
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   120
          build_history(hg, rev = rev, isabelle_identifier = isabelle_identifier,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   121
            components_base = components_base, nonfree = nonfree, verbose = verbose)
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   122
        })
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   123
    }
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   124
  }
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   125
}