src/Pure/Admin/build_history.scala
author wenzelm
Sat, 18 Nov 2023 16:58:14 +0100
changeset 78985 24e686fe043e
parent 78956 12abaffb0346
child 79546 c9774306a879
permissions -rw-r--r--
clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
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
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
    10
object Build_History {
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
    11
  /* log files */
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
    12
65588
b0d8d97198b3 clarified signature;
wenzelm
parents: 65320
diff changeset
    13
  val engine = "build_history"
65596
7fffa01b2d2b proper prefix;
wenzelm
parents: 65591
diff changeset
    14
  val log_prefix = engine + "_"
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
    15
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
    16
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    17
  /* augment settings */
64050
wenzelm
parents: 64049
diff changeset
    18
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    19
  def make_64_32(platform: String): String =
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    20
    platform.replace("x86_64-", "x86_64_32-").replace("arm64-", "arm64_32-")
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    21
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    22
  def augment_settings(
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    23
    other_isabelle: Other_Isabelle,
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    24
    threads: Int,
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
    25
    arch_64: Boolean,
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    26
    arch_apple: Boolean,
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
    27
    heap: Int,
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
    28
    max_heap: Option[Int],
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
    29
    more_settings: List[String]
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
    30
  ): String = {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
    31
    val (ml_platform, ml_settings) = {
73671
7404f2e1d092 clarified platforms;
wenzelm
parents: 73611
diff changeset
    32
      val cygwin_32 = "x86-cygwin"
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    33
      val windows_32 = "x86-windows"
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    34
      val windows_64 = "x86_64-windows"
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    35
      val windows_64_32 = "x86_64_32-windows"
69166
5c553c48c0e5 tuned signature;
wenzelm
parents: 68221
diff changeset
    36
      val platform_32 = other_isabelle.getenv("ISABELLE_PLATFORM32")
5c553c48c0e5 tuned signature;
wenzelm
parents: 68221
diff changeset
    37
      val platform_64 = other_isabelle.getenv("ISABELLE_PLATFORM64")
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    38
      val platform_64_32 = make_64_32(platform_64)
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    39
      val platform_apple_64 = other_isabelle.getenv("ISABELLE_APPLE_PLATFORM64")
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    40
      val platform_apple_64_32 = make_64_32(platform_apple_64)
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    41
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    42
      val polyml_home =
69166
5c553c48c0e5 tuned signature;
wenzelm
parents: 68221
diff changeset
    43
        try { Path.explode(other_isabelle.getenv("ML_HOME")).dir }
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    44
        catch { case ERROR(msg) => error("Bad ML_HOME: " + msg) }
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    45
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    46
      def ml_home(platform: String): Path = polyml_home + Path.explode(platform)
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
    47
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    48
      def err(platform: String): Nothing =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    49
        error("Platform " + platform + " unavailable on this machine")
64050
wenzelm
parents: 64049
diff changeset
    50
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    51
      def check_dir(platform: String): Boolean =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    52
        platform != "" && ml_home(platform).is_dir
64050
wenzelm
parents: 64049
diff changeset
    53
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    54
      val ml_platform =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    55
        if (Platform.is_windows && arch_64) {
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    56
          if (check_dir(windows_64)) windows_64 else err(windows_64)
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    57
        }
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    58
        else if (Platform.is_windows && !arch_64) {
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    59
          if (check_dir(windows_64_32)) windows_64_32
73671
7404f2e1d092 clarified platforms;
wenzelm
parents: 73611
diff changeset
    60
          else if (check_dir(cygwin_32)) cygwin_32
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    61
          else if (check_dir(windows_32)) windows_32
73671
7404f2e1d092 clarified platforms;
wenzelm
parents: 73611
diff changeset
    62
          else err(windows_32)
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    63
        }
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    64
        else if (arch_apple && arch_64) {
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    65
          if (check_dir(platform_apple_64)) platform_apple_64 else err(platform_apple_64)
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    66
        }
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    67
        else if (arch_apple) {
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    68
          if (check_dir(platform_apple_64_32)) platform_apple_64_32 else err(platform_apple_64_32)
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
    69
        }
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    70
        else if (arch_64) {
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    71
          if (check_dir(platform_64)) platform_64 else err(platform_64)
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    72
        }
69727
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    73
        else if (check_dir(platform_64_32)) platform_64_32
55dc07077c6b prefer x86_64_32 over x86;
wenzelm
parents: 69434
diff changeset
    74
        else platform_32
64050
wenzelm
parents: 64049
diff changeset
    75
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    76
      val ml_options =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    77
        "--minheap " + heap + (if (max_heap.isDefined) " --maxheap " + max_heap.get else "") +
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    78
        " --gcthreads " + threads +
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    79
        (if (ml_platform.endsWith("-windows")) " --codepage utf8" else "")
64050
wenzelm
parents: 64049
diff changeset
    80
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    81
      (ml_platform,
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    82
        List(
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    83
          "ML_HOME=" + File.bash_path(ml_home(ml_platform)),
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    84
          "ML_PLATFORM=" + quote(ml_platform),
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    85
          "ML_OPTIONS=" + quote(ml_options)))
64050
wenzelm
parents: 64049
diff changeset
    86
    }
wenzelm
parents: 64049
diff changeset
    87
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    88
    val thread_settings =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    89
      List(
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    90
        "ISABELLE_JAVA_SYSTEM_OPTIONS=\"$ISABELLE_JAVA_SYSTEM_OPTIONS -Disabelle.threads=" + threads + "\"",
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    91
        "ISABELLE_BUILD_OPTIONS=\"threads=" + threads + "\"")
64050
wenzelm
parents: 64049
diff changeset
    92
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    93
    val settings =
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    94
      List(ml_settings, thread_settings) :::
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
    95
      (if (more_settings.isEmpty) Nil else List(more_settings))
64050
wenzelm
parents: 64049
diff changeset
    96
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    97
    File.append(other_isabelle.etc_settings, "\n" + cat_lines(settings.map(terminate_lines(_))))
64050
wenzelm
parents: 64049
diff changeset
    98
64188
f88bae1922c4 clarified modules;
wenzelm
parents: 64173
diff changeset
    99
    ml_platform
64049
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   100
  }
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   101
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   102
ac3ed62c53c3 misc tuning and clarification;
wenzelm
parents: 64048
diff changeset
   103
75549
4b21e823d35f clarified names;
wenzelm
parents: 75544
diff changeset
   104
  /** local build **/
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   105
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   106
  private val default_multicore = (1, 1)
64335
24e676390259 more ambitious default;
wenzelm
parents: 64305
diff changeset
   107
  private val default_heap = 1500
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   108
  private val default_isabelle_identifier = "build_history"
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   109
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   110
  def local_build(
66861
f6676691ef8a partition AFP sessions according to structure, which happens to cut it roughly into equal parts;
wenzelm
parents: 66860
diff changeset
   111
    options: Options,
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   112
    root: Path,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71632
diff changeset
   113
    progress: Progress = new Progress,
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   114
    afp: Boolean = false,
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   115
    isabelle_identifier: String = default_isabelle_identifier,
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   116
    ml_statistics_step: Int = 1,
77128
f40c36ab154d clarified names to emphasize suble differences in meaning;
wenzelm
parents: 77127
diff changeset
   117
    component_repository: String = Components.static_component_repository,
f40c36ab154d clarified names to emphasize suble differences in meaning;
wenzelm
parents: 77127
diff changeset
   118
    components_base: String = Components.dynamic_components_base,
78610
fd1fec53665b clarified signature: prefer enum types;
wenzelm
parents: 78492
diff changeset
   119
    clean_platforms: Option[List[Platform.Family]] = None,
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   120
    clean_archives: Boolean = false,
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   121
    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
   122
    hostname: String = "",
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   123
    multicore_base: Boolean = false,
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   124
    multicore_list: List[(Int, Int)] = List(default_multicore),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   125
    arch_64: Boolean = false,
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   126
    arch_apple: Boolean = false,
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   127
    heap: Int = default_heap,
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   128
    max_heap: Option[Int] = None,
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   129
    more_settings: List[String] = Nil,
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   130
    more_preferences: List[String] = Nil,
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   131
    verbose: Boolean = false,
64297
12a47f263122 support for free-form build tags;
wenzelm
parents: 64296
diff changeset
   132
    build_tags: List[String] = Nil,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
   133
    build_args: List[String] = Nil
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
   134
  ): List[(Process_Result, Path)] = {
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   135
    /* sanity checks */
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   136
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   137
    if (File.eq(Path.ISABELLE_HOME, root)) {
73522
b219774a71ae tuned signature -- more explicit types;
wenzelm
parents: 73359
diff changeset
   138
      error("Repository coincides with ISABELLE_HOME=" + Path.ISABELLE_HOME.expand)
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   139
    }
64046
5a6a7401c48b clarified sanity checks;
wenzelm
parents: 64044
diff changeset
   140
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   141
    for ((threads, _) <- multicore_list if threads < 1) {
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   142
      error("Bad threads value < 1: " + threads)
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   143
    }
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   144
    for ((_, processes) <- multicore_list if processes < 1) {
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   145
      error("Bad processes value < 1: " + processes)
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   146
    }
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   147
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   148
    if (heap < 100) error("Bad heap value < 100: " + heap)
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   149
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   150
    if (max_heap.isDefined && max_heap.get < heap) {
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   151
      error("Bad max_heap value < heap: " + max_heap.get)
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   152
    }
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   153
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   154
    System.getenv("ISABELLE_SETTINGS_PRESENT") match {
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   155
      case null | "" =>
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   156
      case _ => error("Cannot run Admin/build_other within existing Isabelle settings environment")
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   157
    }
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   158
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   159
75549
4b21e823d35f clarified names;
wenzelm
parents: 75544
diff changeset
   160
    /* Isabelle + AFP directory */
64031
eef8a3f8ef4a more sanity checks;
wenzelm
parents: 64030
diff changeset
   161
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   162
    def directory(dir: Path): Mercurial.Hg_Sync.Directory = {
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   163
      val directory = Mercurial.Hg_Sync.directory(dir)
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   164
      if (verbose) progress.echo(directory.log)
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   165
      directory
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   166
    }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   167
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   168
    val isabelle_directory = directory(root)
78618
209607465a90 discontinue odd AFP partitioning: let Build_Cluster / Build_Engine do the job;
wenzelm
parents: 78610
diff changeset
   169
    val (afp_directory, afp_build_args) =
209607465a90 discontinue odd AFP partitioning: let Build_Cluster / Build_Engine do the job;
wenzelm
parents: 78610
diff changeset
   170
      if (afp) (Some(directory(root + Path.explode("AFP"))), List("-d", "~~/AFP/thys"))
209607465a90 discontinue odd AFP partitioning: let Build_Cluster / Build_Engine do the job;
wenzelm
parents: 78610
diff changeset
   171
      else (None, Nil)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   172
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   173
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   174
    /* main */
64043
44b6c620c371 more thorought update of components;
wenzelm
parents: 64040
diff changeset
   175
67045
6c94f749410a tuned signature;
wenzelm
parents: 66913
diff changeset
   176
    val other_isabelle =
77075
973de7855948 removed unused user_home argument (see also 897f1ac84aab and 19b6091c2137);
wenzelm
parents: 77074
diff changeset
   177
      Other_Isabelle(root, isabelle_identifier = isabelle_identifier, progress = progress)
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   178
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   179
    def resolve_components(): Unit =
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   180
      other_isabelle.resolve_components(
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   181
        echo = verbose,
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   182
        component_repository = component_repository,
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   183
        clean_platforms = clean_platforms,
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   184
        clean_archives = clean_archives)
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   185
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
   186
    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
   187
    val build_history_date = Date.now()
64296
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   188
    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
   189
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   190
    var first_build = true
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
   191
    for ((threads, processes) <- multicore_list) yield {
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   192
      /* init settings */
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   193
69388
fc58534bc475 clarified component settings;
wenzelm
parents: 69387
diff changeset
   194
      val component_settings =
69434
b93404a4c3dd clarified settings and defaults;
wenzelm
parents: 69397
diff changeset
   195
        other_isabelle.init_components(
77091
15e710116a16 recovered option -C from 092449efcb0e (still required for isabelle_cronjob.scala on Windows), but with slightly different meaning;
wenzelm
parents: 77088
diff changeset
   196
          components_base = components_base,
77055
f56800b8b085 clarified defaults;
wenzelm
parents: 77051
diff changeset
   197
          catalogs = Components.optional_catalogs)
77129
c79da77d9e87 obsolete (see also d547173212d2);
wenzelm
parents: 77128
diff changeset
   198
      other_isabelle.init_settings(component_settings)
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   199
      resolve_components()
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   200
      val ml_platform =
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   201
        augment_settings(
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   202
          other_isabelle, threads, arch_64, arch_apple, heap, max_heap, more_settings)
64043
44b6c620c371 more thorought update of components;
wenzelm
parents: 64040
diff changeset
   203
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   204
      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
   205
68219
c0341c0080e2 clarified store directories;
wenzelm
parents: 68209
diff changeset
   206
      val isabelle_output =
77080
7e11e96a922d more formal Other_Isabelle.settings, with derived expand_path / bash_path;
wenzelm
parents: 77075
diff changeset
   207
        other_isabelle.expand_path(
7e11e96a922d more formal Other_Isabelle.settings, with derived expand_path / bash_path;
wenzelm
parents: 77075
diff changeset
   208
          Path.explode("$ISABELLE_HOME_USER/heaps/$ML_IDENTIFIER"))
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   209
      val isabelle_output_log = isabelle_output + Path.explode("log")
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   210
      val isabelle_base_log = isabelle_output + Path.explode("../base_log")
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   211
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   212
      if (first_build) {
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   213
        resolve_components()
77072
e8010cb36820 more robust and uniform Other_Isabelle.scala_build;
wenzelm
parents: 77055
diff changeset
   214
        other_isabelle.scala_build(fresh = fresh, echo = verbose)
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   215
69253
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   216
        for {
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   217
          tool <- List("ghc_setup", "ocaml_setup")
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   218
          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
   219
            (other_isabelle.isabelle_home + Path.explode("lib/Tools/" + tool)).is_file
77044
a4380a2d6d2c tuned signature: avoid aliases;
wenzelm
parents: 76367
diff changeset
   220
        } other_isabelle.bash("bin/isabelle " + tool, echo = verbose)
69253
8bfa615ddde4 proper ghc_setup / ocaml_setup on target Isabelle distribution (amending 2a17c481d05e);
wenzelm
parents: 69243
diff changeset
   221
64213
b265dd04d57d clarified file operations;
wenzelm
parents: 64194
diff changeset
   222
        Isabelle_System.rm_tree(isabelle_base_log)
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   223
      }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   224
64213
b265dd04d57d clarified file operations;
wenzelm
parents: 64194
diff changeset
   225
      Isabelle_System.rm_tree(isabelle_output)
72375
e48d93811ed7 clarified signature;
wenzelm
parents: 72020
diff changeset
   226
      Isabelle_System.make_directory(isabelle_output)
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   227
77080
7e11e96a922d more formal Other_Isabelle.settings, with derived expand_path / bash_path;
wenzelm
parents: 77075
diff changeset
   228
      other_isabelle.expand_path(Path.explode("$ISABELLE_HOME_USER/mash_state")).file.delete
76367
3ace8ac64f20 more thorough cleanup;
wenzelm
parents: 76366
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
77080
7e11e96a922d more formal Other_Isabelle.settings, with derived expand_path / bash_path;
wenzelm
parents: 77075
diff changeset
   238
      val build_out = other_isabelle.expand_path(Path.explode("$ISABELLE_HOME_USER/log/build.out"))
65927
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
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
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)
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   247
      }
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   248
64117
c2b41b073d8a build_history log files with formal meta info;
wenzelm
parents: 64052
diff changeset
   249
      val build_start = Date.now()
66862
136793b73c7c clarified stored build_args;
wenzelm
parents: 66861
diff changeset
   250
      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
   251
77074
wenzelm
parents: 77072
diff changeset
   252
      val build_result =
67045
6c94f749410a tuned signature;
wenzelm
parents: 66913
diff changeset
   253
        Other_Isabelle(root, isabelle_identifier = isabelle_identifier,
77075
973de7855948 removed unused user_home argument (see also 897f1ac84aab and 19b6091c2137);
wenzelm
parents: 77074
diff changeset
   254
          progress = build_out_progress)
78618
209607465a90 discontinue odd AFP partitioning: let Build_Cluster / Build_Engine do the job;
wenzelm
parents: 78610
diff changeset
   255
        .bash("bin/isabelle build " + Bash.strings(build_args1),
71967
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
78985
24e686fe043e clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents: 78956
diff changeset
   260
      val store = Store(options + "build_database_server=false")
24e686fe043e clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents: 78956
diff changeset
   261
65646
014dbbe5331f parse ml_statistics only when required;
wenzelm
parents: 65624
diff changeset
   262
      val build_info: Build_Log.Build_Info =
78985
24e686fe043e clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents: 78956
diff changeset
   263
        Build_Log.Log_File(log_path.file_name, build_result.out_lines, cache = store.cache).
65646
014dbbe5331f parse ml_statistics only when required;
wenzelm
parents: 65624
diff changeset
   264
          parse_build_info(ml_statistics = true)
64296
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   265
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   266
544481988e65 explicit identification of builds and correlated build groups;
wenzelm
parents: 64263
diff changeset
   267
      /* output log */
64120
6c5039016321 record heap sizes;
wenzelm
parents: 64119
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),
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   279
          Build_Log.Prop.isabelle_version.name -> isabelle_directory.id) :::
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   280
        afp_directory.map(dir => Build_Log.Prop.afp_version.name -> dir.id).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 =
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   284
        build_info.finished_sessions.flatMap { session_name =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   285
          val database = isabelle_output + store.database(session_name)
66874
0b8da0fc9563 store theory timings in session in build_log database;
wenzelm
parents: 66871
diff changeset
   286
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   287
          if (database.is_file) {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   288
            using(SQLite.open_database(database)) { db =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   289
              val theory_timings =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   290
                try {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   291
                  store.read_theory_timings(db, session_name).map(ps =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   292
                    Protocol.Theory_Timing_Marker((Build_Log.SESSION_NAME, session_name) :: ps))
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   293
                }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   294
                catch { case ERROR(_) => Nil }
72014
wenzelm
parents: 72013
diff changeset
   295
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   296
              val session_sources =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   297
                store.read_build(db, session_name).map(_.sources) match {
77207
d98a99e4eea9 proper Shasum.digest, to emulate old form from build_history database;
wenzelm
parents: 77132
diff changeset
   298
                  case Some(sources) if !sources.is_empty =>
d98a99e4eea9 proper Shasum.digest, to emulate old form from build_history database;
wenzelm
parents: 77132
diff changeset
   299
                    List("Sources " + session_name + " " + sources.digest.toString)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   300
                  case _ => Nil
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   301
                }
66913
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   302
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   303
              theory_timings ::: session_sources
66913
7cdd4d59e95c store session sources stamp;
wenzelm
parents: 66878
diff changeset
   304
            }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   305
          }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   306
          else Nil
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   307
        }
