src/Pure/Build/build.scala
author wenzelm
Tue, 16 Apr 2024 15:11:13 +0200
changeset 80118 0323cd9fcab9
parent 80116 d510a1cf9965
child 80128 2fe244c4bb01
permissions -rw-r--r--
clarified signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
79502
c7a98469c0e7 clarified directories;
wenzelm
parents: 78945
diff changeset
     1
/*  Title:      Pure/Build/build.scala
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
57923
cdae2467311d tuned comments;
wenzelm
parents: 56890
diff changeset
     3
    Options:    :folding=explicit:
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     4
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
     5
Command-line tools to build and manage Isabelle sessions.
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     6
*/
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     7
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     8
package isabelle
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
     9
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    10
import scala.collection.mutable
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    11
import scala.util.matching.Regex
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    12
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
    13
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74845
diff changeset
    14
object Build {
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    15
  /** "isabelle build" **/
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
    16
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    17
  /* options */
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    18
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    19
  def hostname(options: Options): String =
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    20
    Isabelle_System.hostname(options.string("build_hostname"))
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    21
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    22
  def engine_name(options: Options): String = options.string("build_engine")
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    23
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    24
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
    25
78421
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    26
  /* context */
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    27
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    28
  sealed case class Context(
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    29
    store: Store,
79643
51e9d1a80e39 clarified signature;
wenzelm
parents: 79642
diff changeset
    30
    deps: isabelle.Sessions.Deps,
79642
1b0668acf319 clarified signature;
wenzelm
parents: 79639
diff changeset
    31
    engine: Engine = Engine.Default,
78421
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    32
    afp_root: Option[Path] = None,
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    33
    build_hosts: List[Build_Cluster.Host] = Nil,
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    34
    ml_platform: String = Isabelle_System.getenv("ML_PLATFORM"),
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    35
    hostname: String = Isabelle_System.hostname(),
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    36
    numa_shuffling: Boolean = false,
80109
dbcd6dc7f70f back to static numa_nodes (reverting part of c2c59de57df9);
wenzelm
parents: 80056
diff changeset
    37
    numa_nodes: List[Int] = Nil,
79710
32ca3d1283de clarified signature: Build_Process tells how to clean sessions;
wenzelm
parents: 79709
diff changeset
    38
    clean_sessions: List[String] = Nil,
80118
0323cd9fcab9 clarified signature;
wenzelm
parents: 80116
diff changeset
    39
    store_heap: Boolean = false,
78421
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    40
    fresh_build: Boolean = false,
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    41
    no_build: Boolean = false,
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    42
    session_setup: (String, Session) => Unit = (_, _) => (),
79717
da4e82434985 tuned signature;
wenzelm
parents: 79715
diff changeset
    43
    build_uuid: String = UUID.random_string(),
79811
d9fc2cc37694 more robust build_start for master and workers (via database);
wenzelm
parents: 79810
diff changeset
    44
    build_start: Option[Date] = None,
79644
389c1bfa7c3e clarified signature: more standard defaults;
wenzelm
parents: 79643
diff changeset
    45
    jobs: Int = 0,
78421
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    46
    master: Boolean = false
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    47
  ) {
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    48
    def build_options: Options = store.options
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    49
79643
51e9d1a80e39 clarified signature;
wenzelm
parents: 79642
diff changeset
    50
    def sessions_structure: isabelle.Sessions.Structure = deps.sessions_structure
78421
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    51
79645
7a1153c95bf9 clarifier worker vs. master, which may coincide for local build;
wenzelm
parents: 79644
diff changeset
    52
    def worker: Boolean = jobs > 0
7a1153c95bf9 clarifier worker vs. master, which may coincide for local build;
wenzelm
parents: 79644
diff changeset
    53
7a1153c95bf9 clarifier worker vs. master, which may coincide for local build;
wenzelm
parents: 79644
diff changeset
    54
    override def toString: String =
7a1153c95bf9 clarifier worker vs. master, which may coincide for local build;
wenzelm
parents: 79644
diff changeset
    55
      "Build.Context(build_uuid = " + quote(build_uuid) +
7a1153c95bf9 clarifier worker vs. master, which may coincide for local build;
wenzelm
parents: 79644
diff changeset
    56
        if_proper(worker, ", worker = true") +
7a1153c95bf9 clarifier worker vs. master, which may coincide for local build;
wenzelm
parents: 79644
diff changeset
    57
        if_proper(master, ", master = true") + ")"
78421
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    58
  }
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    59
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
    60
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
    61
  /* results */
48424
wenzelm
parents: 48423
diff changeset
    62
77311
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    63
  object Results {
78440
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    64
    def apply(
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    65
      context: Context,
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    66
      results: Map[String, Process_Result] = Map.empty,
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    67
      other_rc: Int = Process_Result.RC.ok
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    68
    ): Results = {
79643
51e9d1a80e39 clarified signature;
wenzelm
parents: 79642
diff changeset
    69
      new Results(context.store, context.deps, results, other_rc)
78440
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    70
    }
77311
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    71
  }
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    72
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    73
  class Results private(
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77719
diff changeset
    74
    val store: Store,
76209
365f6a621fc5 clarified signature;
wenzelm
parents: 76206
diff changeset
    75
    val deps: Sessions.Deps,
78440
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    76
    results: Map[String, Process_Result],
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    77
    other_rc: Int
76198
fb4215da4919 clarified presentation_sessions: work with partial results;
wenzelm
parents: 76197
diff changeset
    78
  ) {
76206
769a7cd5a16a clarified signature: re-use store/cache from build results;
wenzelm
parents: 76202
diff changeset
    79
    def cache: Term.Cache = store.cache
769a7cd5a16a clarified signature: re-use store/cache from build results;
wenzelm
parents: 76202
diff changeset
    80
77311
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    81
    def sessions_ok: List[String] =
80116
wenzelm
parents: 80109
diff changeset
    82
      List.from(
wenzelm
parents: 80109
diff changeset
    83
        for {
wenzelm
parents: 80109
diff changeset
    84
          name <- deps.sessions_structure.build_topological_order.iterator
wenzelm
parents: 80109
diff changeset
    85
          result <- results.get(name) if result.ok
wenzelm
parents: 80109
diff changeset
    86
        } yield name)
77311
5212446f3d7f clarified signature;
wenzelm
parents: 77310
diff changeset
    87
77250
22016642d6af clarified data structure: use static info from deps, not dynamic results;
wenzelm
parents: 77246
diff changeset
    88
    def info(name: String): Sessions.Info = deps.sessions_structure(name)
62403
1d7aba20a332 explicit class Build_Results;
wenzelm
parents: 62402
diff changeset
    89
    def sessions: Set[String] = results.keySet
77253
792dad9cb04f clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents: 77252
diff changeset
    90
    def cancelled(name: String): Boolean = !results(name).defined
792dad9cb04f clarified data structure: absorb Option[Process_Result] into Process_Result, e.g. to simplify database storage;
wenzelm
parents: 77252
diff changeset
    91
    def apply(name: String): Process_Result = results(name).strict
78440
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    92
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    93
    val rc: Int =
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    94
      Process_Result.RC.merge(other_rc,
126a12483c67 support for Build_Cluster.Session.init (rsync + Admin/init);
wenzelm
parents: 78437
diff changeset
    95
        Process_Result.RC.merge(results.valuesIterator.map(_.strict.rc)))
74306
a117c076aa22 clarified signature;
wenzelm
parents: 73826
diff changeset
    96
    def ok: Boolean = rc == Process_Result.RC.ok
62406
b5b8fb87447a tuned signature;
wenzelm
parents: 62405
diff changeset
    97
78566
a04277e3b313 tuned message: failure may stem from build_cluster init;
wenzelm
parents: 78562
diff changeset
    98
    lazy val unfinished: List[String] = sessions.iterator.filterNot(apply(_).ok).toList.sorted
76199
6bf42525f111 tuned signature;
wenzelm
parents: 76198
diff changeset
    99
62406
b5b8fb87447a tuned signature;
wenzelm
parents: 62405
diff changeset
   100
    override def toString: String = rc.toString
62403
1d7aba20a332 explicit class Build_Results;
wenzelm
parents: 62402
diff changeset
   101
  }
1d7aba20a332 explicit class Build_Results;
wenzelm
parents: 62402
diff changeset
   102
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
   103
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
   104
  /* engine */
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
   105
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   106
  object Engine {
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   107
    lazy val services: List[Engine] =
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   108
      Isabelle_System.make_services(classOf[Engine])
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   109
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   110
    def apply(name: String): Engine =
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   111
      services.find(_.name == name).getOrElse(error("Bad build engine " + quote(name)))
79642
1b0668acf319 clarified signature;
wenzelm
parents: 79639
diff changeset
   112
1b0668acf319 clarified signature;
wenzelm
parents: 79639
diff changeset
   113
    class Default extends Engine("") { override def toString: String = "<default>" }
1b0668acf319 clarified signature;
wenzelm
parents: 79639
diff changeset
   114
    object Default extends Default
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   115
  }
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   116
77411
149cc77f7348 clafified signature: simplify object-oriented reuse;
wenzelm
parents: 77384
diff changeset
   117
  class Engine(val name: String) extends Isabelle_System.Service {
79705
wenzelm
parents: 79700
diff changeset
   118
    engine =>
wenzelm
parents: 79700
diff changeset
   119
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
   120
    override def toString: String = name
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   121
79614
58c0636e0ef5 clarified signature;
wenzelm
parents: 79502
diff changeset
   122
    def build_options(options: Options, build_cluster: Boolean = false): Options = {
78401
822ddccda899 proforma support for remote build hosts;
wenzelm
parents: 78379
diff changeset
   123
      val options1 = options + "completion_limit=0" + "editor_tracing_messages=0"
79814
2da08d9ce629 prefer explicit option "build_log_verbose";
wenzelm
parents: 79811
diff changeset
   124
      if (build_cluster) options1 + "build_database" + "build_log_verbose" else options1
78401
822ddccda899 proforma support for remote build hosts;
wenzelm
parents: 78379
diff changeset
   125
    }
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   126
78412
wenzelm
parents: 78411
diff changeset
   127
    final def build_store(options: Options,
79614
58c0636e0ef5 clarified signature;
wenzelm
parents: 79502
diff changeset
   128
      build_cluster: Boolean = false,
78412
wenzelm
parents: 78411
diff changeset
   129
      cache: Term.Cache = Term.Cache.make()
wenzelm
parents: 78411
diff changeset
   130
    ): Store = {
79705
wenzelm
parents: 79700
diff changeset
   131
      val build_options = engine.build_options(options, build_cluster = build_cluster)
wenzelm
parents: 79700
diff changeset
   132
      val store = Store(build_options, build_cluster = build_cluster, cache = cache)
78412
wenzelm
parents: 78411
diff changeset
   133
      Isabelle_System.make_directory(store.output_dir + Path.basic("log"))
wenzelm
parents: 78411
diff changeset
   134
      Isabelle_Fonts.init()
wenzelm
parents: 78411
diff changeset
   135
      store
wenzelm
parents: 78411
diff changeset
   136
    }
wenzelm
parents: 78411
diff changeset
   137
78436
5f5f909206bb clarified signature: more "object-oriented" style;
wenzelm
parents: 78435
diff changeset
   138
    def open_build_process(
78421
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
   139
      build_context: Context,
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   140
      build_progress: Progress,
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   141
      server: SSH.Server
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   142
    ): Build_Process = new Build_Process(build_context, build_progress, server)
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   143
78436
5f5f909206bb clarified signature: more "object-oriented" style;
wenzelm
parents: 78435
diff changeset
   144
    final def run_build_process(
78421
fd24f380b588 clarified modules;
wenzelm
parents: 78420
diff changeset
   145
      context: Context,
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   146
      progress: Progress,
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   147
      server: SSH.Server
78412
wenzelm
parents: 78411
diff changeset
   148
    ): Results = {
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   149
      Isabelle_Thread.uninterruptible {
79710
32ca3d1283de clarified signature: Build_Process tells how to clean sessions;
wenzelm
parents: 79709
diff changeset
   150
        using(open_build_process(context, progress, server)) { build_process =>
32ca3d1283de clarified signature: Build_Process tells how to clean sessions;
wenzelm
parents: 79709
diff changeset
   151
          build_process.prepare()
32ca3d1283de clarified signature: Build_Process tells how to clean sessions;
wenzelm
parents: 79709
diff changeset
   152
          build_process.run()
32ca3d1283de clarified signature: Build_Process tells how to clean sessions;
wenzelm
parents: 79709
diff changeset
   153
        }
78232
45c7b88d1609 clarified signature;
wenzelm
parents: 78228
diff changeset
   154
      }
78412
wenzelm
parents: 78411
diff changeset
   155
    }
77330
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
   156
  }
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
   157
47eb96592aa2 support alternative build engines, via system option "build_engine";
wenzelm
parents: 77326
diff changeset
   158
77558
wenzelm
parents: 77557
diff changeset
   159
wenzelm
parents: 77557
diff changeset
   160
  /* build */
wenzelm
parents: 77557
diff changeset
   161
62641
0b1b7465f2ef always build with full results;
wenzelm
parents: 62638
diff changeset
   162
  def build(
50404
898cac1dad5e avoid startup within GUI thread -- it is only required later for dialog;
wenzelm
parents: 50367
diff changeset
   163
    options: Options,
78401
822ddccda899 proforma support for remote build hosts;
wenzelm
parents: 78379
diff changeset
   164
    build_hosts: List[Build_Cluster.Host] = Nil,
71981
0be06f99b210 clarified signature;
wenzelm
parents: 71978
diff changeset
   165
    selection: Sessions.Selection = Sessions.Selection.empty,
75942
603852abed8f clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents: 75941
diff changeset
   166
    browser_info: Browser_Info.Config = Browser_Info.Config.none,
71726
a5fda30edae2 clarified signature: more uniform treatment of stopped/interrupted state;
wenzelm
parents: 71718
diff changeset
   167
    progress: Progress = new Progress,
65832
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   168
    check_unknown_files: Boolean = false,
48511
37999ee01156 remove old output heaps, to ensure that result is valid wrt. check_stamps;
wenzelm
parents: 48509
diff changeset
   169
    build_heap: Boolean = false,
48595
231e6fa96dbb added build option -c;
wenzelm
parents: 48594
diff changeset
   170
    clean_build: Boolean = false,
78418
bc62be4144e6 added option -A for AFP root, following "isabelle sync";
wenzelm
parents: 78412
diff changeset
   171
    afp_root: Option[Path] = None,
56890
7f120d227ca5 tuned signature;
wenzelm
parents: 56873
diff changeset
   172
    dirs: List[Path] = Nil,
7f120d227ca5 tuned signature;
wenzelm
parents: 56873
diff changeset
   173
    select_dirs: List[Path] = Nil,
66968
9991671c98aa allow to augment session context via explicit session infos;
wenzelm
parents: 66962
diff changeset
   174
    infos: List[Sessions.Info] = Nil,
64265
8eb6365f5916 isabelle build -N;
wenzelm
parents: 64173
diff changeset
   175
    numa_shuffling: Boolean = false,
79616
12bb31d01510 more robust type, with explicit default;
wenzelm
parents: 79615
diff changeset
   176
    max_jobs: Option[Int] = None,
48903
1621b3f26095 added build option -l (list files);
wenzelm
parents: 48883
diff changeset
   177
    list_files: Boolean = false,
59891
9ce697050455 added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents: 59811
diff changeset
   178
    check_keywords: Set[String] = Set.empty,
66841
5c32a072ca8b added isablle build option -f;
wenzelm
parents: 66822
diff changeset
   179
    fresh_build: Boolean = false,
48509
4854ced3e9d7 support session groups;
wenzelm
parents: 48508
diff changeset
   180
    no_build: Boolean = false,
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   181
    soft_build: Boolean = false,
73805
b73777a0c076 allow build session setup, e.g. for protocol handlers;
wenzelm
parents: 73804
diff changeset
   182
    export_files: Boolean = false,
76927
da13da82f6f9 treat update_options as part of Sessions.Info meta_digest, for proper re-build of updated sessions;
wenzelm
parents: 76919
diff changeset
   183
    augment_options: String => List[Options.Spec] = _ => Nil,
77559
4ad322ee6025 clarified signature: support all arguments of Sessions.store();
wenzelm
parents: 77558
diff changeset
   184
    session_setup: (String, Session) => Unit = (_, _) => (),
4ad322ee6025 clarified signature: support all arguments of Sessions.store();
wenzelm
parents: 77558
diff changeset
   185
    cache: Term.Cache = Term.Cache.make()
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74845
diff changeset
   186
  ): Results = {
79707
wenzelm
parents: 79705
diff changeset
   187
    val engine = Engine(engine_name(options))
wenzelm
parents: 79705
diff changeset
   188
    val store = engine.build_store(options, build_cluster = build_hosts.nonEmpty, cache = cache)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   189
    val build_options = store.options
69369
6ecc85955e04 prefer "Isabelle DejaVu Sans", even for headless batch-build (session_graph.pdf);
wenzelm
parents: 68957
diff changeset
   190
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   191
    using(store.open_server()) { server =>
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   192
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   193
      /* session selection and dependencies */
65422
b606c98e6d10 tuned signature;
wenzelm
parents: 65420
diff changeset
   194
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   195
      val full_sessions =
80056
9279e96eb34e clarified signature;
wenzelm
parents: 79873
diff changeset
   196
        Sessions.load_structure(build_options, dirs = AFP.main_dirs(afp_root) ::: dirs,
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   197
          select_dirs = select_dirs, infos = infos, augment_options = augment_options)
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   198
      val full_sessions_selection = full_sessions.imports_selection(selection)
73012
238ddf525da4 clarified HTML presentation, e.g. avoid bulky jobs like HOL or HOL-Analysis in applications;
wenzelm
parents: 72993
diff changeset
   199
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   200
      val build_deps = {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   201
        val deps0 =
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   202
          Sessions.deps(full_sessions.selection(selection), progress = progress,
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   203
            inlined_files = true, list_files = list_files, check_keywords = check_keywords
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   204
          ).check_errors
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   205
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   206
        if (soft_build && !fresh_build) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   207
          val outdated =
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   208
            deps0.sessions_structure.build_topological_order.flatMap(name =>
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   209
              store.try_open_database(name, server = server) match {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   210
                case Some(db) =>
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   211
                  using(db)(store.read_build(_, name)) match {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   212
                    case Some(build) if build.ok =>
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   213
                      val session_options = deps0.sessions_structure(name).options
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   214
                      val session_sources = deps0.sources_shasum(name)
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   215
                      if (Sessions.eq_sources(session_options, build.sources, session_sources)) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   216
                        None
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   217
                      }
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   218
                      else Some(name)
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   219
                    case _ => Some(name)
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   220
                  }
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   221
                case None => Some(name)
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   222
              })
68204
a554da2811f2 clarified signature;
wenzelm
parents: 68198
diff changeset
   223
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   224
          Sessions.deps(full_sessions.selection(Sessions.Selection(sessions = outdated)),
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   225
            progress = progress, inlined_files = true).check_errors
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   226
        }
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   227
        else deps0
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   228
      }
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   229
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   230
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   231
      /* check unknown files */
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   232
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   233
      if (check_unknown_files) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   234
        val source_files =
80116
wenzelm
parents: 80109
diff changeset
   235
          List.from(
wenzelm
parents: 80109
diff changeset
   236
            for {
wenzelm
parents: 80109
diff changeset
   237
              (_, base) <- build_deps.session_bases.iterator
wenzelm
parents: 80109
diff changeset
   238
              (path, _) <- base.session_sources.iterator
wenzelm
parents: 80109
diff changeset
   239
            } yield path)
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   240
        Mercurial.check_files(source_files)._2 match {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   241
          case Nil =>
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   242
          case unknown_files =>
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   243
            progress.echo_warning(
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   244
              "Unknown files (not part of the underlying Mercurial repository):" +
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   245
              unknown_files.map(File.standard_path).sorted.mkString("\n  ", "\n  ", ""))
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   246
        }
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   247
      }
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   248
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   249
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   250
      /* build process and results */
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   251
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   252
      val clean_sessions =
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   253
        if (clean_build) full_sessions.imports_descendants(full_sessions_selection) else Nil
