src/Pure/Admin/build_history.scala
author wenzelm
Tue, 11 May 2021 16:30:24 +0200
changeset 73671 7404f2e1d092
parent 73611 cc36841eeff6
child 74035 ec3249dd63dd
permissions -rw-r--r--
clarified platforms;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64160
1eea419fab65 clarified files;
wenzelm
parents: 64155
diff changeset
     1
/*  Title:      Pure/Admin/build_history.scala
64021
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
object Build_History
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
    11
{
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
    12
  /* log files */
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
    13
65588
b0d8d97198b3 clarified signature;
wenzelm
parents: 65320
diff changeset
    14
  val engine = "build_history"
65596
7fffa01b2d2b proper prefix;
wenzelm
parents: 65591
diff changeset
    15
  val log_prefix = engine + "_"
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
    16
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
    17
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    18
  /* augment settings */
64050
wenzelm
parents: 64049
diff changeset
    19
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    20
  def augment_settings(
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    21
    other_isabelle: Other_Isabelle,
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    22
    threads: Int,
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
    23
    arch_64: Boolean,
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
    24
    heap: Int,
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
    25
    max_heap: Option[Int],
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    26
    more_settings: List[String]): String =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    27
  {
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    28
    val (ml_platform, ml_settings) =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    29
    {
73671
7404f2e1d092 clarified platforms;
wenzelm
parents: 73611
diff changeset
    30
      val cygwin_32 = "x86-cygwin"
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    31
      val windows_32 = "x86-windows"
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    32
      val windows_64 = "x86_64-windows"
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    33
      val windows_64_32 = "x86_64_32-windows"
69166
5c553c48c0e5 tuned signature;
wenzelm
parents: 68221
diff changeset
    34
      val platform_32 = other_isabelle.getenv("ISABELLE_PLATFORM32")
5c553c48c0e5 tuned signature;
wenzelm
parents: 68221
diff changeset
    35
      val platform_64 = other_isabelle.getenv("ISABELLE_PLATFORM64")
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    36
      val platform_64_32 = platform_64.replace("x86_64-", "x86_64_32-")
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    37
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    38
      val polyml_home =
69166
5c553c48c0e5 tuned signature;
wenzelm
parents: 68221
diff changeset
    39
        try { Path.explode(other_isabelle.getenv("ML_HOME")).dir }
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    40
        catch { case ERROR(msg) => error("Bad ML_HOME: " + msg) }
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    41
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    42
      def ml_home(platform: String): Path = polyml_home + Path.explode(platform)
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    43
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    44
      def err(platform: String): Nothing =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    45
        error("Platform " + platform + " unavailable on this machine")
64050
wenzelm
parents: 64049
diff changeset
    46
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    47
      def check_dir(platform: String): Boolean =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    48
        platform != "" && ml_home(platform).is_dir
64050
wenzelm
parents: 64049
diff changeset
    49
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    50
      val ml_platform =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    51
        if (Platform.is_windows && arch_64) {
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    52
          if (check_dir(windows_64)) windows_64 else err(windows_64)
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    53
        }
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    54
        else if (Platform.is_windows && !arch_64) {
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    55
          if (check_dir(windows_64_32)) windows_64_32
73671
7404f2e1d092 clarified platforms;
wenzelm
parents: 73611
diff changeset
    56
          else if (check_dir(cygwin_32)) cygwin_32
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    57
          else if (check_dir(windows_32)) windows_32
73671
7404f2e1d092 clarified platforms;
wenzelm
parents: 73611
diff changeset
    58
          else err(windows_32)
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    59
        }
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    60
        else if (arch_64) {
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    61
          if (check_dir(platform_64)) platform_64 else err(platform_64)
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    62
        }
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    63
        else if (check_dir(platform_64_32)) platform_64_32
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    64
        else platform_32
64050
wenzelm
parents: 64049
diff changeset
    65
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    66
      val ml_options =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    67
        "--minheap " + heap + (if (max_heap.isDefined) " --maxheap " + max_heap.get else "") +
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    68
        " --gcthreads " + threads +
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    69
        (if (ml_platform.endsWith("-windows")) " --codepage utf8" else "")
64050
wenzelm
parents: 64049
diff changeset
    70
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    71
      (ml_platform,
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    72
        List(
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    73
          "ML_HOME=" + File.bash_path(ml_home(ml_platform)),
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    74
          "ML_PLATFORM=" + quote(ml_platform),
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    75
          "ML_OPTIONS=" + quote(ml_options)))
64050
wenzelm
parents: 64049
diff changeset
    76
    }
wenzelm
parents: 64049
diff changeset
    77
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    78
    val thread_settings =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    79
      List(
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    80
        "ISABELLE_JAVA_SYSTEM_OPTIONS=\"$ISABELLE_JAVA_SYSTEM_OPTIONS -Disabelle.threads=" + threads + "\"",
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    81
        "ISABELLE_BUILD_OPTIONS=\"threads=" + threads + "\"")
64050
wenzelm
parents: 64049
diff changeset
    82
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    83
    val settings =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    84
      List(ml_settings, thread_settings) :::
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
    85
      (if (more_settings.isEmpty) Nil else List(more_settings))
64050
wenzelm
parents: 64049
diff changeset
    86
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    87
    File.append(other_isabelle.etc_settings, "\n" + cat_lines(settings.map(terminate_lines(_))))
64050
wenzelm
parents: 64049
diff changeset
    88
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    89
    ml_platform
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    90
  }
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    91
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    92
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    93
64050
wenzelm
parents: 64049
diff changeset
    94
  /** build_history **/
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    95
73522
b219774a71ae tuned signature -- more explicit types;
wenzelm
parents: 73359
diff changeset
    96
  private val default_user_home = Path.USER_HOME
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
    97
  private val default_rev = "tip"
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
    98
  private val default_multicore = (1, 1)