66874
0b8da0fc9563 store theory timings in session in build_log database;
wenzelm
parents: 66871
diff changeset
   308
65927
23a1e2fa5c8a more progress information, for the sake of sporadic dropouts;
wenzelm
parents: 65917
diff changeset
   309
      build_out_progress.echo("Reading ML statistics ...")
64119
8094eaa38d4b inline session ML statistics into main build log;
wenzelm
parents: 64118
diff changeset
   310
      val ml_statistics =
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   311
        build_info.finished_sessions.flatMap { session_name =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   312
          val database = isabelle_output + store.database(session_name)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   313
          val log_gz = isabelle_output + store.log_gz(session_name)
65293
a53a5ae88205 prefer database, but also accept log.gz from historic versions;
wenzelm
parents: 64909
diff changeset
   314
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   315
          val properties =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   316
            if (database.is_file) {
78162
wenzelm
parents: 77799
diff changeset
   317
              using(SQLite.open_database(database))(store.read_ml_statistics(_, session_name))
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   318
            }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   319
            else if (log_gz.is_file) {
78985
24e686fe043e clarified Log_File.cache: reuse existing Store.cache / Build_Log.Store.cache;
wenzelm
parents: 78956
diff changeset
   320
              Build_Log.Log_File.read(log_gz.file, cache = store.cache)
78867
b02f8fb6b1b6 clarified signature;
wenzelm
parents: 78618
diff changeset
   321
                .parse_session_info(ml_statistics = true).ml_statistics
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   322
            }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   323
            else Nil
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   324
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   325
          val trimmed_properties =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   326
            if (ml_statistics_step <= 0) Nil
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   327
            else if (ml_statistics_step == 1) properties
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   328
            else {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   329
              (for { (ps, i) <- properties.iterator.zipWithIndex if i % ml_statistics_step == 0 }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   330
               yield ps).toList
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   331
            }
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   332
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   333
          trimmed_properties.map(ps => (Build_Log.SESSION_NAME -> session_name) :: ps)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   334
        }