79710
32ca3d1283de clarified signature: Build_Process tells how to clean sessions;
wenzelm
parents: 79709
diff changeset
   254
80109
dbcd6dc7f70f back to static numa_nodes (reverting part of c2c59de57df9);
wenzelm
parents: 80056
diff changeset
   255
      val numa_nodes = Host.numa_nodes(enabled = numa_shuffling)
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   256
      val build_context =
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   257
        Context(store, build_deps, engine = engine, afp_root = afp_root,
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   258
          build_hosts = build_hosts, hostname = hostname(build_options),
80118
0323cd9fcab9 clarified signature;
wenzelm
parents: 80116
diff changeset
   259
          clean_sessions = clean_sessions, store_heap = build_heap,
80109
dbcd6dc7f70f back to static numa_nodes (reverting part of c2c59de57df9);
wenzelm
parents: 80056
diff changeset
   260
          numa_shuffling = numa_shuffling, numa_nodes = numa_nodes,
dbcd6dc7f70f back to static numa_nodes (reverting part of c2c59de57df9);
wenzelm
parents: 80056
diff changeset
   261
          fresh_build = fresh_build, no_build = no_build, session_setup = session_setup,
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   262
          jobs = max_jobs.getOrElse(if (build_hosts.nonEmpty) 0 else 1), master = true)