64335
24e676390259 more ambitious default;
wenzelm
parents: 64305
diff changeset
    99
  private val default_heap = 1500
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   100
  private val default_isabelle_identifier = "build_history"
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   101
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   102
  def build_history(
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   103
    options: Options,
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   104
    root: Path,
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   105
    user_home: Path = default_user_home,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71632
diff changeset
   106
    progress: Progress = new Progress,
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   107
    rev: String = default_rev,
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   108
    afp_rev: Option[String] = None,
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   109
    afp_partition: Int = 0,
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   110
    isabelle_identifier: String = default_isabelle_identifier,
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   111
    ml_statistics_step: Int = 1,
73240
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   112
    component_repository: String = Components.default_component_repository,
69434
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69397
diff changeset
   113
    components_base: Path = Components.default_components_base,
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   114
    fresh: Boolean = false,
69304
1f4afcde3334 more robust hostname for Isabelle cronjobs: do not rely on target OS installation for resulting build_log database content;
wenzelm
parents: 69253
diff changeset
   115
    hostname: String = "",
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   116
    multicore_base: Boolean = false,
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   117
    multicore_list: List[(Int, Int)] = List(default_multicore),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   118
    arch_64: Boolean = false,
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   119
    heap: Int = default_heap,
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   120
    max_heap: Option[Int] = None,
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
   121
    init_settings: List[String] = Nil,
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   122
    more_settings: List[String] = Nil,
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   123
    more_preferences: List[String] = Nil,
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   124
    verbose: Boolean = false,
64297
12a47f263122 support for free-form build tags;
wenzelm
parents: 64296
diff changeset
   125
    build_tags: List[String] = Nil,
64194
b5ada7dcceaa integrity test of build_history vs. build_history_base;
wenzelm
parents: 64193
diff changeset
   126
    build_args: List[String] = Nil): List[(Process_Result, Path)] =
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   127
  {
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   128
    /* sanity checks */
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   129
73522
b219774a71ae tuned signature -- more explicit types;
wenzelm
parents: 73359
diff changeset
   130
    if (File.eq(Path.ISABELLE_HOME, root))
b219774a71ae tuned signature -- more explicit types;
wenzelm
parents: 73359
diff changeset
   131
      error("Repository coincides with ISABELLE_HOME=" + Path.ISABELLE_HOME.expand)
64046
5a6a7401c48b clarified sanity checks;
wenzelm
parents: 64044
diff changeset
   132
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   133
    for ((threads, _) <- multicore_list if threads < 1)
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   134
      error("Bad threads value < 1: " + threads)
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   135
    for ((_, processes) <- multicore_list if processes < 1)
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   136
      error("Bad processes value < 1: " + processes)
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   137
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   138
    if (heap < 100) error("Bad heap value < 100: " + heap)
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   139
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   140
    if (max_heap.isDefined && max_heap.get < heap)
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   141
      error("Bad max_heap value < heap: " + max_heap.get)
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   142
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   143
    System.getenv("ISABELLE_SETTINGS_PRESENT") match {
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   144
      case null | "" =>
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   145
      case _ => error("Cannot run build_history within existing Isabelle settings environment")
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   146
    }
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   147
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   148
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   149
    /* checkout Isabelle + AFP repository */
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   150
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   151
    def checkout(dir: Path, version: String): String =
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   152
    {
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   153
      val hg = Mercurial.repository(dir)
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   154
      hg.update(rev = version, clean = true)
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   155
      progress.echo_if(verbose, hg.log(version, options = "-l1"))
66866
f5cd84280b7a proper argument;
wenzelm
parents: 66862
diff changeset
   156
      hg.id(rev = version)
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   157
    }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   158
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   159
    val isabelle_version = checkout(root, rev)
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   160
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   161
    val afp_repos = root + Path.explode("AFP")
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   162
    val afp_version = afp_rev.map(checkout(afp_repos, _))
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   163
66862
136793b73c7c clarified stored build_args;
wenzelm
parents: 66861
diff changeset
   164
    val (afp_build_args, afp_sessions) =
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   165
      if (afp_rev.isEmpty) (Nil, Nil)
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   166
      else {
73184
a5998396051e more robust: defer error in sessions structure to build process;
wenzelm
parents: 73183
diff changeset
   167
        val (opt, sessions) =
a5998396051e more robust: defer error in sessions structure to build process;
wenzelm
parents: 73183
diff changeset
   168
          try {
a5998396051e more robust: defer error in sessions structure to build process;
wenzelm
parents: 73183
diff changeset
   169
            val afp = AFP.init(options, afp_repos)
a5998396051e more robust: defer error in sessions structure to build process;
wenzelm
parents: 73183
diff changeset
   170
            ("-d", afp.partition(afp_partition))
a5998396051e more robust: defer error in sessions structure to build process;
wenzelm
parents: 73183
diff changeset
   171
          } catch { case ERROR(_) => ("-D", Nil) }
a5998396051e more robust: defer error in sessions structure to build process;
wenzelm
parents: 73183
diff changeset
   172
        (List(opt, "~~/AFP/thys"), sessions)
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   173
      }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   174
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   175
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   176
    /* main */
64043
44b6c620c371 more thorought update of components;
wenzelm
parents: 64040
diff changeset
   177
67045
6c94f749410a tuned signature;
wenzelm
parents: 66913
diff changeset
   178
    val other_isabelle =
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   179
      Other_Isabelle(root, isabelle_identifier = isabelle_identifier,
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   180
        user_home = user_home, progress = progress)
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   181
69304
1f4afcde3334 more robust hostname for Isabelle cronjobs: do not rely on target OS installation for resulting build_log database content;
wenzelm
parents: 69253
diff changeset
   182
    val build_host = proper_string(hostname) getOrElse Isabelle_System.hostname()
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   183
    val build_history_date = Date.now()
64296
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   184
    val build_group_id = build_host + ":" + build_history_date.time.ms
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   185
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   186
    var first_build = true
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   187
    for ((threads, processes) <- multicore_list) yield
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   188
    {
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   189
      /* init settings */
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   190
69388
fc58534bc475 clarified component settings;
wenzelm
parents: 69387
diff changeset
   191
      val component_settings =
69434
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69397
diff changeset
   192
        other_isabelle.init_components(
73240
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   193
          component_repository = component_repository,
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   194
          components_base = components_base,
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   195
          catalogs = List("main", "optional"))
69388
fc58534bc475 clarified component settings;
wenzelm
parents: 69387
diff changeset
   196
      other_isabelle.init_settings(component_settings ::: init_settings)
73242
9fd449357079 tuned signature;
wenzelm
parents: 73240
diff changeset
   197
      other_isabelle.resolve_components(echo = verbose)
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   198
      val ml_platform =
65845
b8ff63149256 proper init_settings, before inspecting ML_HOME etc;
wenzelm
parents: 65844
diff changeset
   199
        augment_settings(other_isabelle, threads, arch_64, heap, max_heap, more_settings)
64043
44b6c620c371 more thorought update of components;
wenzelm
parents: 64040
diff changeset
   200
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   201
      File.write(other_isabelle.etc_preferences, cat_lines(more_preferences))
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   202
68219
c0341c0080e2 clarified store directories;
wenzelm
parents: 68209
diff changeset
   203
      val isabelle_output =
c0341c0080e2 clarified store directories;
wenzelm
parents: 68209
diff changeset
   204
        other_isabelle.isabelle_home_user + Path.explode("heaps") +
69166
5c553c48c0e5 tuned signature;
wenzelm
parents: 68221
diff changeset
   205
          Path.explode(other_isabelle.getenv("ML_IDENTIFIER"))
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   206
      val isabelle_output_log = isabelle_output + Path.explode("log")
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   207
      val isabelle_base_log = isabelle_output + Path.explode("../base_log")
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   208
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   209
      if (first_build) {
73242
9fd449357079 tuned signature;
wenzelm
parents: 73240
diff changeset
   210
        other_isabelle.resolve_components(echo = verbose)
64376
68ace7f3d78f more thorough cleanup of lib/classes -- it may contain broken Pure.jar or copies of Scala libraries (in historic versions);
wenzelm
parents: 64353
diff changeset
   211
68ace7f3d78f more thorough cleanup of lib/classes -- it may contain broken Pure.jar or copies of Scala libraries (in historic versions);
wenzelm
parents: 64353
diff changeset
   212
        if (fresh)
68ace7f3d78f more thorough cleanup of lib/classes -- it may contain broken Pure.jar or copies of Scala libraries (in historic versions);
wenzelm
parents: 64353
diff changeset
   213
          Isabelle_System.rm_tree(other_isabelle.isabelle_home + Path.explode("lib/classes"))
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   214
        other_isabelle.bash(
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   215
          "env PATH=\"" + File.bash_path(Path.explode("~~/lib/dummy_stty").expand) + ":$PATH\" " +
64376
68ace7f3d78f more thorough cleanup of lib/classes -- it may contain broken Pure.jar or copies of Scala libraries (in historic versions);
wenzelm
parents: 64353
diff changeset
   216
            "bin/isabelle jedit -b", redirect = true, echo = verbose).check
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   217
69253
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   218
        for {
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   219
          tool <- List("ghc_setup", "ocaml_setup")
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   220
          if other_isabelle.getenv("ISABELLE_" + Word.uppercase(tool)) == "true" &&
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   221
            (other_isabelle.isabelle_home + Path.explode("lib/Tools/" + tool)).is_file
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   222
        } other_isabelle(tool, echo = verbose)
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   223
64213
b265dd04d57d clarified file operations;
wenzelm
parents: 64194
diff changeset
   224
        Isabelle_System.rm_tree(isabelle_base_log)
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   225
      }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   226
64213
b265dd04d57d clarified file operations;
wenzelm
parents: 64194
diff changeset
   227
      Isabelle_System.rm_tree(isabelle_output)
72375
e48d93811ed7 clarified signature;
wenzelm
parents: 72020
diff changeset
   228
      Isabelle_System.make_directory(isabelle_output)
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   229
65909
4940682a2e1a more persistent build.out;
wenzelm
parents: 65889
diff changeset
   230
      val log_path =
4940682a2e1a more persistent build.out;
wenzelm
parents: 65889
diff changeset
   231
        other_isabelle.isabelle_home_user +
4940682a2e1a more persistent build.out;
wenzelm
parents: 65889
diff changeset
   232
          Build_Log.log_subdir(build_history_date) +
4940682a2e1a more persistent build.out;
wenzelm
parents: 65889
diff changeset
   233
          Build_Log.log_filename(Build_History.engine, build_history_date,
4940682a2e1a more persistent build.out;
wenzelm
parents: 65889
diff changeset
   234
            List(build_host, ml_platform, "M" + threads) ::: build_tags)
4940682a2e1a more persistent build.out;
wenzelm
parents: 65889
diff changeset
   235
72375
e48d93811ed7 clarified signature;
wenzelm
parents: 72020
diff changeset
   236
      Isabelle_System.make_directory(log_path.dir)
65927
23a1e2fa5c8a more progress information, for the sake of sporadic dropouts;
wenzelm
parents: 65917
diff changeset
   237
23a1e2fa5c8a more progress information, for the sake of sporadic dropouts;
wenzelm
parents: 65917
diff changeset
   238
      val build_out = other_isabelle.isabelle_home_user + Path.explode("log/build.out")
23a1e2fa5c8a more progress information, for the sake of sporadic dropouts;
wenzelm
parents: 65917
diff changeset
   239
      val build_out_progress = new File_Progress(build_out)
65909
4940682a2e1a more persistent build.out;
wenzelm
parents: 65889
diff changeset
   240
      build_out.file.delete
4940682a2e1a more persistent build.out;
wenzelm
parents: 65889
diff changeset
   241
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   242
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   243
      /* build */
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   244
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   245
      if (multicore_base && !first_build && isabelle_base_log.is_dir)
64189
dfb63036c4f6 tuned signature;
wenzelm
parents: 64188
diff changeset
   246
        Isabelle_System.copy_dir(isabelle_base_log, isabelle_output_log)
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   247
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   248
      val build_start = Date.now()
66862
136793b73c7c clarified stored build_args;
wenzelm
parents: 66861
diff changeset
   249
      val build_args1 = List("-v", "-j" + processes) ::: afp_build_args ::: build_args
71967
65ad3a6cee81 tuned --- avoid error in IntelliJ IDEA;
wenzelm
parents: 71726
diff changeset
   250
65ad3a6cee81 tuned --- avoid error in IntelliJ IDEA;
wenzelm
parents: 71726
diff changeset
   251
      val build_isabelle =
67045
6c94f749410a tuned signature;
wenzelm
parents: 66913
diff changeset
   252
        Other_Isabelle(root, isabelle_identifier = isabelle_identifier,
71967
65ad3a6cee81 tuned --- avoid error in IntelliJ IDEA;
wenzelm
parents: 71726
diff changeset
   253
          user_home = user_home, progress = build_out_progress)
65ad3a6cee81 tuned --- avoid error in IntelliJ IDEA;
wenzelm
parents: 71726
diff changeset
   254
      val build_result =
65ad3a6cee81 tuned --- avoid error in IntelliJ IDEA;
wenzelm
parents: 71726
diff changeset
   255
        build_isabelle("build " + Bash.strings(build_args1 ::: afp_sessions),
65ad3a6cee81 tuned --- avoid error in IntelliJ IDEA;
wenzelm
parents: 71726
diff changeset
   256
          redirect = true, echo = true, strict = false)
65ad3a6cee81 tuned --- avoid error in IntelliJ IDEA;
wenzelm
parents: 71726
diff changeset
   257
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   258
      val build_end = Date.now()
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   259
65646
014dbbe5331f parse ml_statistics only when required;
wenzelm
parents: 65624
diff changeset
   260
      val build_info: Build_Log.Build_Info =
69366
b6dacf6eabe3 clarified signature;
wenzelm
parents: 69304
diff changeset
   261
        Build_Log.Log_File(log_path.file_name, build_result.out_lines).
65646
014dbbe5331f parse ml_statistics only when required;
wenzelm
parents: 65624
diff changeset
   262
          parse_build_info(ml_statistics = true)
64296
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   263
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   264
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   265
      /* output log */
64120
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   266
68221
dbef88c2b6c5 support for build_database_server (PostgreSQL);
wenzelm
parents: 68219
diff changeset
   267
      val store = Sessions.store(options + "build_database_server=false")
65293
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   268
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   269
      val meta_info =
65624
32fa61f694ef clarified multi-line properties;
wenzelm
parents: 65596
diff changeset
   270
        Properties.lines_nonempty(Build_Log.Prop.build_tags.name, build_tags) :::
32fa61f694ef clarified multi-line properties;
wenzelm
parents: 65596
diff changeset
   271
        Properties.lines_nonempty(Build_Log.Prop.build_args.name, build_args1) :::
64296
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   272
        List(
65591
5953c7fbc2b8 more SQL operations;
wenzelm
parents: 65588
diff changeset
   273
          Build_Log.Prop.build_group_id.name -> build_group_id,
5953c7fbc2b8 more SQL operations;
wenzelm
parents: 65588
diff changeset
   274
          Build_Log.Prop.build_id.name -> (build_host + ":" + build_start.time.ms),
5953c7fbc2b8 more SQL operations;
wenzelm
parents: 65588
diff changeset
   275
          Build_Log.Prop.build_engine.name -> Build_History.engine,
5953c7fbc2b8 more SQL operations;
wenzelm
parents: 65588
diff changeset
   276
          Build_Log.Prop.build_host.name -> build_host,
5953c7fbc2b8 more SQL operations;
wenzelm
parents: 65588
diff changeset
   277
          Build_Log.Prop.build_start.name -> Build_Log.print_date(build_start),
5953c7fbc2b8 more SQL operations;
wenzelm
parents: 65588
diff changeset
   278
          Build_Log.Prop.build_end.name -> Build_Log.print_date(build_end),
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   279
          Build_Log.Prop.isabelle_version.name -> isabelle_version) :::
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   280
        afp_version.map(Build_Log.Prop.afp_version.name -> _).toList
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   281
66913
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   282
      build_out_progress.echo("Reading session build info ...")
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   283
      val session_build_info =
66874
0b8da0fc9563 store theory timings in session in build_log database;
wenzelm
parents: 66871
diff changeset
   284
        build_info.finished_sessions.flatMap(session_name =>
0b8da0fc9563 store theory timings in session in build_log database;
wenzelm
parents: 66871
diff changeset
   285
          {
0b8da0fc9563 store theory timings in session in build_log database;
wenzelm
parents: 66871
diff changeset
   286
            val database = isabelle_output + store.database(session_name)
0b8da0fc9563 store theory timings in session in build_log database;
wenzelm
parents: 66871
diff changeset
   287
66913
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   288
            if (database.is_file) {
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   289
              using(SQLite.open_database(database))(db =>
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   290
              {
72014
wenzelm
parents: 72013
diff changeset
   291
                val theory_timings =
wenzelm
parents: 72013
diff changeset
   292
                  try {
wenzelm
parents: 72013
diff changeset
   293
                    store.read_theory_timings(db, session_name).map(ps =>
wenzelm
parents: 72013
diff changeset
   294
                      Protocol.Theory_Timing_Marker((Build_Log.SESSION_NAME, session_name) :: ps))
wenzelm
parents: 72013
diff changeset
   295
                  }
wenzelm
parents: 72013
diff changeset
   296
                  catch { case ERROR(_) => Nil }
wenzelm
parents: 72013
diff changeset
   297
66913
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   298
                val session_sources =
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   299
                  store.read_build(db, session_name).map(_.sources) match {
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   300
                    case Some(sources) if sources.length == SHA1.digest_length =>
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   301
                      List("Sources " + session_name + " " + sources)
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   302
                    case _ => Nil
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   303
                  }
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   304
72020
ca69be5f60fe clarified messages: avoid duplicate Timing;
wenzelm
parents: 72018
diff changeset
   305
                theory_timings ::: session_sources
66913
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   306
              })
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   307
            }
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   308
            else Nil
66874
0b8da0fc9563 store theory timings in session in build_log database;
wenzelm
parents: 66871
diff changeset
   309
          })
0b8da0fc9563 store theory timings in session in build_log database;
wenzelm
parents: 66871
diff changeset
   310
65927
23a1e2fa5c8a more progress information, for the sake of sporadic dropouts;
wenzelm
parents: 65917
diff changeset
   311
      build_out_progress.echo("Reading ML statistics ...")
64119
8094eaa38d4b inline session ML statistics into main build log;
wenzelm
parents: 64118
diff changeset
   312
      val ml_statistics =
64120
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   313
        build_info.finished_sessions.flatMap(session_name =>
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   314
          {
65293
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   315
            val database = isabelle_output + store.database(session_name)
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   316
            val log_gz = isabelle_output + store.log_gz(session_name)
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   317
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   318
            val properties =
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   319
              if (database.is_file) {
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   320
                using(SQLite.open_database(database))(db =>
65935
73c099fa96a4 more selective database access;
wenzelm
parents: 65931
diff changeset
   321
                  store.read_ml_statistics(db, session_name))
65293
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   322
              }
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   323
              else if (log_gz.is_file) {
65318
342efc382558 eliminated somewhat redundant inlined name (despite a7aa17a1f721);
wenzelm
parents: 65296
diff changeset
   324
                Build_Log.Log_File(log_gz).parse_session_info(ml_statistics = true).ml_statistics
65293
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   325
              }
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   326
              else Nil
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   327
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   328
            val trimmed_properties =
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   329
              if (ml_statistics_step <= 0) Nil
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   330
              else if (ml_statistics_step == 1) properties
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   331
              else {
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   332
                (for { (ps, i) <- properties.iterator.zipWithIndex if i % ml_statistics_step == 0 }
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   333
                 yield ps).toList
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   334
              }
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   335
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   336
            trimmed_properties.map(ps => (Build_Log.SESSION_NAME -> session_name) :: ps)
64120
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   337
          })
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   338
65937
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   339
      build_out_progress.echo("Reading error messages ...")
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   340
      val session_errors =
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   341
        build_info.failed_sessions.flatMap(session_name =>
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   342
          {
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   343
            val database = isabelle_output + store.database(session_name)
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   344
            val errors =
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   345
              if (database.is_file) {
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   346
                try {
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   347
                  using(SQLite.open_database(database))(db => store.read_errors(db, session_name))
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   348
                } // column "errors" could be missing
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   349
                catch { case _: java.sql.SQLException => Nil }
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   350
              }
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   351
              else Nil
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   352
            errors.map(msg => List(Build_Log.SESSION_NAME -> session_name, Markup.CONTENT -> msg))
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   353
          })
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   354
65927
23a1e2fa5c8a more progress information, for the sake of sporadic dropouts;
wenzelm
parents: 65917
diff changeset
   355
      build_out_progress.echo("Reading heap sizes ...")
64120
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   356
      val heap_sizes =
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   357
        build_info.finished_sessions.flatMap(session_name =>
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   358
          {
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   359
            val heap = isabelle_output + Path.explode(session_name)
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   360
            if (heap.is_file)
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   361
              Some("Heap " + session_name + " (" + Value.Long(heap.file.length) + " bytes)")
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   362
            else None
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   363
          })
64119
8094eaa38d4b inline session ML statistics into main build log;
wenzelm
parents: 64118
diff changeset
   364
72575
c7ab83a0c564 tuned signature;
wenzelm
parents: 72375
diff changeset
   365
      build_out_progress.echo("Writing log file " + log_path.xz + " ...")
c7ab83a0c564 tuned signature;
wenzelm
parents: 72375
diff changeset
   366
      File.write_xz(log_path.xz,
64173
85ff21510ba9 tuned signature;
wenzelm
parents: 64162
diff changeset
   367
        terminate_lines(
71630
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71620
diff changeset
   368
          Protocol.Meta_Info_Marker(meta_info) :: build_result.out_lines :::
66913
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   369
          session_build_info :::
71630
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71620
diff changeset
   370
          ml_statistics.map(Protocol.ML_Statistics_Marker.apply) :::
50425e4c3910 clarified modules: global quasi-scope for markers;
wenzelm
parents: 71620
diff changeset
   371
          session_errors.map(Protocol.Error_Message_Marker.apply) :::
64253
a4718dfc9cd4 more compression for big log files;
wenzelm
parents: 64234
diff changeset
   372
          heap_sizes), XZ.options(6))
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   373
64119
8094eaa38d4b inline session ML statistics into main build log;
wenzelm
parents: 64118
diff changeset
   374
8094eaa38d4b inline session ML statistics into main build log;
wenzelm
parents: 64118
diff changeset
   375
      /* next build */
8094eaa38d4b inline session ML statistics into main build log;
wenzelm
parents: 64118
diff changeset
   376
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   377
      if (multicore_base && first_build && isabelle_output_log.is_dir)
64189
dfb63036c4f6 tuned signature;
wenzelm
parents: 64188
diff changeset
   378
        Isabelle_System.copy_dir(isabelle_output_log, isabelle_base_log)
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   379
64260
5389ebfd576d more thorough cleanup;
wenzelm
parents: 64256
diff changeset
   380
      Isabelle_System.rm_tree(isabelle_output)
5389ebfd576d more thorough cleanup;
wenzelm
parents: 64256
diff changeset
   381
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   382
      first_build = false
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   383
72575
c7ab83a0c564 tuned signature;
wenzelm
parents: 72375
diff changeset
   384
      (build_result, log_path.xz)
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   385
    }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   386
  }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   387
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   388
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   389
  /* command line entry point */
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   390
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   391
  private object Multicore
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   392
  {
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   393
    private val Pat1 = """^(\d+)$""".r
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   394
    private val Pat2 = """^(\d+)x(\d+)$""".r
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   395
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   396
    def parse(s: String): (Int, Int) =
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   397
      s match {
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   398
        case Pat1(Value.Int(x)) => (x, 1)
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   399
        case Pat2(Value.Int(x), Value.Int(y)) => (x, y)
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   400
        case _ => error("Bad multicore configuration: " + quote(s))
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   401
      }
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   402
  }
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   403
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 73242
diff changeset
   404
  def main(args: Array[String]): Unit =
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   405
  {
71632
c1bc38327bc2 clarified signature;
wenzelm
parents: 71630
diff changeset
   406
    Command_Line.tool {
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   407
      var afp_rev: Option[String] = None
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   408
      var multicore_base = false
69434
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69397
diff changeset
   409
      var components_base: Path = Components.default_components_base
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   410
      var heap: Option[Int] = None
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   411
      var max_heap: Option[Int] = None
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   412
      var multicore_list = List(default_multicore)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   413
      var isabelle_identifier = default_isabelle_identifier
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   414
      var afp_partition = 0
73240
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   415
      var component_repository = Components.default_component_repository
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   416
      var more_settings: List[String] = Nil
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   417
      var more_preferences: List[String] = Nil
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   418
      var fresh = false
69304
1f4afcde3334 more robust hostname for Isabelle cronjobs: do not rely on target OS installation for resulting build_log database content;
wenzelm
parents: 69253
diff changeset
   419
      var hostname = ""
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
   420
      var init_settings: List[String] = Nil
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   421
      var arch_64 = false
65844
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   422
      var output_file = ""
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   423
      var rev = default_rev
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   424
      var ml_statistics_step = 1
64297
12a47f263122 support for free-form build tags;
wenzelm
parents: 64296
diff changeset
   425
      var build_tags = List.empty[String]
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   426
      var user_home = default_user_home
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   427
      var verbose = false
65950
34c4cd9abc1a no exit code from build processes by default, e.g. relevant for non-strict results of remote_build_history;
wenzelm
parents: 65937
diff changeset
   428
      var exit_code = false
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   429
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   430
      val getopts = Getopts("""
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   431
Usage: Admin/build_history [OPTIONS] REPOSITORY [ARGS ...]
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   432
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   433
  Options are:
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   434
    -A REV       include $ISABELLE_HOME/AFP repository at given revision
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   435
    -B           first multicore build serves as base for scheduling information
69434
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69397
diff changeset
   436
    -C DIR       base directory for Isabelle components (default: """ +
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69397
diff changeset
   437
      Components.default_components_base + """)
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
   438
    -H SIZE      minimal ML heap in MB (default: """ + default_heap + """ for x86, """ +
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
   439
      default_heap * 2 + """ for x86_64)
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   440
    -M MULTICORE multicore configurations (see below)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   441
    -N NAME      alternative ISABELLE_IDENTIFIER (default: """ + default_isabelle_identifier + """)
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   442
    -P NUMBER    AFP partition number (0, 1, 2, default: 0=unrestricted)
73240
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   443
    -R URL       remote repository for Isabelle components (default: """ +
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   444
      Components.default_component_repository + """)
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   445
    -U SIZE      maximal ML heap in MB (default: unbounded)
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   446
    -e TEXT      additional text for generated etc/settings
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   447
    -f           fresh build of Isabelle/Scala components (recommended)
69304
1f4afcde3334 more robust hostname for Isabelle cronjobs: do not rely on target OS installation for resulting build_log database content;
wenzelm
parents: 69253
diff changeset
   448
    -h NAME      override local hostname
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
   449
    -i TEXT      initial text for generated etc/settings
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   450
    -m ARCH      processor architecture (32=x86, 64=x86_64, default: x86)
65844
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   451
    -o FILE      output file for log names (default: stdout)
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   452
    -p TEXT      additional text for generated etc/preferences
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   453
    -r REV       update to revision (default: """ + default_rev + """)
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   454
    -s NUMBER    step size for ML statistics (0=none, 1=all, n=step, default: 1)
64297
12a47f263122 support for free-form build tags;
wenzelm
parents: 64296
diff changeset
   455
    -t TAG       free-form build tag (multiple occurrences possible)
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   456
    -u DIR       alternative USER_HOME directory
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   457
    -v           verbose
65950
34c4cd9abc1a no exit code from build processes by default, e.g. relevant for non-strict results of remote_build_history;
wenzelm
parents: 65937
diff changeset
   458
    -x           return overall exit code from build processes
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   459
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   460
  Build Isabelle sessions from the history of another REPOSITORY clone,
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   461
  passing ARGS directly to its isabelle build tool.
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   462
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   463
  Each MULTICORE configuration consists of one or two numbers (default 1):
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   464
  THREADS or THREADSxPROCESSES, e.g. -M 1,2,4 or -M 1x4,2x2,4.
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   465
""",
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   466
        "A:" -> (arg => afp_rev = Some(arg)),
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   467
        "B" -> (_ => multicore_base = true),
69434
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69397
diff changeset
   468
        "C:" -> (arg => components_base = Path.explode(arg)),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   469
        "H:" -> (arg => heap = Some(Value.Int.parse(arg))),
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 69727
diff changeset
   470
        "M:" -> (arg => multicore_list = space_explode(',', arg).map(Multicore.parse)),
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   471
        "N:" -> (arg => isabelle_identifier = arg),
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   472
        "P:" -> (arg => afp_partition = Value.Int.parse(arg)),
73240
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   473
        "R:" -> (arg => component_repository = arg),
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   474
        "U:" -> (arg => max_heap = Some(Value.Int.parse(arg))),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   475
        "e:" -> (arg => more_settings = more_settings ::: List(arg)),
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   476
        "f" -> (_ => fresh = true),
69304
1f4afcde3334 more robust hostname for Isabelle cronjobs: do not rely on target OS installation for resulting build_log database content;
wenzelm
parents: 69253
diff changeset
   477
        "h:" -> (arg => hostname = arg),
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
   478
        "i:" -> (arg => init_settings = init_settings ::: List(arg)),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   479
        "m:" ->
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   480
          {
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   481
            case "32" | "x86" => arch_64 = false
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   482
            case "64" | "x86_64" => arch_64 = true
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   483
            case bad => error("Bad processor architecture: " + quote(bad))
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   484
          },
65844
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   485
        "o:" -> (arg => output_file = arg),
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   486
        "p:" -> (arg => more_preferences = more_preferences ::: List(arg)),
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   487
        "r:" -> (arg => rev = arg),
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   488
        "s:" -> (arg => ml_statistics_step = Value.Int.parse(arg)),
64297
12a47f263122 support for free-form build tags;
wenzelm
parents: 64296
diff changeset
   489
        "t:" -> (arg => build_tags = build_tags ::: List(arg)),
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   490
        "u:" -> (arg => user_home = Path.explode(arg)),
65950
34c4cd9abc1a no exit code from build processes by default, e.g. relevant for non-strict results of remote_build_history;
wenzelm
parents: 65937
diff changeset
   491
        "v" -> (_ => verbose = true),
34c4cd9abc1a no exit code from build processes by default, e.g. relevant for non-strict results of remote_build_history;
wenzelm
parents: 65937
diff changeset
   492
        "x" -> (_ => exit_code = true))
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   493
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   494
      val more_args = getopts(args)
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   495
      val (root, build_args) =
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   496
        more_args match {
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   497
          case root :: build_args => (Path.explode(root), build_args)
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   498
          case _ => getopts.usage()
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   499
        }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   500
64162
03057a8fdd1f simplified: no internal state for Mercurial;
wenzelm
parents: 64160
diff changeset
   501
      val progress = new Console_Progress(stderr = true)
64346
5f49765a25ec process results immediately;
wenzelm
parents: 64335
diff changeset
   502
64162
03057a8fdd1f simplified: no internal state for Mercurial;
wenzelm
parents: 64160
diff changeset
   503
      val results =
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   504
        build_history(Options.init(), root, user_home = user_home, progress = progress, rev = rev,
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   505
          afp_rev = afp_rev, afp_partition = afp_partition,
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   506
          isabelle_identifier = isabelle_identifier, ml_statistics_step = ml_statistics_step,
73240
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   507
          component_repository = component_repository, components_base = components_base,
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   508
          fresh = fresh, hostname = hostname, multicore_base = multicore_base,
3e963d68d394 more robust ISABELLE_COMPONENT_REPOSITORY: use current value of managing process to avoid its fluctuation in ancient history;
wenzelm
parents: 73184
diff changeset
   509
          multicore_list = multicore_list, arch_64 = arch_64,
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   510
          heap = heap.getOrElse(if (arch_64) default_heap * 2 else default_heap),
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
   511
          max_heap = max_heap, init_settings = init_settings, more_settings = more_settings,
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   512
          more_preferences = more_preferences, verbose = verbose, build_tags = build_tags,
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   513
          build_args = build_args)
64162
03057a8fdd1f simplified: no internal state for Mercurial;
wenzelm
parents: 64160
diff changeset
   514
65844
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   515
      if (output_file == "") {
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   516
        for ((_, log_path) <- results)
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   517
          Output.writeln(log_path.implode, stdout = true)
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   518
      }
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   519
      else {
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   520
        File.write(Path.explode(output_file),
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   521
          cat_lines(for ((_, log_path) <- results) yield log_path.implode))
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   522
      }
64472
c2191352e908 recovered Output.writeln for remote build_history (cf. ed8940d6295c), in order to have log files copied and removed;
wenzelm
parents: 64468
diff changeset
   523
73359
d8a0e996614b tuned --- fewer warnings;
wenzelm
parents: 73340
diff changeset
   524
      val rc = results.foldLeft(0) { case (rc, (res, _)) => rc max res.rc }
65950
34c4cd9abc1a no exit code from build processes by default, e.g. relevant for non-strict results of remote_build_history;
wenzelm
parents: 65937
diff changeset
   525
      if (rc != 0 && exit_code) sys.exit(rc)
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   526
    }
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   527
  }
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   528
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   529
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   530
64225
wenzelm
parents: 64223
diff changeset
   531
  /** remote build_history -- via command-line **/
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   532
64225
wenzelm
parents: 64223
diff changeset
   533
  def remote_build_history(
64256
c3197aeae90b simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents: 64253
diff changeset
   534
    ssh: SSH.Session,
64227
wenzelm
parents: 64225
diff changeset
   535
    isabelle_repos_self: Path,
wenzelm
parents: 64225
diff changeset
   536
    isabelle_repos_other: Path,
73611
cc36841eeff6 clarified signature: more operations;
wenzelm
parents: 73609
diff changeset
   537
    isabelle_repository: Mercurial.Server = Isabelle_System.isabelle_repository,
cc36841eeff6 clarified signature: more operations;
wenzelm
parents: 73609
diff changeset
   538
    afp_repository: Mercurial.Server = Isabelle_System.afp_repository,
65928
38eb5d633b0b avoid conflict with generated settings of other_isabelle;
wenzelm
parents: 65927
diff changeset
   539
    isabelle_identifier: String = "remote_build_history",
64227
wenzelm
parents: 64225
diff changeset
   540
    self_update: Boolean = false,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71632
diff changeset
   541
    progress: Progress = new Progress,
66106
b5333fc056da always start with fresh clone (with explicitly given rev): more robust on Windows;
wenzelm
parents: 65999
diff changeset
   542
    rev: String = "",
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   543
    afp_rev: Option[String] = None,
64227
wenzelm
parents: 64225
diff changeset
   544
    options: String = "",
65929
de3adcf6a276 prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents: 65928
diff changeset
   545
    args: String = ""): List[(String, Bytes)] =
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   546
  {
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   547
    /* Isabelle self repository */
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   548
67754
197366313aaf self_update implies push_isabelle_home (see also 4c253e84ae62);
wenzelm
parents: 67753
diff changeset
   549
    val self_hg =
73611
cc36841eeff6 clarified signature: more operations;
wenzelm
parents: 73609
diff changeset
   550
      Mercurial.setup_repository(isabelle_repository.root, isabelle_repos_self, ssh = ssh)
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   551
66877
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   552
    def execute(cmd: String, args: String, echo: Boolean = false, strict: Boolean = true): Unit =
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   553
      ssh.execute(
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   554
        Isabelle_System.export_isabelle_identifier(isabelle_identifier) +
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   555
          ssh.bash_path(isabelle_repos_self + Path.explode(cmd)) + " " + args,
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   556
        progress_stdout = progress.echo_if(echo, _),
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   557
        progress_stderr = progress.echo_if(echo, _),
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   558
        strict = strict).check
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   559
66106
b5333fc056da always start with fresh clone (with explicitly given rev): more robust on Windows;
wenzelm
parents: 65999
diff changeset
   560
    if (self_update) {
73522
b219774a71ae tuned signature -- more explicit types;
wenzelm
parents: 73359
diff changeset
   561
      val hg = Mercurial.repository(Path.ISABELLE_HOME)
67756
d2fe32ebe3c7 clarified self_update: imitate visible directory state on remote side;
wenzelm
parents: 67754
diff changeset
   562
      hg.push(self_hg.root_url, force = true)
d2fe32ebe3c7 clarified self_update: imitate visible directory state on remote side;
wenzelm
parents: 67754
diff changeset
   563
      self_hg.update(rev = hg.parent(), clean = true)
67754
197366313aaf self_update implies push_isabelle_home (see also 4c253e84ae62);
wenzelm
parents: 67753
diff changeset
   564
66877
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   565
      execute("bin/isabelle", "components -I")
66878
91da58bb560d tuned output;
wenzelm
parents: 66877
diff changeset
   566
      execute("bin/isabelle", "components -a", echo = true)
66877
4f0ccfe1bcb6 uniform execute, with proper isabelle_identifier (notably for "isabelle components -I");
wenzelm
parents: 66876
diff changeset
   567
      execute("Admin/build", "jars_fresh")
66106
b5333fc056da always start with fresh clone (with explicitly given rev): more robust on Windows;
wenzelm
parents: 65999
diff changeset
   568
    }
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   569
67773
4a7ed678785c more robust: normalize potentially symbolic rev;
wenzelm
parents: 67756
diff changeset
   570
    val rev_id = self_hg.id(rev)
4a7ed678785c more robust: normalize potentially symbolic rev;
wenzelm
parents: 67756
diff changeset
   571
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   572
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   573
    /* Isabelle other + AFP repository */
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   574
66570
9af879e222cc clarified signature;
wenzelm
parents: 66107
diff changeset
   575
    if (Mercurial.is_repository(isabelle_repos_other, ssh = ssh)) {
66107
8c8e77dbe6fe more robust: do not touch unrelated directory isabelle_repos_other (i.e. bad argument);
wenzelm
parents: 66106
diff changeset
   576
      ssh.rm_tree(isabelle_repos_other)
8c8e77dbe6fe more robust: do not touch unrelated directory isabelle_repos_other (i.e. bad argument);
wenzelm
parents: 66106
diff changeset
   577
    }
73006
b60c4ba462d4 tuned (see also b5333fc056da);
wenzelm
parents: 72575
diff changeset
   578
b60c4ba462d4 tuned (see also b5333fc056da);
wenzelm
parents: 72575
diff changeset
   579
    Mercurial.clone_repository(
b60c4ba462d4 tuned (see also b5333fc056da);
wenzelm
parents: 72575
diff changeset
   580
      ssh.bash_path(isabelle_repos_self), isabelle_repos_other, rev = rev_id, ssh = ssh)
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   581
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   582
    val afp_options =
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   583
      if (afp_rev.isEmpty) ""
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   584
      else {
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   585
        val afp_repos = isabelle_repos_other + Path.explode("AFP")
73611
cc36841eeff6 clarified signature: more operations;
wenzelm
parents: 73609
diff changeset
   586
        Mercurial.setup_repository(afp_repository.root, afp_repos, ssh = ssh)
73140
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   587
        " -A " + Bash.string(afp_rev.get)
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   588
      }
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   589
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   590
64256
c3197aeae90b simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents: 64253
diff changeset
   591
    /* Admin/build_history */
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   592
65846
aa6e58dc54d0 prefer explicit output file: potentially more robust than stdout;
wenzelm
parents: 65845
diff changeset
   593
    ssh.with_tmp_dir(tmp_dir =>
aa6e58dc54d0 prefer explicit output file: potentially more robust than stdout;
wenzelm
parents: 65845
diff changeset
   594
    {
aa6e58dc54d0 prefer explicit output file: potentially more robust than stdout;
wenzelm
parents: 65845
diff changeset
   595
      val output_file = tmp_dir + Path.explode("output")
64346
5f49765a25ec process results immediately;
wenzelm
parents: 64335
diff changeset
   596
73140
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   597
      val rev_options = if (rev == "") "" else " -r " + Bash.string(rev_id)
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   598
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   599
      try {
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   600
        execute("Admin/build_history",
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   601
          "-o " + ssh.bash_path(output_file) + rev_options + afp_options + " " + options + " " +
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   602
            ssh.bash_path(isabelle_repos_other) + " " + args,
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   603
          echo = true, strict = false)
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   604
      }
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   605
      catch {
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   606
        case ERROR(msg) =>
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   607
          cat_error(msg,
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   608
            "The error(s) above occurred for build_bistory " + rev_options + afp_options)
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   609
      }
64468
ed8940d6295c back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents: 64466
diff changeset
   610
65929
de3adcf6a276 prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents: 65928
diff changeset
   611
      for (line <- split_lines(ssh.read(output_file)))
de3adcf6a276 prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents: 65928
diff changeset
   612
      yield {
de3adcf6a276 prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents: 65928
diff changeset
   613
        val log = Path.explode(line)
de3adcf6a276 prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents: 65928
diff changeset
   614
        val bytes = ssh.read_bytes(log)
de3adcf6a276 prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents: 65928
diff changeset
   615
        ssh.rm(log)
69366
b6dacf6eabe3 clarified signature;
wenzelm
parents: 69304
diff changeset
   616
        (log.file_name, bytes)
65929
de3adcf6a276 prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents: 65928
diff changeset
   617
      }
65846
aa6e58dc54d0 prefer explicit output file: potentially more robust than stdout;
wenzelm
parents: 65845
diff changeset
   618
    })
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   619
  }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   620
}