64120
6c5039016321 record heap sizes;
wenzelm
parents: 64119
diff changeset
   335
65937
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   336
      build_out_progress.echo("Reading error messages ...")
fde7b5d209d5 store errors in build_history logs and database;
wenzelm
parents: 65935
diff changeset
   337
      val session_errors =
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   338
        build_info.failed_sessions.flatMap { session_name =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   339
          val database = isabelle_output + store.database(session_name)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   340
          val errors =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   341
            if (database.is_file) {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   342
              try {
78162
wenzelm
parents: 77799
diff changeset
   343
                using(SQLite.open_database(database))(store.read_errors(_, session_name))
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   344
              } // column "errors" could be missing
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   345
              catch { case _: java.sql.SQLException => Nil }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   346
            }
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   347
            else Nil
77799
3fb2c47a7605 more robust: avoid crash of Build_Log.parse_build_info / Protocol.Error_Message_Marker, e.g. in session MDP-Rewards of Isabelle/26ec258e5cf8 + AFP/2859e11cc09b;
wenzelm
parents: 77792
diff changeset
   348
          for (msg <- errors)
3fb2c47a7605 more robust: avoid crash of Build_Log.parse_build_info / Protocol.Error_Message_Marker, e.g. in session MDP-Rewards of Isabelle/26ec258e5cf8 + AFP/2859e11cc09b;
wenzelm
parents: 77792
diff changeset
   349
          yield {
3fb2c47a7605 more robust: avoid crash of Build_Log.parse_build_info / Protocol.Error_Message_Marker, e.g. in session MDP-Rewards of Isabelle/26ec258e5cf8 + AFP/2859e11cc09b;
wenzelm
parents: 77792
diff changeset
   350
            val content = Library.encode_lines(Output.clean_yxml(msg))
3fb2c47a7605 more robust: avoid crash of Build_Log.parse_build_info / Protocol.Error_Message_Marker, e.g. in session MDP-Rewards of Isabelle/26ec258e5cf8 + AFP/2859e11cc09b;
wenzelm
parents: 77792
diff changeset
   351
            List(Build_Log.SESSION_NAME -> session_name, Markup.CONTENT -> content)
3fb2c47a7605 more robust: avoid crash of Build_Log.parse_build_info / Protocol.Error_Message_Marker, e.g. in session MDP-Rewards of Isabelle/26ec258e5cf8 + AFP/2859e11cc09b;
wenzelm
parents: 77792
diff changeset
   352
          }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   353
        }
