src/Pure/Tools/build_history.scala
author wenzelm
Wed, 05 Oct 2016 12:36:56 +0200
changeset 64051 4dd9d9b28fd5
parent 64050 68fcd61b87ae
child 64052 72fa79eab7f6
permissions -rw-r--r--
allow multiple threads configurations;
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
{
64050
wenzelm
parents: 64049
diff changeset
    16
  /** other Isabelle environment **/
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    17
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    18
  private class Other_Isabelle(progress: Progress, isabelle_home: Path, isabelle_identifier: String)
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    19
  {
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    20
    other_isabelle =>
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    21
64050
wenzelm
parents: 64049
diff changeset
    22
wenzelm
parents: 64049
diff changeset
    23
    /* static system */
wenzelm
parents: 64049
diff changeset
    24
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    25
    def bash(script: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    26
      Isabelle_System.bash(
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    27
        "export ISABELLE_IDENTIFIER=" + File.bash_string(isabelle_identifier) + "\n" + script,
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    28
        env = null, cwd = isabelle_home.file, redirect = redirect,
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    29
        progress_stdout = progress.echo_if(echo, _),
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    30
        progress_stderr = progress.echo_if(echo, _))
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    31
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    32
    def apply(cmdline: String, redirect: Boolean = false, echo: Boolean = false): Process_Result =
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    33
      bash("bin/isabelle " + cmdline, redirect, echo)
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    34
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    35
    def resolve_components(echo: Boolean): Unit =
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    36
      other_isabelle("components -a", redirect = true, echo = echo).check
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    37
64050
wenzelm
parents: 64049
diff changeset
    38
    val isabelle_home_user: Path =
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    39
      Path.explode(other_isabelle("getenv -b ISABELLE_HOME_USER").check.out)
64050
wenzelm
parents: 64049
diff changeset
    40
wenzelm
parents: 64049
diff changeset
    41
    val etc_settings: Path = isabelle_home_user + Path.explode("etc/settings")
wenzelm
parents: 64049
diff changeset
    42
wenzelm
parents: 64049
diff changeset
    43
wenzelm
parents: 64049
diff changeset
    44
    /* reset settings */
wenzelm
parents: 64049
diff changeset
    45
wenzelm
parents: 64049
diff changeset
    46
    def reset_settings(components_base: String, nonfree: Boolean)
wenzelm
parents: 64049
diff changeset
    47
    {
wenzelm
parents: 64049
diff changeset
    48
      if (etc_settings.is_file && !File.read(etc_settings).startsWith("# generated by Isabelle"))
wenzelm
parents: 64049
diff changeset
    49
        error("Cannot proceed with existing user settings file: " + etc_settings)
wenzelm
parents: 64049
diff changeset
    50
wenzelm
parents: 64049
diff changeset
    51
      Isabelle_System.mkdirs(etc_settings.dir)
wenzelm
parents: 64049
diff changeset
    52
      File.write(etc_settings,
wenzelm
parents: 64049
diff changeset
    53
        "# generated by Isabelle " + Calendar.getInstance.getTime + "\n" +
wenzelm
parents: 64049
diff changeset
    54
        "#-*- shell-script -*- :mode=shellscript:\n")
wenzelm
parents: 64049
diff changeset
    55
wenzelm
parents: 64049
diff changeset
    56
      val component_settings =
wenzelm
parents: 64049
diff changeset
    57
      {
wenzelm
parents: 64049
diff changeset
    58
        val components_base_path =
wenzelm
parents: 64049
diff changeset
    59
          if (components_base == "") isabelle_home_user.dir + Path.explode("contrib")
wenzelm
parents: 64049
diff changeset
    60
          else Path.explode(components_base).expand
wenzelm
parents: 64049
diff changeset
    61
wenzelm
parents: 64049
diff changeset
    62
        val catalogs =
wenzelm
parents: 64049
diff changeset
    63
          if (nonfree) List("main", "optional", "nonfree") else List("main", "optional")
wenzelm
parents: 64049
diff changeset
    64
wenzelm
parents: 64049
diff changeset
    65
        catalogs.map(catalog =>
wenzelm
parents: 64049
diff changeset
    66
          "init_components " + File.bash_path(components_base_path) +
wenzelm
parents: 64049
diff changeset
    67
            " \"$ISABELLE_HOME/Admin/components/" + catalog + "\"")
wenzelm
parents: 64049
diff changeset
    68
      }
wenzelm
parents: 64049
diff changeset
    69
      File.append(etc_settings, "\n" + Library.terminate_lines(component_settings))
wenzelm
parents: 64049
diff changeset
    70
    }
wenzelm
parents: 64049
diff changeset
    71
wenzelm
parents: 64049
diff changeset
    72
wenzelm
parents: 64049
diff changeset
    73
    /* augment settings */
wenzelm
parents: 64049
diff changeset
    74
wenzelm
parents: 64049
diff changeset
    75
    def augment_settings(
wenzelm
parents: 64049
diff changeset
    76
      threads: Int,
wenzelm
parents: 64049
diff changeset
    77
      arch_64: Boolean = false,
wenzelm
parents: 64049
diff changeset
    78
      heap: Int = default_heap,
wenzelm
parents: 64049
diff changeset
    79
      max_heap: Option[Int] = None,
wenzelm
parents: 64049
diff changeset
    80
      more_settings: List[String])
wenzelm
parents: 64049
diff changeset
    81
    {
wenzelm
parents: 64049
diff changeset
    82
      val ml_settings =
wenzelm
parents: 64049
diff changeset
    83
      {
wenzelm
parents: 64049
diff changeset
    84
        val windows_32 = "x86-windows"
wenzelm
parents: 64049
diff changeset
    85
        val windows_64 = "x86_64-windows"
wenzelm
parents: 64049
diff changeset
    86
        val platform_32 = other_isabelle("getenv -b ISABELLE_PLATFORM32").check.out
wenzelm
parents: 64049
diff changeset
    87
        val platform_64 = other_isabelle("getenv -b ISABELLE_PLATFORM64").check.out
wenzelm
parents: 64049
diff changeset
    88
        val platform_family = other_isabelle("getenv -b ISABELLE_PLATFORM_FAMILY").check.out
wenzelm
parents: 64049
diff changeset
    89
wenzelm
parents: 64049
diff changeset
    90
        val polyml_home =
wenzelm
parents: 64049
diff changeset
    91
          try { Path.explode(other_isabelle("getenv -b ML_HOME").check.out).dir }
wenzelm
parents: 64049
diff changeset
    92
          catch { case ERROR(msg) => error("Bad ML_HOME: " + msg) }
wenzelm
parents: 64049
diff changeset
    93
wenzelm
parents: 64049
diff changeset
    94
        def ml_home(platform: String): Path = polyml_home + Path.explode(platform)
wenzelm
parents: 64049
diff changeset
    95
wenzelm
parents: 64049
diff changeset
    96
        def err(platform: String): Nothing =
wenzelm
parents: 64049
diff changeset
    97
          error("Platform " + platform + " unavailable on this machine")
wenzelm
parents: 64049
diff changeset
    98
wenzelm
parents: 64049
diff changeset
    99
        def check_dir(platform: String): Boolean =
wenzelm
parents: 64049
diff changeset
   100
          platform != "" && ml_home(platform).is_dir
wenzelm
parents: 64049
diff changeset
   101
wenzelm
parents: 64049
diff changeset
   102
        val ml_platform =
wenzelm
parents: 64049
diff changeset
   103
          if (Platform.is_windows && arch_64) {
wenzelm
parents: 64049
diff changeset
   104
            if (check_dir(windows_64)) windows_64 else err(windows_64)
wenzelm
parents: 64049
diff changeset
   105
          }
wenzelm
parents: 64049
diff changeset
   106
          else if (Platform.is_windows && !arch_64) {
wenzelm
parents: 64049
diff changeset
   107
            if (check_dir(windows_32)) windows_32
wenzelm
parents: 64049
diff changeset
   108
            else platform_32  // x86-cygwin
wenzelm
parents: 64049
diff changeset
   109
          }
wenzelm
parents: 64049
diff changeset
   110
          else {
wenzelm
parents: 64049
diff changeset
   111
            val (platform, platform_name) =
wenzelm
parents: 64049
diff changeset
   112
              if (arch_64) (platform_64, "x86_64-" + platform_family)
wenzelm
parents: 64049
diff changeset
   113
              else (platform_32, "x86-" + platform_family)
wenzelm
parents: 64049
diff changeset
   114
            if (check_dir(platform)) platform else err(platform_name)
wenzelm
parents: 64049
diff changeset
   115
          }
wenzelm
parents: 64049
diff changeset
   116
wenzelm
parents: 64049
diff changeset
   117
        val ml_options =
wenzelm
parents: 64049
diff changeset
   118
          "--minheap " + heap + (if (max_heap.isDefined) " --maxheap " + max_heap.get else "") +
wenzelm
parents: 64049
diff changeset
   119
          " --gcthreads " + threads +
wenzelm
parents: 64049
diff changeset
   120
          (if (ml_platform.endsWith("-windows")) " --codepage utf8" else "")
wenzelm
parents: 64049
diff changeset
   121
wenzelm
parents: 64049
diff changeset
   122
        List(
wenzelm
parents: 64049
diff changeset
   123
          "ML_HOME=" + File.bash_path(ml_home(ml_platform)),
wenzelm
parents: 64049
diff changeset
   124
          "ML_PLATFORM=" + quote(ml_platform),
wenzelm
parents: 64049
diff changeset
   125
          "ML_OPTIONS=" + quote(ml_options))
wenzelm
parents: 64049
diff changeset
   126
      }
wenzelm
parents: 64049
diff changeset
   127
wenzelm
parents: 64049
diff changeset
   128
      val thread_settings =
wenzelm
parents: 64049
diff changeset
   129
        List(
wenzelm
parents: 64049
diff changeset
   130
          "ISABELLE_JAVA_SYSTEM_OPTIONS=\"$ISABELLE_JAVA_SYSTEM_OPTIONS -Disabelle.threads=" + threads + "\"",
wenzelm
parents: 64049
diff changeset
   131
          "ISABELLE_BUILD_OPTIONS=\"threads=" + threads + "\"")
wenzelm
parents: 64049
diff changeset
   132
wenzelm
parents: 64049
diff changeset
   133
      val settings =
wenzelm
parents: 64049
diff changeset
   134
        List(ml_settings, thread_settings) :::
wenzelm
parents: 64049
diff changeset
   135
          (if (more_settings.isEmpty) Nil else List(more_settings))
wenzelm
parents: 64049
diff changeset
   136
wenzelm
parents: 64049
diff changeset
   137
      File.append(etc_settings, "\n" + cat_lines(settings.map(Library.terminate_lines(_))))
wenzelm
parents: 64049
diff changeset
   138
    }
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   139
  }
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   140
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   141
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   142
64050
wenzelm
parents: 64049
diff changeset
   143
  /** build_history **/
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   144
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   145
  private val default_rev = "tip"
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   146
  private val default_threads = 1
64034
51bf28aa18a5 more ambitious default as in former isatest;
wenzelm
parents: 64032
diff changeset
   147
  private val default_heap = 1000
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   148
  private val default_isabelle_identifier = "build_history"
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   149
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   150
  def build_history(
64038
f69ce5e7ea7f incremental output;
wenzelm
parents: 64037
diff changeset
   151
    progress: Progress,
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   152
    hg: Mercurial.Repository,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   153
    rev: String = default_rev,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   154
    isabelle_identifier: String = default_isabelle_identifier,
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   155
    components_base: String = "",
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   156
    fresh: Boolean = false,
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   157
    nonfree: Boolean = false,
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   158
    threads_list: List[Int] = List(default_threads),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   159
    arch_64: Boolean = false,
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   160
    heap: Int = default_heap,
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   161
    max_heap: Option[Int] = None,
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   162
    more_settings: List[String] = Nil,
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   163
    verbose: Boolean = false,
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   164
    build_args: List[String] = Nil): List[Process_Result] =
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   165
  {
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   166
    /* sanity checks */
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   167
64046
5a6a7401c48b clarified sanity checks;
wenzelm
parents: 64044
diff changeset
   168
    if (File.eq(Path.explode("~~").file, hg.root.file))
5a6a7401c48b clarified sanity checks;
wenzelm
parents: 64044
diff changeset
   169
      error("Repository coincides with ISABELLE_HOME=" + Path.explode("~~").expand)
5a6a7401c48b clarified sanity checks;
wenzelm
parents: 64044
diff changeset
   170
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   171
    for (threads <- threads_list if threads < 1) error("Bad threads value < 1: " + threads)
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   172
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   173
    if (heap < 100) error("Bad heap value < 100: " + heap)
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   174
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   175
    if (max_heap.isDefined && max_heap.get < heap)
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   176
      error("Bad max_heap value < heap: " + max_heap.get)
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   177
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   178
    System.getenv("ISABELLE_SETTINGS_PRESENT") match {
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   179
      case null | "" =>
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   180
      case _ => error("Cannot run build_history within existing Isabelle settings environment")
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   181
    }
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   182
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   183
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   184
    /* init repository */
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   185
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   186
    hg.update(rev = rev, clean = true)
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   187
    progress.echo_if(verbose, hg.log(rev, options = "-l1"))
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   188
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   189
    val other_isabelle = new Other_Isabelle(progress, hg.root, isabelle_identifier)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   190
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   191
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   192
    /* init settings and build */
64043
44b6c620c371 more thorought update of components;
wenzelm
parents: 64040
diff changeset
   193
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   194
    var first_build = true
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   195
    for (threads <- threads_list)
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   196
    yield {
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   197
      other_isabelle.reset_settings(components_base, nonfree)
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   198
      other_isabelle.resolve_components(verbose)
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   199
      other_isabelle.augment_settings(threads, arch_64, heap, max_heap, more_settings)
64043
44b6c620c371 more thorought update of components;
wenzelm
parents: 64040
diff changeset
   200
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   201
      if (first_build) {
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   202
        first_build = false
64032
wenzelm
parents: 64031
diff changeset
   203
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   204
        other_isabelle.resolve_components(verbose)
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   205
        other_isabelle.bash(
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   206
          "env PATH=\"" + File.bash_path(Path.explode("~~/lib/dummy_stty").expand) + ":$PATH\" " +
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   207
            "bin/isabelle jedit -b" + (if (fresh) " -f" else ""),
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   208
          redirect = true, echo = verbose).check
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   209
      }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   210
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   211
      val isabelle_output = Path.explode(other_isabelle("getenv -b ISABELLE_OUTPUT").check.out)
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   212
      Isabelle_System.rm_tree(isabelle_output.file)
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   213
      other_isabelle("build " + File.bash_args(build_args), redirect = true, echo = true)
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   214
    }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   215
  }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   216
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   217
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   218
  /* command line entry point */
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   219
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   220
  def main(args: Array[String])
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   221
  {
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   222
    Command_Line.tool0 {
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   223
      var components_base = ""
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   224
      var heap: Option[Int] = None
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   225
      var max_heap: Option[Int] = None
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   226
      var threads_list = List(default_threads)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   227
      var isabelle_identifier = default_isabelle_identifier
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   228
      var more_settings: List[String] = Nil
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   229
      var fresh = false
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   230
      var arch_64 = false
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   231
      var nonfree = false
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   232
      var rev = default_rev
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   233
      var verbose = false
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   234
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   235
      val getopts = Getopts("""
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   236
Usage: isabelle build_history [OPTIONS] REPOSITORY [ARGS ...]
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   237
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   238
  Options are:
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   239
    -C DIR       base directory for Isabelle components (default: $ISABELLE_HOME_USER/../contrib)
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   240
    -H SIZE      minimal ML heap in MB (default: """ + default_heap + """ for x86, """ + default_heap * 2 + """ for x86_64)
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   241
    -M THREADS   multithreading configurations (comma-separated list, default: """ + default_threads + """)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   242
    -N NAME      alternative ISABELLE_IDENTIFIER (default: """ + default_isabelle_identifier + """)
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   243
    -U SIZE      maximal ML heap in MB (default: unbounded)
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   244
    -e TEXT      additional text for generated etc/settings
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   245
    -f           fresh build of Isabelle/Scala components (recommended)
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   246
    -m ARCH      processor architecture (32=x86, 64=x86_64, default: x86)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   247
    -n           include nonfree components
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   248
    -r REV       update to revision (default: """ + default_rev + """)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   249
    -v           verbose
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   250
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   251
  Build Isabelle sessions from the history of another REPOSITORY clone,
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   252
  passing ARGS directly to its isabelle build tool.
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   253
""",
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   254
        "C:" -> (arg => components_base = arg),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   255
        "H:" -> (arg => heap = Some(Value.Int.parse(arg))),
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   256
        "M:" -> (arg => threads_list = space_explode(',', arg).map(Value.Int.parse(_))),
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   257
        "N:" -> (arg => isabelle_identifier = arg),
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   258
        "U:" -> (arg => max_heap = Some(Value.Int.parse(arg))),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   259
        "e:" -> (arg => more_settings = more_settings ::: List(arg)),
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   260
        "f" -> (_ => fresh = true),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   261
        "m:" ->
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   262
          {
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   263
            case "32" | "x86" => arch_64 = false
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   264
            case "64" | "x86_64" => arch_64 = true
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   265
            case bad => error("Bad processor architecture: " + quote(bad))
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   266
          },
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   267
        "n" -> (_ => nonfree = true),
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   268
        "r:" -> (arg => rev = arg),
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   269
        "v" -> (_ => verbose = true))
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   270
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   271
      val more_args = getopts(args)
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   272
      val (root, build_args) =
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   273
        more_args match {
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   274
          case root :: build_args => (root, build_args)
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   275
          case _ => getopts.usage()
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   276
        }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   277
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   278
      using(Mercurial.open_repository(Path.explode(root)))(hg =>
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   279
        {
64038
f69ce5e7ea7f incremental output;
wenzelm
parents: 64037
diff changeset
   280
          val progress = new Console_Progress(false)
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   281
          val results =
64038
f69ce5e7ea7f incremental output;
wenzelm
parents: 64037
diff changeset
   282
            build_history(progress, hg, rev = rev, isabelle_identifier = isabelle_identifier,
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   283
              components_base = components_base, fresh = fresh, nonfree = nonfree,
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   284
              threads_list = threads_list, arch_64 = arch_64,
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   285
              heap = heap.getOrElse(if (arch_64) default_heap * 2 else default_heap),
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   286
              max_heap = max_heap, more_settings = more_settings, verbose = verbose,
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   287
              build_args = build_args)
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   288
          val rc = (0 /: results) { case (rc, res) => rc max res.rc }
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   289
          if (rc != 0) sys.exit(rc)
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   290
        })
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   291
    }
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   292
  }
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   293
}