48504
21dfd6c04482 actually check source vs. target stamps, based on information from log files;
wenzelm
parents: 48494
diff changeset
   263
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   264
      val results = engine.run_build_process(build_context, progress, server)
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   265
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   266
      if (export_files) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   267
        for (name <- full_sessions_selection.iterator if results(name).ok) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   268
          val info = results.info(name)
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   269
          if (info.export_files.nonEmpty) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   270
            progress.echo("Exporting " + info.name + " ...")
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   271
            for ((dir, prune, pats) <- info.export_files) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   272
              Export.export_files(store, name, info.dir + dir,
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   273
                progress = if (progress.verbose) progress else new Progress,
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   274
                export_prune = prune,
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   275
                export_patterns = pats)
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   276
            }
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   277
          }
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   278
        }
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   279
      }
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   280
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   281
      val presentation_sessions =
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   282
        results.sessions_ok.filter(name => browser_info.enabled(results.info(name)))
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   283
      if (presentation_sessions.nonEmpty && !progress.stopped) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   284
        Browser_Info.build(browser_info, results.store, results.deps, presentation_sessions,
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   285
          progress = progress, server = server)
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   286
      }
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   287
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   288
      if (results.unfinished.nonEmpty && (progress.verbose || !no_build)) {
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   289
        progress.echo("Unfinished session(s): " + commas(results.unfinished))
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   290
      }
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   291
79715
e59d93da9109 removed unused database_server (amending 32ca3d1283de);
wenzelm
parents: 79710
diff changeset
   292
      results
65832
2fb85623c386 implicitly check for unknown files (not part of a Mercurial repository);
wenzelm
parents: 65831
diff changeset
   293
    }
48341
752de4e10162 tuned source structure;
wenzelm
parents: 48340
diff changeset
   294
  }
752de4e10162 tuned source structure;
wenzelm
parents: 48340
diff changeset
   295
752de4e10162 tuned source structure;
wenzelm
parents: 48340
diff changeset
   296