65937
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 =
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   357
        build_info.finished_sessions.flatMap { session_name =>
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   358
          val heap = isabelle_output + Path.explode(session_name)
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   359
          if (heap.is_file) {
78956
12abaffb0346 tuned signature: more operations;
wenzelm
parents: 78918
diff changeset
   360
            Some("Heap " + session_name + " (" + Value.Long(File.size(heap)) + " bytes)")
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   361
          }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   362
          else None
42267c650205 tuned formatting;
wenzelm
parents: 75393
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) :::
76351
2cee31cd92f0 generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents: 76136
diff changeset
   372
          heap_sizes), Compress.Options_XZ(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
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
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)
76365
24e951a8a318 tuned: more robust Scala syntax;
wenzelm
parents: 76351
diff changeset
   379
      }
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   380
64260
5389ebfd576d more thorough cleanup;
wenzelm
parents: 64256
diff changeset
   381
      Isabelle_System.rm_tree(isabelle_output)
5389ebfd576d more thorough cleanup;
wenzelm
parents: 64256
diff changeset
   382
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   383
      first_build = false
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   384
72575
c7ab83a0c564 tuned signature;
wenzelm
parents: 72375
diff changeset
   385
      (build_result, log_path.xz)
64051
4dd9d9b28fd5 allow multiple threads configurations;
wenzelm
parents: 64050
diff changeset
   386
    }
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   387
  }
