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