77555
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   297
  /* build logic image */
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   298
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   299
  def build_logic(options: Options, logic: String,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   300
    progress: Progress = new Progress,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   301
    build_heap: Boolean = false,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   302
    dirs: List[Path] = Nil,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   303
    fresh: Boolean = false,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   304
    strict: Boolean = false
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   305
  ): Int = {
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   306
    val selection = Sessions.Selection.session(logic)
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   307
    val rc =
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   308
      if (!fresh && build(options, selection = selection,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   309
            build_heap = build_heap, no_build = true, dirs = dirs).ok) Process_Result.RC.ok
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   310
      else {
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   311
        progress.echo("Build started for Isabelle/" + logic + " ...")
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   312
        build(options, selection = selection, progress = progress,
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   313
          build_heap = build_heap, fresh_build = fresh, dirs = dirs).rc
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   314
      }
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   315
    if (strict && rc != Process_Result.RC.ok) error("Failed to build Isabelle/" + logic) else rc
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   316
  }
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   317
d45a01c41fe2 tuned structure;
wenzelm
parents: 77554
diff changeset
   318
79629
4d81c0391da2 tuned comments;
wenzelm
parents: 79624
diff changeset
   319
  /* Isabelle tool wrappers */
48341
752de4e10162 tuned source structure;
wenzelm
parents: 48340
diff changeset
   320
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   321
  val isabelle_tool1 = Isabelle_Tool("build", "build and manage Isabelle sessions",
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   322
    Scala_Project.here,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   323
    { args =>
78418
bc62be4144e6 added option -A for AFP root, following "isabelle sync";
wenzelm
parents: 78412
diff changeset
   324
      var afp_root: Option[Path] = None
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   325
      val base_sessions = new mutable.ListBuffer[String]
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   326
      val select_dirs = new mutable.ListBuffer[Path]
78401
822ddccda899 proforma support for remote build hosts;
wenzelm
parents: 78379
diff changeset
   327
      val build_hosts = new mutable.ListBuffer[Build_Cluster.Host]
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   328
      var numa_shuffling = false
75942
603852abed8f clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents: 75941
diff changeset
   329
      var browser_info = Browser_Info.Config.none
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   330
      var requirements = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   331
      var soft_build = false
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   332
      val exclude_session_groups = new mutable.ListBuffer[String]
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   333
      var all_sessions = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   334
      var build_heap = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   335
      var clean_build = false
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   336
      val dirs = new mutable.ListBuffer[Path]
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   337
      var export_files = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   338
      var fresh_build = false
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   339
      val session_groups = new mutable.ListBuffer[String]
79616
12bb31d01510 more robust type, with explicit default;
wenzelm
parents: 79615
diff changeset
   340
      var max_jobs: Option[Int] = None
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   341
      var check_keywords: Set[String] = Set.empty
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   342
      var list_files = false
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   343
      var no_build = false
77628
a538dab533ef clarified signature: prefer explicit types;
wenzelm
parents: 77579
diff changeset
   344
      var options = Options.init(specs = Options.Spec.ISABELLE_BUILD_OPTIONS)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   345
      var verbose = false
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   346
      val exclude_sessions = new mutable.ListBuffer[String]
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   347
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   348
      val getopts = Getopts("""
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   349
Usage: isabelle build [OPTIONS] [SESSIONS ...]
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   350
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   351
  Options are:
78418
bc62be4144e6 added option -A for AFP root, following "isabelle sync";
wenzelm
parents: 78412
diff changeset
   352
    -A ROOT      include AFP with given root directory (":" for """ + AFP.BASE.implode + """)
66737
2edc0c42c883 option -B for "isabelle build" and "isabelle imports";
wenzelm
parents: 66736
diff changeset
   353
    -B NAME      include session NAME and all descendants
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   354
    -D DIR       include session directory and select its sessions
79615
a01f4cf202fd tuned usage message;
wenzelm
parents: 79614
diff changeset
   355
    -H HOSTS     additional cluster host specifications of the form
a01f4cf202fd tuned usage message;
wenzelm
parents: 79614
diff changeset
   356
                 NAMES:PARAMETERS (separated by commas)
64265
8eb6365f5916 isabelle build -N;
wenzelm
parents: 64173
diff changeset
   357
    -N           cyclic shuffling of NUMA CPU nodes (performance tuning)
72648
1cbac4ae934d more explicit presentation directory;
wenzelm
parents: 72640
diff changeset
   358
    -P DIR       enable HTML/PDF presentation in directory (":" for default)
71807
cdfa8f027bb9 tuned messages;
wenzelm
parents: 71727
diff changeset
   359
    -R           refer to requirements of selected sessions
66745
e7ac579b883c option -S for "isabelle build";
wenzelm
parents: 66744
diff changeset
   360
    -S           soft build: only observe changes of sources, not heap images
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   361
    -X NAME      exclude sessions from group NAME and all descendants
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   362
    -a           select all sessions
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   363
    -b           build heap images
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   364
    -c           clean build
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   365
    -d DIR       include session directory
69811
18f61ce86425 clarified 'export_files' in session ROOT: require explicit "isabelle build -e";
wenzelm
parents: 69777
diff changeset
   366
    -e           export files from session specification into file-system
66841
5c32a072ca8b added isablle build option -f;
wenzelm
parents: 66822
diff changeset
   367
    -f           fresh build
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   368
    -g NAME      select session group NAME
79647
b7187d4cdf68 clarified default "isabelle build -j0 -H";
wenzelm
parents: 79646
diff changeset
   369
    -j INT       maximum number of parallel jobs
b7187d4cdf68 clarified default "isabelle build -j0 -H";
wenzelm
parents: 79646
diff changeset
   370
                 (default: 1 for local build, 0 for build cluster)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   371
    -k KEYWORD   check theory sources for conflicts with proposed keywords
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   372
    -l           list session source files
77554
4465d9dff448 clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents: 77553
diff changeset
   373
    -n           no build -- take existing session build databases
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   374
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   375
    -v           verbose
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   376
    -x NAME      exclude session NAME and all descendants
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   377
77647
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   378
  Build and manage Isabelle sessions: ML heaps, session databases, documents.
62596
cf79f8866bc3 tuned messages;
wenzelm
parents: 62595
diff changeset
   379
79615
a01f4cf202fd tuned usage message;
wenzelm
parents: 79614
diff changeset
   380
  Parameters for cluster host specifications (-H), apart from system options:
78408
092f1e435b3a proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents: 78405
diff changeset
   381
""" + Library.indent_lines(4, Build_Cluster.Host.parameters.print()) +
092f1e435b3a proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents: 78405
diff changeset
   382
"""
092f1e435b3a proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents: 78405
diff changeset
   383
77647
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   384
  Notable system options: see "isabelle options -l -t build"
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   385
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   386
  Notable system settings:
78408
092f1e435b3a proper Build_Cluster.Host.parse for parameters and system options;
wenzelm
parents: 78405
diff changeset
   387
""" + Library.indent_lines(4, Build_Log.Settings.show()) + "\n",
78418
bc62be4144e6 added option -A for AFP root, following "isabelle sync";
wenzelm
parents: 78412
diff changeset
   388
        "A:" -> (arg => afp_root = Some(if (arg == ":") AFP.BASE else Path.explode(arg))),
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   389
        "B:" -> (arg => base_sessions += arg),
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   390
        "D:" -> (arg => select_dirs += Path.explode(arg)),
78945
73162a487f94 build cluster host specifications are based on registry entries (table prefix "host");
wenzelm
parents: 78916
diff changeset
   391
        "H:" -> (arg => build_hosts ++= Build_Cluster.Host.parse(Registry.global, arg)),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   392
        "N" -> (_ => numa_shuffling = true),
75942
603852abed8f clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents: 75941
diff changeset
   393
        "P:" -> (arg => browser_info = Browser_Info.Config.make(arg)),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   394
        "R" -> (_ => requirements = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   395
        "S" -> (_ => soft_build = true),
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   396
        "X:" -> (arg => exclude_session_groups += arg),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   397
        "a" -> (_ => all_sessions = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   398
        "b" -> (_ => build_heap = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   399
        "c" -> (_ => clean_build = true),
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   400
        "d:" -> (arg => dirs += Path.explode(arg)),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   401
        "e" -> (_ => export_files = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   402
        "f" -> (_ => fresh_build = true),
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   403
        "g:" -> (arg => session_groups += arg),
79616
12bb31d01510 more robust type, with explicit default;
wenzelm
parents: 79615
diff changeset
   404
        "j:" -> (arg => max_jobs = Some(Value.Nat.parse(arg))),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   405
        "k:" -> (arg => check_keywords = check_keywords + arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   406
        "l" -> (_ => list_files = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   407
        "n" -> (_ => no_build = true),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   408
        "o:" -> (arg => options = options + arg),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   409
        "v" -> (_ => verbose = true),
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   410
        "x:" -> (arg => exclude_sessions += arg))
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   411
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   412
      val sessions = getopts(args)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   413
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   414
      val progress = new Console_Progress(verbose = verbose)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   415
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   416
      progress.echo(
78895
wenzelm
parents: 78842
diff changeset
   417
        "Started at " + Build_Log.print_date(progress.start) +
77719
cbfbf48b0281 tuned signature;
wenzelm
parents: 77677
diff changeset
   418
          " (" + Isabelle_System.ml_identifier() + " on " + hostname(options) +")",
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   419
        verbose = true)
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77505
diff changeset
   420
      progress.echo(Build_Log.Settings.show() + "\n", verbose = true)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   421
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   422
      val results =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   423
        progress.interrupt_handler {
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   424
          build(options,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   425
            selection = Sessions.Selection(
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   426
              requirements = requirements,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   427
              all_sessions = all_sessions,
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   428
              base_sessions = base_sessions.toList,
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   429
              exclude_session_groups = exclude_session_groups.toList,
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   430
              exclude_sessions = exclude_sessions.toList,
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   431
              session_groups = session_groups.toList,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   432
              sessions = sessions),
75942
603852abed8f clarified names: Browser_Info.Config vs. Browser_Info.Context;
wenzelm
parents: 75941
diff changeset
   433
            browser_info = browser_info,
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   434
            progress = progress,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   435
            check_unknown_files = Mercurial.is_repository(Path.ISABELLE_HOME),
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   436
            build_heap = build_heap,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   437
            clean_build = clean_build,
78437
84471794b280 proper afp_root;
wenzelm
parents: 78436
diff changeset
   438
            afp_root = afp_root,
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   439
            dirs = dirs.toList,
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   440
            select_dirs = select_dirs.toList,
77477
f376aebca9c1 clarified modules;
wenzelm
parents: 77453
diff changeset
   441
            numa_shuffling = Host.numa_check(progress, numa_shuffling),
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   442
            max_jobs = max_jobs,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   443
            list_files = list_files,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   444
            check_keywords = check_keywords,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   445
            fresh_build = fresh_build,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   446
            no_build = no_build,
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   447
            soft_build = soft_build,
78401
822ddccda899 proforma support for remote build hosts;
wenzelm
parents: 78379
diff changeset
   448
            export_files = export_files,
822ddccda899 proforma support for remote build hosts;
wenzelm
parents: 78379
diff changeset
   449
            build_hosts = build_hosts.toList)
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   450
        }
79810
4b23abde5d0b more accurate progress.now(), notably for Database_Progress;
wenzelm
parents: 79717
diff changeset
   451
      val stop_date = progress.now()
79819
wenzelm
parents: 79814
diff changeset
   452
      val elapsed_time = stop_date - progress.start
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   453
77545
4af88aca2a4f clarified database content;
wenzelm
parents: 77536
diff changeset
   454
      progress.echo("\nFinished at " + Build_Log.print_date(stop_date), verbose = true)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   455
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   456
      val total_timing =
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   457
        results.sessions.iterator.map(a => results(a).timing).foldLeft(Timing.zero)(_ + _).
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   458
          copy(elapsed = elapsed_time)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   459
      progress.echo(total_timing.message_resources)
62590
0c837beeb5e7 upgrade "isabelle build" to Isabelle/Scala;
wenzelm
parents: 62573
diff changeset
   460
75394
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   461
      sys.exit(results.rc)
42267c650205 tuned formatting;
wenzelm
parents: 75393
diff changeset
   462
    })
68305
5321218147d3 clarified signature;
wenzelm
parents: 68292
diff changeset
   463
5321218147d3 clarified signature;
wenzelm
parents: 68292
diff changeset
   464
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   465
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   466
  /** build cluster management **/
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   467
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   468
  /* identified builds */
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   469
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   470
  def read_builds(build_database: Option[SQL.Database]): List[Build_Process.Build] =
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   471
    build_database match {
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   472
      case None => Nil
78634
0beb46a96cf3 clarified output;
wenzelm
parents: 78633
diff changeset
   473
      case Some(db) => Build_Process.read_builds(db)
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   474
    }
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   475
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   476
  def print_builds(build_database: Option[SQL.Database], builds: List[Build_Process.Build]): String =
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   477
  {
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   478
    val print_database =
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   479
      build_database match {
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   480
        case None => ""
78634
0beb46a96cf3 clarified output;
wenzelm
parents: 78633
diff changeset
   481
        case Some(db) => " (database " + db + ")"
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   482
      }
78640
5ee978b3c009 tuned messages;
wenzelm
parents: 78637
diff changeset
   483
    if (builds.isEmpty) "No build processes" + print_database
78641
wenzelm
parents: 78640
diff changeset
   484
    else "Build processes" + print_database + builds.map(build => "\n  " + build.print).mkString
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   485
  }
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   486
78410
c5170293d392 clarified options;
wenzelm
parents: 78408
diff changeset
   487
  def find_builds(
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   488
    build_database: Option[SQL.Database],
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   489
    build_id: String,
78221
60fa7a0b9372 clarified output;
wenzelm
parents: 78220
diff changeset
   490
    builds: List[Build_Process.Build]
78410
c5170293d392 clarified options;
wenzelm
parents: 78408
diff changeset
   491
  ): Build_Process.Build = {
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   492
    (build_id, builds.length) match {
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   493
      case (UUID(_), _) if builds.exists(_.build_uuid == build_id) =>
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   494
        builds.find(_.build_uuid == build_id).get
78410
c5170293d392 clarified options;
wenzelm
parents: 78408
diff changeset
   495
      case ("", 1) => builds.head
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   496
      case ("", 0) => error(print_builds(build_database, builds))
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   497
      case _ =>
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   498
        cat_error("Cannot identify build process " + quote(build_id),
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   499
          print_builds(build_database, builds))
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   500
    }
78410
c5170293d392 clarified options;
wenzelm
parents: 78408
diff changeset
   501
  }
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   502
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   503
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   504
  /* "isabelle build_process" */
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   505
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   506
  def build_process(
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   507
    options: Options,
79676
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79647
diff changeset
   508
    build_cluster: Boolean = false,
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   509
    list_builds: Boolean = false,
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   510
    remove_builds: Boolean = false,
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   511
    force: Boolean = false,
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   512
    progress: Progress = new Progress
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   513
  ): Unit = {
79707
wenzelm
parents: 79705
diff changeset
   514
    val engine = Engine(engine_name(options))
wenzelm
parents: 79705
diff changeset
   515
    val store = engine.build_store(options, build_cluster = build_cluster)
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   516
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   517
    using(store.open_server()) { server =>
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   518
      using_optional(store.maybe_open_build_database(server = server)) { build_database =>
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   519
        def print(builds: List[Build_Process.Build]): Unit =
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   520
          if (list_builds) progress.echo(print_builds(build_database, builds))
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   521
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   522
        build_database match {
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   523
          case None => print(Nil)
79847
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   524
          case Some(db) if remove_builds && force =>
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   525
            db.transaction {
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   526
              val tables0 =
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   527
                ML_Heap.private_data.tables.list :::
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   528
                Store.private_data.tables.list :::
79873
6c19c29ddcbe clarified modules;
wenzelm
parents: 79847
diff changeset
   529
                Database_Progress.private_data.tables.list :::
79847
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   530
                Build_Process.private_data.tables.list
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   531
              val tables = tables0.filter(t => db.exists_table(t.name)).sortBy(_.name)
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   532
              if (tables.nonEmpty) {
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   533
                progress.echo("Removing tables " + commas_quote(tables.map(_.name)) + " ...")
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   534
                db.execute_statement(SQL.MULTI(tables.map(db.destroy)))
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   535
              }
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   536
            }
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   537
          case Some(db) =>
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   538
            Build_Process.private_data.transaction_lock(db, create = true, label = "build_process") {
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   539
              val builds = Build_Process.private_data.read_builds(db)
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   540
              print(builds)
79847
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   541
              if (remove_builds) {
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   542
                val remove = builds.flatMap(_.active_build_uuid)
f7dfe92e6785 more thorough "isabelle build_process -C -r -f";
wenzelm
parents: 79845
diff changeset
   543
                if (remove.nonEmpty) {
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   544
                  progress.echo("Removing " + commas(remove) + " ...")
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   545
                  Build_Process.private_data.remove_builds(db, remove)
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   546
                  print(Build_Process.private_data.read_builds(db))
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   547
                }
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   548
              }
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   549
            }
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   550
        }
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   551
      }
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   552
    }
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   553
  }
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   554
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   555
  val isabelle_tool2 = Isabelle_Tool("build_process", "manage session build process",
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   556
    Scala_Project.here,
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   557
    { args =>
79676
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79647
diff changeset
   558
      var build_cluster = false
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   559
      var force = false
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   560
      var list_builds = false
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   561
      var options =
79682
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79679
diff changeset
   562
        Options.init(specs =
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79679
diff changeset
   563
          Options.Spec.ISABELLE_BUILD_OPTIONS ::: List(Options.Spec.make("build_database")))
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   564
      var remove_builds = false
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   565
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   566
      val getopts = Getopts("""
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   567
Usage: isabelle build_process [OPTIONS]
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   568
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   569
  Options are:
79676
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79647
diff changeset
   570
    -C           build cluster mode (database server)
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   571
    -f           extra force for option -r
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   572
    -l           list build processes
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   573
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   574
    -r           remove data from build processes: inactive processes (default)
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   575
                 or all processes (option -f)
79700
aeb53334f521 proper usage;
wenzelm
parents: 79682
diff changeset
   576
aeb53334f521 proper usage;
wenzelm
parents: 79682
diff changeset
   577
  Manage Isabelle build process, notably distributed build cluster (option -C).
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   578
""",
79679
ba2c43592f35 proper treatment of "isabelle build_process -C" (amending 0cac7e3634d0);
wenzelm
parents: 79676
diff changeset
   579
        "C" -> (_ => build_cluster = true),
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   580
        "f" -> (_ => force = true),
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   581
        "l" -> (_ => list_builds = true),
78636
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   582
        "o:" -> (arg => options = options + arg),
163c392675dc support "isabelle build_process -r -f";
wenzelm
parents: 78634
diff changeset
   583
        "r" -> (_ => remove_builds = true))
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   584
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   585
      val more_args = getopts(args)
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   586
      if (more_args.nonEmpty) getopts.usage()
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   587
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   588
      val progress = new Console_Progress()
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   589
79676
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79647
diff changeset
   590
      build_process(options, build_cluster = build_cluster, list_builds = list_builds,
0cac7e3634d0 more explicit build_cluster flag to guard open_build_database server;
wenzelm
parents: 79647
diff changeset
   591
        remove_builds = remove_builds, force = force, progress = progress)
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   592
    })
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   593
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   594
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   595
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   596
  /* "isabelle build_worker" */
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   597
78444
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   598
  def build_worker_command(
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   599
    host: Build_Cluster.Host,
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   600
    ssh: SSH.System = SSH.Local,
78558
ca0fe2802123 tuned signature;
wenzelm
parents: 78556
diff changeset
   601
    build_options: List[Options.Spec] = Nil,
78444
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   602
    build_id: String = "",
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   603
    isabelle_home: Path = Path.current,
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   604
    afp_root: Option[Path] = None,
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   605
    dirs: List[Path] = Nil,
78637
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   606
    quiet: Boolean = false,
78444
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   607
    verbose: Boolean = false
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   608
  ): String = {
78916
e97fa2edf4b2 clarified signature;
wenzelm
parents: 78915
diff changeset
   609
    val options = build_options ::: Options.Spec.eq("build_hostname", host.name) :: host.options
79624
8e97d1fcbbc2 clarified signature;
wenzelm
parents: 79622
diff changeset
   610
    ssh.bash_path(Isabelle_Tool.exe(isabelle_home)) + " build_worker" +
78444
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   611
      if_proper(build_id, " -B " + Bash.string(build_id)) +
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   612
      if_proper(afp_root, " -A " + ssh.bash_path(afp_root.get)) +
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   613
      dirs.map(dir => " -d " + ssh.bash_path(dir)).mkString +
78560
39f6f180008d clarified signature;
wenzelm
parents: 78558
diff changeset
   614
      if_proper(host.numa, " -N") + " -j" + host.jobs +
78915
90756ad4d8d7 more accurate treatment of surrounding whitespace;
wenzelm
parents: 78908
diff changeset
   615
      Options.Spec.bash_strings(options, bg = true) +
78637
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   616
      if_proper(quiet, " -q") +
78444
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   617
      if_proper(verbose, " -v")
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   618
  }
3d1746a716fa clarified signature: Build_Cluster.Session.build_context;
wenzelm
parents: 78440
diff changeset
   619
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   620
  def build_worker(
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   621
    options: Options,
78410
c5170293d392 clarified options;
wenzelm
parents: 78408
diff changeset
   622
    build_id: String = "",
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   623
    progress: Progress = new Progress,
78420
c157af5f346e more pro-forma support for afp_root;
wenzelm
parents: 78418
diff changeset
   624
    afp_root: Option[Path] = None,
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   625
    dirs: List[Path] = Nil,
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   626
    numa_shuffling: Boolean = false,
79616
12bb31d01510 more robust type, with explicit default;
wenzelm
parents: 79615
diff changeset
   627
    max_jobs: Option[Int] = None
78568
a97d2b6b5c3e tuned signature;
wenzelm
parents: 78566
diff changeset
   628
  ): Results = {
79707
wenzelm
parents: 79705
diff changeset
   629
    val engine = Engine(engine_name(options))
wenzelm
parents: 79705
diff changeset
   630
    val store = engine.build_store(options, build_cluster = true)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   631
    val build_options = store.options
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   632
78372
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   633
    using(store.open_server()) { server =>
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   634
      using_optional(store.maybe_open_build_database(server = server)) { build_database =>
30d3faa6c245 reuse SSH.Server connection database server;
wenzelm
parents: 78368
diff changeset
   635
        val builds = read_builds(build_database)
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   636
78634
0beb46a96cf3 clarified output;
wenzelm
parents: 78633
diff changeset
   637
        val build_master = find_builds(build_database, build_id, builds.filter(_.active))
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   638
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   639
        val sessions_structure =
80056
9279e96eb34e clarified signature;
wenzelm
parents: 79873
diff changeset
   640
          Sessions.load_structure(build_options, dirs = AFP.main_dirs(afp_root) ::: dirs).
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   641
            selection(Sessions.Selection(sessions = build_master.sessions))
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   642
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   643
        val build_deps =
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   644
          Sessions.deps(sessions_structure, progress = progress, inlined_files = true).check_errors
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   645
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   646
        val build_context =
79707
wenzelm
parents: 79705
diff changeset
   647
          Context(store, build_deps, engine = engine, afp_root = afp_root,
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   648
            hostname = hostname(build_options), numa_shuffling = numa_shuffling,
79811
d9fc2cc37694 more robust build_start for master and workers (via database);
wenzelm
parents: 79810
diff changeset
   649
            build_uuid = build_master.build_uuid, build_start = Some(build_master.start),
d9fc2cc37694 more robust build_start for master and workers (via database);
wenzelm
parents: 79810
diff changeset
   650
            jobs = max_jobs.getOrElse(1))
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   651
79707
wenzelm
parents: 79705
diff changeset
   652
        engine.run_build_process(build_context, progress, server)
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   653
      }
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   654
    }
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   655
  }
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   656
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   657
  val isabelle_tool3 = Isabelle_Tool("build_worker", "start worker for session build process",
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   658
    Scala_Project.here,
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   659
    { args =>
78420
c157af5f346e more pro-forma support for afp_root;
wenzelm
parents: 78418
diff changeset
   660
      var afp_root: Option[Path] = None
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   661
      var build_id = ""
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   662
      var numa_shuffling = false
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   663
      val dirs = new mutable.ListBuffer[Path]
79616
12bb31d01510 more robust type, with explicit default;
wenzelm
parents: 79615
diff changeset
   664
      var max_jobs: Option[Int] = None
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   665
      var options =
79682
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79679
diff changeset
   666
        Options.init(specs =
1fa1b32b0379 build local log_db, with store/restore via optional database server;
wenzelm
parents: 79679
diff changeset
   667
          Options.Spec.ISABELLE_BUILD_OPTIONS ::: List(Options.Spec.make("build_database")))
78637
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   668
      var quiet = false
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   669
      var verbose = false
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   670
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   671
      val getopts = Getopts("""
78219
af2963b74752 support for identified builds;
wenzelm
parents: 78216
diff changeset
   672
Usage: isabelle build_worker [OPTIONS]
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   673
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   674
  Options are:
78420
c157af5f346e more pro-forma support for afp_root;
wenzelm
parents: 78418
diff changeset
   675
    -A ROOT      include AFP with given root directory (":" for """ + AFP.BASE.implode + """)
78411
wenzelm
parents: 78410
diff changeset
   676
    -B UUID      existing UUID for build process (default: from database)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   677
    -N           cyclic shuffling of NUMA CPU nodes (performance tuning)
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   678
    -d DIR       include session directory
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   679
    -j INT       maximum number of parallel jobs (default 1)
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   680
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
78637
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   681
    -q           quiet mode: no progress
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   682
    -v           verbose
77647
c14db5d67400 tuned output;
wenzelm
parents: 77628
diff changeset
   683
""",
78420
c157af5f346e more pro-forma support for afp_root;
wenzelm
parents: 78418
diff changeset
   684
        "A:" -> (arg => afp_root = Some(if (arg == ":") AFP.BASE else Path.explode(arg))),
78410
c5170293d392 clarified options;
wenzelm
parents: 78408
diff changeset
   685
        "B:" -> (arg => build_id = arg),
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   686
        "N" -> (_ => numa_shuffling = true),
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   687
        "d:" -> (arg => dirs += Path.explode(arg)),
79616
12bb31d01510 more robust type, with explicit default;
wenzelm
parents: 79615
diff changeset
   688
        "j:" -> (arg => max_jobs = Some(Value.Nat.parse(arg))),
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   689
        "o:" -> (arg => options = options + arg),
78637
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   690
        "q" -> (_ => quiet = true),
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   691
        "v" -> (_ => verbose = true))
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   692
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   693
      val more_args = getopts(args)
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   694
      if (more_args.nonEmpty) getopts.usage()
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   695
78637
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   696
      val progress =
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   697
        if (quiet && verbose) new Progress { override def verbose: Boolean = true }
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   698
        else if (quiet) new Progress
9a5d86549719 support "isabelle build_worker -q";
wenzelm
parents: 78636
diff changeset
   699
        else new Console_Progress(verbose = verbose)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   700
78568
a97d2b6b5c3e tuned signature;
wenzelm
parents: 78566
diff changeset
   701
      val results =
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   702
        progress.interrupt_handler {
78411
wenzelm
parents: 78410
diff changeset
   703
          build_worker(options,
wenzelm
parents: 78410
diff changeset
   704
            build_id = build_id,
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   705
            progress = progress,
78420
c157af5f346e more pro-forma support for afp_root;
wenzelm
parents: 78418
diff changeset
   706
            afp_root = afp_root,
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   707
            dirs = dirs.toList,
78368
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   708
            numa_shuffling = Host.numa_check(progress, numa_shuffling),
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   709
            max_jobs = max_jobs)
6689b4c07bba clarified signature: proper Scala function for command-line tool;
wenzelm
parents: 78280
diff changeset
   710
        }
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   711
78568
a97d2b6b5c3e tuned signature;
wenzelm
parents: 78566
diff changeset
   712
      if (!results.ok) sys.exit(results.rc)
77557
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   713
    })
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   714
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   715
eff08c3f89fe basic setup for "isabelle build_worker";
wenzelm
parents: 77555
diff changeset
   716
77563
cbb49fe8e5a2 renamed "isabelle log" to "isabelle build_log";
wenzelm
parents: 77559
diff changeset
   717
  /** "isabelle build_log" **/
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   718
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   719
  /* theory markup/messages from session database */
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   720
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   721
  def read_theory(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   722
    theory_context: Export.Theory_Context,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   723
    unicode_symbols: Boolean = false
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   724
  ): Option[Document.Snapshot] = {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   725
    def decode_bytes(bytes: Bytes): String =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   726
      Symbol.output(unicode_symbols, UTF8.decode_permissive(bytes))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   727
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   728
    def read(name: String): Export.Entry = theory_context(name, permissive = true)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   729
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   730
    def read_xml(name: String): XML.Body =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   731
      YXML.parse_body(decode_bytes(read(name).bytes), cache = theory_context.cache)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   732
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77719
diff changeset
   733
    def read_source_file(name: String): Store.Source_File =
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   734
      theory_context.session_context.source_file(name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   735
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   736
    for {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   737
      id <- theory_context.document_id()
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   738
      (thy_file, blobs_files) <- theory_context.files(permissive = true)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   739
    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   740
    yield {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   741
      val master_dir =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   742
        Path.explode(Url.strip_base_name(thy_file).getOrElse(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   743
          error("Cannot determine theory master directory: " + quote(thy_file))))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   744
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   745
      val blobs =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   746
        blobs_files.map { name =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   747
          val path = Path.explode(name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   748
          val src_path = File.relative_path(master_dir, path).getOrElse(path)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   749
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   750
          val file = read_source_file(name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   751
          val bytes = file.bytes
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   752
          val text = decode_bytes(bytes)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   753
          val chunk = Symbol.Text_Chunk(text)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   754
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   755
          Command.Blob(Document.Node.Name(name), src_path, Some((file.digest, chunk))) ->
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   756
            Document.Blobs.Item(bytes, text, chunk, changed = false)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   757
        }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   758
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   759
      val thy_source = decode_bytes(read_source_file(thy_file).bytes)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   760
      val thy_xml = read_xml(Export.MARKUP)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   761
      val blobs_xml =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   762
        for (i <- (1 to blobs.length).toList)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   763
          yield read_xml(Export.MARKUP + i)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   764
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   765
      val markups_index = Command.Markup_Index.make(blobs.map(_._1))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   766
      val markups =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   767
        Command.Markups.make(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   768
          for ((index, xml) <- markups_index.zip(thy_xml :: blobs_xml))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   769
          yield index -> Markup_Tree.from_XML(xml))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   770
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   771
      val results =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   772
        Command.Results.make(
78592
fdfe9b91d96e misc tuning: support "scalac -source 3.3";
wenzelm
parents: 78578
diff changeset
   773
          for (case elem@XML.Elem(Markup(_, Markup.Serial(i)), _) <- read_xml(Export.MESSAGES))
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   774
            yield i -> elem)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   775
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   776
      val command =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   777
        Command.unparsed(thy_source, theory = true, id = id,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   778
          node_name = Document.Node.Name(thy_file, theory = theory_context.theory),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   779
          blobs_info = Command.Blobs_Info.make(blobs),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   780
          markups = markups, results = results)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   781
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   782
      val doc_blobs = Document.Blobs.make(blobs)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   783
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   784
      Document.State.init.snippet(command, doc_blobs)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   785
    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   786
  }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   787
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   788
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   789
  /* print messages */
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   790
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   791
  def print_log(
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   792
    options: Options,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   793
    sessions: List[String],
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   794
    theories: List[String] = Nil,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   795
    message_head: List[Regex] = Nil,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   796
    message_body: List[Regex] = Nil,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   797
    progress: Progress = new Progress,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   798
    margin: Double = Pretty.default_margin,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   799
    breakgain: Double = Pretty.default_breakgain,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   800
    metric: Pretty.Metric = Symbol.Metric,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   801
    unicode_symbols: Boolean = false
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   802
  ): Unit = {
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77719
diff changeset
   803
    val store = Store(options)
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   804
    val session = new Session(options, Resources.bootstrap)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   805
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   806
    def check(filter: List[Regex], make_string: => String): Boolean =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   807
      filter.isEmpty || {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   808
        val s = Output.clean_yxml(make_string)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   809
        filter.forall(r => r.findFirstIn(Output.clean_yxml(s)).nonEmpty)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   810
      }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   811
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   812
    def print(session_name: String): Unit = {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   813
      using(Export.open_session_context0(store, session_name)) { session_context =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   814
        val result =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   815
          for {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   816
            db <- session_context.session_db()
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   817
            theories = store.read_theories(db, session_name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   818
            errors = store.read_errors(db, session_name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   819
            info <- store.read_build(db, session_name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   820
          } yield (theories, errors, info.return_code)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   821
        result match {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   822
          case None => store.error_database(session_name)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   823
          case Some((used_theories, errors, rc)) =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   824
            theories.filterNot(used_theories.toSet) match {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   825
              case Nil =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   826
              case bad => error("Unknown theories " + commas_quote(bad))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   827
            }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   828
            val print_theories =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   829
              if (theories.isEmpty) used_theories else used_theories.filter(theories.toSet)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   830
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   831
            for (thy <- print_theories) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   832
              val thy_heading = "\nTheory " + quote(thy) + " (in " + session_name + ")" + ":"
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   833
78280
865b44cbaad1 clarified modules (amending 570f65953173);
wenzelm
parents: 78237
diff changeset
   834
              Build.read_theory(session_context.theory(thy), unicode_symbols = unicode_symbols) match {
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   835
                case None => progress.echo(thy_heading + " MISSING")
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   836
                case Some(snapshot) =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   837
                  val rendering = new Rendering(snapshot, options, session)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   838
                  val messages =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   839
                    rendering.text_messages(Text.Range.full)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   840
                      .filter(message => progress.verbose || Protocol.is_exported(message.info))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   841
                  if (messages.nonEmpty) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   842
                    val line_document = Line.Document(snapshot.node.source)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   843
                    val buffer = new mutable.ListBuffer[String]
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   844
                    for (Text.Info(range, elem) <- messages) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   845
                      val line = line_document.position(range.start).line1
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   846
                      val pos = Position.Line_File(line, snapshot.node_name.node)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   847
                      def message_text: String =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   848
                        Protocol.message_text(elem, heading = true, pos = pos,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   849
                          margin = margin, breakgain = breakgain, metric = metric)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   850
                      val ok =
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   851
                        check(message_head, Protocol.message_heading(elem, pos)) &&
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   852
                        check(message_body, XML.content(Pretty.unformatted(List(elem))))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   853
                      if (ok) buffer += message_text
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   854
                    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   855
                    if (buffer.nonEmpty) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   856
                      progress.echo(thy_heading)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   857
                      buffer.foreach(progress.echo(_))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   858
                    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   859
                  }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   860
              }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   861
            }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   862
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   863
            if (errors.nonEmpty) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   864
              val msg = Symbol.output(unicode_symbols, cat_lines(errors))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   865
              progress.echo("\nBuild errors:\n" + Output.error_message_text(msg))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   866
            }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   867
            if (rc != Process_Result.RC.ok) {
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   868
              progress.echo("\n" + Process_Result.RC.print_long(rc))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   869
            }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   870
        }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   871
      }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   872
    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   873
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   874
    val errors = new mutable.ListBuffer[String]
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   875
    for (session_name <- sessions) {
78705
fde0b195cb7d clarified signature: avoid association with potentially dangerous Exn.capture;
wenzelm
parents: 78643
diff changeset
   876
      Exn.result(print(session_name)) match {
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   877
        case Exn.Res(_) =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   878
        case Exn.Exn(exn) => errors += Exn.message(exn)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   879
      }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   880
    }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   881
    if (errors.nonEmpty) error(cat_lines(errors.toList))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   882
  }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   883
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   884
79629
4d81c0391da2 tuned comments;
wenzelm
parents: 79624
diff changeset
   885
  /* Isabelle tool wrapper */
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   886
78562
53e3fa5e3720 clarified command-line tools;
wenzelm
parents: 78560
diff changeset
   887
  val isabelle_tool4 = Isabelle_Tool("build_log", "print messages from session build database",
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   888
    Scala_Project.here,
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   889
    { args =>
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   890
      /* arguments */
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   891
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   892
      val message_head = new mutable.ListBuffer[Regex]
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   893
      val message_body = new mutable.ListBuffer[Regex]
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   894
      var unicode_symbols = false
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   895
      val theories = new mutable.ListBuffer[String]
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   896
      var margin = Pretty.default_margin
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   897
      var options = Options.init()
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   898
      var verbose = false
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   899
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   900
      val getopts = Getopts("""
77563
cbb49fe8e5a2 renamed "isabelle log" to "isabelle build_log";
wenzelm
parents: 77559
diff changeset
   901
Usage: isabelle build_log [OPTIONS] [SESSIONS ...]
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   902
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   903
  Options are:
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   904
    -H REGEX     filter messages by matching against head
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   905
    -M REGEX     filter messages by matching against body
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   906
    -T NAME      restrict to given theories (multiple options possible)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   907
    -U           output Unicode symbols
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   908
    -m MARGIN    margin for pretty printing (default: """ + margin + """)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   909
    -o OPTION    override Isabelle system OPTION (via NAME=VAL or NAME)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   910
    -v           print all messages, including information etc.
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   911
77554
4465d9dff448 clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents: 77553
diff changeset
   912
  Print messages from the session build database of the given sessions,
4465d9dff448 clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents: 77553
diff changeset
   913
  without any checks against current sources nor session structure: results
4465d9dff448 clarified terminology of "session build database", while "build database" is the one underlying Build_Process;
wenzelm
parents: 77553
diff changeset
   914
  from old sessions or failed builds can be printed as well.
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   915
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   916
  Multiple options -H and -M are conjunctive: all given patterns need to
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   917
  match. Patterns match any substring, but ^ or $ may be used to match the
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   918
  start or end explicitly.
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   919
""",
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   920
        "H:" -> (arg => message_head += arg.r),
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   921
        "M:" -> (arg => message_body += arg.r),
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   922
        "T:" -> (arg => theories += arg),
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   923
        "U" -> (_ => unicode_symbols = true),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   924
        "m:" -> (arg => margin = Value.Double.parse(arg)),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   925
        "o:" -> (arg => options = options + arg),
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   926
        "v" -> (_ => verbose = true))
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   927
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   928
      val sessions = getopts(args)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   929
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   930
      val progress = new Console_Progress(verbose = verbose)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   931
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   932
      if (sessions.isEmpty) progress.echo_warning("No sessions to print")
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   933
      else {
78405
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   934
        print_log(options, sessions, theories = theories.toList, message_head = message_head.toList,
8ff1698e7247 minor performance tuning;
wenzelm
parents: 78403
diff changeset
   935
          message_body = message_body.toList, margin = margin, progress = progress,
77553
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   936
          unicode_symbols = unicode_symbols)
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   937
      }
570f65953173 clarified modules;
wenzelm
parents: 77546
diff changeset
   938
    })
48276
4bd480886813 basic setup for Isabelle build tool;
wenzelm
parents:
diff changeset
   939
}