64021
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
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   390
  /* command line entry point */
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   391
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
   392
  private object Multicore {
64301
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
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
   404
  def main(args: Array[String]): Unit = {
71632
c1bc38327bc2 clarified signature;
wenzelm
parents: 71630
diff changeset
   405
    Command_Line.tool {
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   406
      var afp = false
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   407
      var multicore_base = false
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   408
      var heap: Option[Int] = None
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   409
      var max_heap: Option[Int] = None
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   410
      var multicore_list = List(default_multicore)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   411
      var isabelle_identifier = default_isabelle_identifier
78610
fd1fec53665b clarified signature: prefer enum types;
wenzelm
parents: 78492
diff changeset
   412
      var clean_platforms: Option[List[Platform.Family]] = None
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   413
      var clean_archives = false
77128
f40c36ab154d clarified names to emphasize suble differences in meaning;
wenzelm
parents: 77127
diff changeset
   414
      var component_repository = Components.static_component_repository
78918
8378354bbdad avoid option -C: free this latter for build-related configuration;
wenzelm
parents: 78867
diff changeset
   415
      var components_base = Components.dynamic_components_base
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   416
      var arch_apple = false
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   417
      var more_settings: List[String] = Nil
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   418
      var more_preferences: List[String] = Nil
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   419
      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
   420
      var hostname = ""
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 = ""
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   423
      var ml_statistics_step = 1
64297
12a47f263122 support for free-form build tags;
wenzelm
parents: 64296
diff changeset
   424
      var build_tags = List.empty[String]
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   425
      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
   426
      var exit_code = false
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   427
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   428
      val getopts = Getopts("""
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   429
Usage: Admin/build_other [OPTIONS] ISABELLE_HOME [ARGS ...]
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   430
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   431
  Options are:
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   432
    -A           include $ISABELLE_HOME/AFP directory
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   433
    -B           first multicore build serves as base for scheduling information
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   434
    -H SIZE      minimal ML heap in MB (default: """ + default_heap + """ for 32bit, """ +
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   435
      default_heap * 2 + """ for 64bit)
64301
8053c882839f more flexible multicore configuration;
wenzelm
parents: 64300
diff changeset
   436
    -M MULTICORE multicore configurations (see below)
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   437
    -N NAME      alternative ISABELLE_IDENTIFIER (default: """ + default_isabelle_identifier + """)
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   438
    -O PLATFORMS clean resolved components, retaining only the given list
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   439
                 platform families (separated by commas; default: do nothing)
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   440
    -Q           clean archives of downloaded 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
   441
    -R URL       remote repository for Isabelle components (default: """ +
77128
f40c36ab154d clarified names to emphasize suble differences in meaning;
wenzelm
parents: 77127
diff changeset
   442
      Components.static_component_repository + """)
78918
8378354bbdad avoid option -C: free this latter for build-related configuration;
wenzelm
parents: 78867
diff changeset
   443
    -S DIR       base directory for Isabelle components (default: """ +
8378354bbdad avoid option -C: free this latter for build-related configuration;
wenzelm
parents: 78867
diff changeset
   444
      quote(Components.dynamic_components_base) + """)
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   445
    -U SIZE      maximal ML heap in MB (default: unbounded)
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   446
    -a           processor architecture is Apple Silicon (ARM64)
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   447
    -e TEXT      additional text for generated etc/settings
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   448
    -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
   449
    -h NAME      override local hostname
65843
d547173212d2 proper init_settings for init_component (before generated ML_OPTIONS etc.);
wenzelm
parents: 65646
diff changeset
   450
    -i TEXT      initial text for generated etc/settings
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   451
    -m ARCH      processor architecture (32, 64, default: 32)
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   452
    -n           no build: sync only
65844
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   453
    -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
   454
    -p TEXT      additional text for generated etc/preferences
66867
b00d8e1f8ddd added ml_statistics_step to trim stored properties;
wenzelm
parents: 66866
diff changeset
   455
    -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
   456
    -t TAG       free-form build tag (multiple occurrences possible)
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
""",
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   466
        "A" -> (_ => afp = true),
64052
72fa79eab7f6 added multicore_base option;
wenzelm
parents: 64051
diff changeset
   467
        "B" -> (_ => multicore_base = true),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   468
        "H:" -> (arg => heap = Some(Value.Int.parse(arg))),
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 69727
diff changeset
   469
        "M:" -> (arg => multicore_list = space_explode(',', arg).map(Multicore.parse)),
64025
ff4910ced9ba clarified command-line;
wenzelm
parents: 64023
diff changeset
   470
        "N:" -> (arg => isabelle_identifier = arg),
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   471
        "O:" -> (arg => clean_platforms = Some(space_explode(',',arg).map(Platform.Family.parse))),
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   472
        "Q" -> (_ => clean_archives = true),
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),
78918
8378354bbdad avoid option -C: free this latter for build-related configuration;
wenzelm
parents: 78867
diff changeset
   474
        "S:" -> (arg => components_base = arg),
64036
a14fe26c0144 clarified heap options;
wenzelm
parents: 64034
diff changeset
   475
        "U:" -> (arg => max_heap = Some(Value.Int.parse(arg))),
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   476
        "a" -> (_ => arch_apple = true),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   477
        "e:" -> (arg => more_settings = more_settings ::: List(arg)),
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   478
        "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
   479
        "h:" -> (arg => hostname = arg),
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   480
        "m:" ->
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   481
          {
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   482
            case "32" => arch_64 = false
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   483
            case "64" => arch_64 = true
64030
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   484
            case bad => error("Bad processor architecture: " + quote(bad))
04f9e1e9003a more options for generated settings;
wenzelm
parents: 64027
diff changeset
   485
          },
65844
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   486
        "o:" -> (arg => output_file = arg),
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   487
        "p:" -> (arg => more_preferences = more_preferences ::: List(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)),
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
   490
        "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
   491
        "x" -> (_ => exit_code = true))
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   492
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   493
      val more_args = getopts(args)
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   494
      val (root, build_args) =
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   495
        more_args match {
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   496
          case root :: build_args => (Path.explode(root), build_args)
64026
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   497
          case _ => getopts.usage()
cbecd26e063f clarified command line;
wenzelm
parents: 64025
diff changeset
   498
        }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   499
64162
03057a8fdd1f simplified: no internal state for Mercurial;
wenzelm
parents: 64160
diff changeset
   500
      val progress = new Console_Progress(stderr = true)
64346
5f49765a25ec process results immediately;
wenzelm
parents: 64335
diff changeset
   501
64162
03057a8fdd1f simplified: no internal state for Mercurial;
wenzelm
parents: 64160
diff changeset
   502
      val results =
78618
209607465a90 discontinue odd AFP partitioning: let Build_Cluster / Build_Engine do the job;
wenzelm
parents: 78610
diff changeset
   503
        local_build(Options.init(), root, progress = progress, afp = afp,
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   504
          isabelle_identifier = isabelle_identifier, ml_statistics_step = ml_statistics_step,
77091
15e710116a16 recovered option -C from 092449efcb0e (still required for isabelle_cronjob.scala on Windows), but with slightly different meaning;
wenzelm
parents: 77088
diff changeset
   505
          component_repository = component_repository, components_base = components_base,
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   506
          clean_platforms = clean_platforms, clean_archives = clean_archives,
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
          fresh = fresh, hostname = hostname, multicore_base = multicore_base,
78492
aeda5a004d89 proper support for Apple Silicon (ARM64);
wenzelm
parents: 78439
diff changeset
   508
          multicore_list = multicore_list, arch_64 = arch_64, arch_apple = arch_apple,
67047
19b6091c2137 support alternative USER_HOME directory;
wenzelm
parents: 67045
diff changeset
   509
          heap = heap.getOrElse(if (arch_64) default_heap * 2 else default_heap),
77129
c79da77d9e87 obsolete (see also d547173212d2);
wenzelm
parents: 77128
diff changeset
   510
          max_heap = max_heap, more_settings = more_settings,
71998
f43b08980f56 support generated preferences, i.e. non-strict system options;
wenzelm
parents: 71967
diff changeset
   511
          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
   512
          build_args = build_args)
64162
03057a8fdd1f simplified: no internal state for Mercurial;
wenzelm
parents: 64160
diff changeset
   513
76366
wenzelm
parents: 76365
diff changeset
   514
      if (output_file.isEmpty) {
wenzelm
parents: 76365
diff changeset
   515
        for ((_, log_path) <- results) Output.writeln(log_path.implode, stdout = true)
65844
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   516
      }
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   517
      else {
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   518
        File.write(Path.explode(output_file),
76e60a142ca1 support for explicit output file: potentially more robust than stdout;
wenzelm
parents: 65843
diff changeset
   519
          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
   520
      }
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
   521
78439
001d423daf7c prefer Process_Result.RC.merge: strict treatment of interrupt;
wenzelm
parents: 78178
diff changeset
   522
      val rc = Process_Result.RC.merge(results.map(p => p._1.rc))
74306
a117c076aa22 clarified signature;
wenzelm
parents: 74036
diff changeset
   523
      if (rc != Process_Result.RC.ok && exit_code) sys.exit(rc)
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   524
    }
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   525
  }
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   526
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   527
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   528
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   529
  /** remote build -- via rsync and ssh **/
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   530
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   531
  def remote_build(
64256
c3197aeae90b simplified SSH.Session: sftp channel is always open and its operations provided by the main interface;
wenzelm
parents: 64253
diff changeset
   532
    ssh: SSH.Session,
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   533
    isabelle_self: Path,
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   534
    isabelle_other: Path,
65928
38eb5d633b0b avoid conflict with generated settings of other_isabelle;
wenzelm
parents: 65927
diff changeset
   535
    isabelle_identifier: String = "remote_build_history",
77132
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   536
    component_repository: String = Components.static_component_repository,
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   537
    components_base: String = Components.dynamic_components_base,
77131
c8d34e74a12b tuned signature;
wenzelm
parents: 77129
diff changeset
   538
    clean_platform: Boolean = false,
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   539
    clean_archives: Boolean = false,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71632
diff changeset
   540
    progress: Progress = new Progress,
66106
b5333fc056da always start with fresh clone (with explicitly given rev): more robust on Windows;
wenzelm
parents: 65999
diff changeset
   541
    rev: String = "",
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   542
    afp_repos: Option[Path] = None,
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   543
    afp_rev: String = "",
64227
wenzelm
parents: 64225
diff changeset
   544
    options: String = "",
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   545
    args: String = "",
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   546
    no_build: Boolean = false,
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74306
diff changeset
   547
  ): List[(String, Bytes)] = {
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   548
    /* synchronize Isabelle + AFP repositories */
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   549
75549
4b21e823d35f clarified names;
wenzelm
parents: 75544
diff changeset
   550
    def sync(target: Path, accurate: Boolean = false,
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   551
      rev: String = "", afp_rev: String = "", afp: Boolean = false
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   552
    ): Unit = {
77792
b81b2c50fc7c use "rsync --secluded-args" by default, discontinue obsolete option -P of sync tools;
wenzelm
parents: 77787
diff changeset
   553
      val context = Rsync.Context(progress = progress, ssh = ssh)
77783
fb61887c069a clarified underlying SSH session of "isabelle hg_sync" and "isabelle sync";
wenzelm
parents: 77368
diff changeset
   554
      Sync.sync(ssh.options, context, target,
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   555
        thorough = accurate, preserve_jars = !accurate,
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   556
        rev = rev, afp_rev = afp_rev, afp_root = if (afp) afp_repos else None)
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   557
    }
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   558
75549
4b21e823d35f clarified names;
wenzelm
parents: 75544
diff changeset
   559
    sync(isabelle_self)
77099
378bb7a739c3 prefer Other_Isabelle.init instead of adhoc scripts;
wenzelm
parents: 77092
diff changeset
   560
378bb7a739c3 prefer Other_Isabelle.init instead of adhoc scripts;
wenzelm
parents: 77092
diff changeset
   561
    val self_isabelle =
378bb7a739c3 prefer Other_Isabelle.init instead of adhoc scripts;
wenzelm
parents: 77092
diff changeset
   562
      Other_Isabelle(isabelle_self, isabelle_identifier = isabelle_identifier,
378bb7a739c3 prefer Other_Isabelle.init instead of adhoc scripts;
wenzelm
parents: 77092
diff changeset
   563
        ssh = ssh, progress = progress)
378bb7a739c3 prefer Other_Isabelle.init instead of adhoc scripts;
wenzelm
parents: 77092
diff changeset
   564
77132
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   565
    val clean_platforms = if (clean_platform) Some(List(ssh.isabelle_platform_family)) else None
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   566
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   567
    self_isabelle.init(fresh = true, echo = true,
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   568
      component_repository = component_repository,
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   569
      other_settings = self_isabelle.init_components(components_base = components_base),
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   570
      clean_platforms = clean_platforms,
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   571
      clean_archives = clean_archives)
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   572
75549
4b21e823d35f clarified names;
wenzelm
parents: 75544
diff changeset
   573
    sync(isabelle_other, accurate = true,
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   574
      rev = proper_string(rev) getOrElse "tip",
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   575
      afp_rev = proper_string(afp_rev) getOrElse "tip",
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   576
      afp = true)
66860
54ae2cc05325 support for AFP in build_history and remote_build_history;
wenzelm
parents: 66570
diff changeset
   577
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   578
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   579
    /* build */
73140
68f0bd0c8e87 more informative error;
wenzelm
parents: 73006
diff changeset
   580
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   581
    if (no_build) Nil
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   582
    else {
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   583
      ssh.with_tmp_dir { tmp_dir =>
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   584
        val output_file = tmp_dir + Path.explode("output")
77368
wenzelm
parents: 77207
diff changeset
   585
        val build_options = if_proper(afp_repos, " -A") + " " + options
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   586
        try {
77099
378bb7a739c3 prefer Other_Isabelle.init instead of adhoc scripts;
wenzelm
parents: 77092
diff changeset
   587
          val script =
77127
a8f002720ebb prefer high-level Other_Isabelle.bash over low-level SSH.execute;
wenzelm
parents: 77126
diff changeset
   588
            ssh.bash_path(Path.explode("Admin/build_other")) +
77132
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   589
              " -R " + Bash.string(component_repository) +
78918
8378354bbdad avoid option -C: free this latter for build-related configuration;
wenzelm
parents: 78867
diff changeset
   590
              " -S " + Bash.string(components_base) +
77132
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   591
              (clean_platforms match {
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   592
                case Some(ps) => " -O " + Bash.string(ps.mkString(","))
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   593
                case None => ""
53ce5a39c987 more uniform components context for the managing "self_isabelle" and the managed "other_isabelle";
wenzelm
parents: 77131
diff changeset
   594
              }) +
77125
158790217aa9 more options to manage resolved components;
wenzelm
parents: 77124
diff changeset
   595
              (if (clean_archives) " -Q" else "") +
77099
378bb7a739c3 prefer Other_Isabelle.init instead of adhoc scripts;
wenzelm
parents: 77092
diff changeset
   596
              " -o " + ssh.bash_path(output_file) + build_options + " " +
378bb7a739c3 prefer Other_Isabelle.init instead of adhoc scripts;
wenzelm
parents: 77092
diff changeset
   597
              ssh.bash_path(isabelle_other) + " " + args
77127
a8f002720ebb prefer high-level Other_Isabelle.bash over low-level SSH.execute;
wenzelm
parents: 77126
diff changeset
   598
          self_isabelle.bash(script, echo = true, strict = false).check
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   599
        }
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   600
        catch {
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   601
          case ERROR(msg) =>
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   602
            cat_error(msg, "The error(s) above occurred for Admin/build_other " + build_options)
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   603
        }
64468
ed8940d6295c back to more elementary result (see 5f49765a25ec): avoid concurrent use of ssh channel;
wenzelm
parents: 64466
diff changeset
   604
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   605
        for (line <- split_lines(ssh.read(output_file)))
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   606
        yield {
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   607
          val log = Path.explode(line)
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   608
          val bytes = ssh.read_bytes(log)
77092
4d9f3d1e1749 more operations for SSH.System;
wenzelm
parents: 77091
diff changeset
   609
          ssh.delete(log)
75518
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   610
          (log.file_name, bytes)
cb4af8c6152f clarified remote vs. local build_history: operate on hg_sync directory instead of repository;
wenzelm
parents: 75506
diff changeset
   611
        }
65929
de3adcf6a276 prefer strict result (in contrast to 0f3b0a929c02);
wenzelm
parents: 65928
diff changeset
   612
      }
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   613
    }
64223
9d5b9f41df77 remove invocation of build_history: results are reported via stdout;
wenzelm
parents: 64213
diff changeset
   614
  }
64021
1e23caac8757 basic setup for Admin/build_history -- outside of Isabelle environment;
wenzelm
parents:
diff changeset
   615
}