src/Pure/Tools/build_job.scala
author wenzelm
Sun, 09 Jul 2023 17:41:02 +0200
changeset 78280 865b44cbaad1
parent 78237 c2c59de57df9
child 78359 cb0a90df4871
permissions -rw-r--r--
clarified modules (amending 570f65953173);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
72662
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Tools/build_job.scala
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     3
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     4
Build job running prover process, with rudimentary PIDE session.
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     5
*/
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     6
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     7
package isabelle
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     8
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
     9
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
    10
import scala.collection.mutable
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
    11
5c08ad7adf77 clarified modules;
wenzelm
parents:
diff changeset
    12
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
    13
trait Build_Job {
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
    14
  def cancel(): Unit = ()
77298
39c7d79ace34 clarified signature defaults;
wenzelm
parents: 77297
diff changeset
    15
  def is_finished: Boolean = false
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
    16
  def join: (Process_Result, SHA1.Shasum) = (Process_Result.undefined, SHA1.no_shasum)
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
    17
}
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
    18
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 74755
diff changeset
    19
object Build_Job {
77396
f184fbac99bc clarified modules;
wenzelm
parents: 77372
diff changeset
    20
  /* build session */
f184fbac99bc clarified modules;
wenzelm
parents: 77372
diff changeset
    21
77474
5ecaf881b563 clarified signature;
wenzelm
parents: 77473
diff changeset
    22
  def start_session(
5ecaf881b563 clarified signature;
wenzelm
parents: 77473
diff changeset
    23
    build_context: Build_Process.Context,
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
    24
    session_context: Session_Context,
77505
7ee426daafa3 support progress backed by database;
wenzelm
parents: 77496
diff changeset
    25
    progress: Progress,
7ee426daafa3 support progress backed by database;
wenzelm
parents: 77496
diff changeset
    26
    log: Logger,
78213
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78205
diff changeset
    27
    database_server: Option[SQL.Database],
77474
5ecaf881b563 clarified signature;
wenzelm
parents: 77473
diff changeset
    28
    session_background: Sessions.Background,
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
    29
    sources_shasum: SHA1.Shasum,
77474
5ecaf881b563 clarified signature;
wenzelm
parents: 77473
diff changeset
    30
    input_shasum: SHA1.Shasum,
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
    31
    node_info: Host.Node_Info,
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
    32
    store_heap: Boolean
77505
7ee426daafa3 support progress backed by database;
wenzelm
parents: 77496
diff changeset
    33
  ): Session_Job = {
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
    34
    new Session_Job(build_context, session_context, progress, log, database_server,
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
    35
      session_background, sources_shasum, input_shasum, node_info, store_heap)
77505
7ee426daafa3 support progress backed by database;
wenzelm
parents: 77496
diff changeset
    36
  }
77474
5ecaf881b563 clarified signature;
wenzelm
parents: 77473
diff changeset
    37
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    38
  object Session_Context {
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    39
    def load(
77529
40ccee0fe19a separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents: 77521
diff changeset
    40
      build_uuid: String,
77444
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    41
      name: String,
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    42
      deps: List[String],
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    43
      ancestors: List[String],
77610
3b09ae9e40cb clarified session prefs (or "options" within the database);
wenzelm
parents: 77587
diff changeset
    44
      session_prefs: String,
77458
403748b23f13 clarified signature: prefer static data;
wenzelm
parents: 77456
diff changeset
    45
      sources_shasum: SHA1.Shasum,
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    46
      timeout: Time,
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77652
diff changeset
    47
      store: Store,
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    48
      progress: Progress = new Progress
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    49
    ): Session_Context = {
77450
167b5095ba14 tuned signature (again);
wenzelm
parents: 77445
diff changeset
    50
      def default: Session_Context =
77496
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    51
        Session_Context(
77610
3b09ae9e40cb clarified session prefs (or "options" within the database);
wenzelm
parents: 77587
diff changeset
    52
          name, deps, ancestors, session_prefs, sources_shasum, timeout,
3b09ae9e40cb clarified session prefs (or "options" within the database);
wenzelm
parents: 77587
diff changeset
    53
          Time.zero, Bytes.empty, build_uuid)
77444
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    54
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    55
      store.try_open_database(name) match {
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    56
        case None => default
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    57
        case Some(db) =>
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    58
          def ignore_error(msg: String) = {
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    59
            progress.echo_warning(
77444
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    60
              "Ignoring bad database " + db + " for session " + quote(name) +
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    61
              if_proper(msg, ":\n" + msg))
77444
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    62
            default
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    63
          }
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    64
          try {
77444
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    65
            val command_timings = store.read_command_timings(db, name)
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    66
            val elapsed =
77444
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    67
              store.read_session_timing(db, name) match {
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    68
                case Markup.Elapsed(s) => Time.seconds(s)
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    69
                case _ => Time.zero
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    70
              }
77444
0c704aba71e3 clarified signature: reduce explicit access to static Sessions.Structure;
wenzelm
parents: 77442
diff changeset
    71
            new Session_Context(
77610
3b09ae9e40cb clarified session prefs (or "options" within the database);
wenzelm
parents: 77587
diff changeset
    72
              name, deps, ancestors, session_prefs, sources_shasum, timeout,
3b09ae9e40cb clarified session prefs (or "options" within the database);
wenzelm
parents: 77587
diff changeset
    73
              elapsed, command_timings, build_uuid)
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    74
          }
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    75
          catch {
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    76
            case ERROR(msg) => ignore_error(msg)
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    77
            case exn: java.lang.Error => ignore_error(Exn.message(exn))
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    78
            case _: XML.Error => ignore_error("XML.Error")
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    79
          }
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    80
          finally { db.close() }
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    81
      }
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    82
    }
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    83
  }
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    84
77496
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    85
  sealed case class Session_Context(
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    86
    name: String,
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    87
    deps: List[String],
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    88
    ancestors: List[String],
77610
3b09ae9e40cb clarified session prefs (or "options" within the database);
wenzelm
parents: 77587
diff changeset
    89
    session_prefs: String,
77496
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    90
    sources_shasum: SHA1.Shasum,
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    91
    timeout: Time,
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    92
    old_time: Time,
f0d9f9196b9b more database content;
wenzelm
parents: 77493
diff changeset
    93
    old_command_timings_blob: Bytes,
77529
40ccee0fe19a separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents: 77521
diff changeset
    94
    build_uuid: String
77652
5f706f7c624b more thorough synchronization of internal "_state" vs. external "_database";
wenzelm
parents: 77651
diff changeset
    95
  ) extends Library.Named
77442
9969b6aed223 clarified modules (again);
wenzelm
parents: 77414
diff changeset
    96
77474
5ecaf881b563 clarified signature;
wenzelm
parents: 77473
diff changeset
    97
  class Session_Job private[Build_Job](
77455
ce53c1ce8536 tuned signature;
wenzelm
parents: 77454
diff changeset
    98
    build_context: Build_Process.Context,
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
    99
    session_context: Session_Context,
77505
7ee426daafa3 support progress backed by database;
wenzelm
parents: 77496
diff changeset
   100
    progress: Progress,
7ee426daafa3 support progress backed by database;
wenzelm
parents: 77496
diff changeset
   101
    log: Logger,
78213
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78205
diff changeset
   102
    database_server: Option[SQL.Database],
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   103
    session_background: Sessions.Background,
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
   104
    sources_shasum: SHA1.Shasum,
77460
ccca589d7027 tuned signature: support general Build_Job instances;
wenzelm
parents: 77458
diff changeset
   105
    input_shasum: SHA1.Shasum,
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
   106
    node_info: Host.Node_Info,
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
   107
    store_heap: Boolean
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   108
  ) extends Build_Job {
77455
ce53c1ce8536 tuned signature;
wenzelm
parents: 77454
diff changeset
   109
    private val store = build_context.store
ce53c1ce8536 tuned signature;
wenzelm
parents: 77454
diff changeset
   110
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   111
    def session_name: String = session_background.session_name
77349
5a84de89170d more operations to support management of jobs, e.g. from external database;
wenzelm
parents: 77298
diff changeset
   112
77493
2d5529f56124 tuned signature;
wenzelm
parents: 77486
diff changeset
   113
    private val info: Sessions.Info = session_background.sessions_structure(session_name)
77550
ed2f53e1552c tuned signature;
wenzelm
parents: 77547
diff changeset
   114
    private val options: Options = node_info.process_policy(info.options)
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   115
77493
2d5529f56124 tuned signature;
wenzelm
parents: 77486
diff changeset
   116
    private val session_sources =
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77652
diff changeset
   117
      Store.Sources.load(session_background.base, cache = store.cache.compress)
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   118
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   119
    private val future_result: Future[(Process_Result, SHA1.Shasum)] =
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   120
      Future.thread("build", uninterruptible = true) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   121
        val env =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   122
          Isabelle_System.settings(
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   123
            List("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   124
77473
362bf802013e clarified modules;
wenzelm
parents: 77465
diff changeset
   125
        val session_heaps =
362bf802013e clarified modules;
wenzelm
parents: 77465
diff changeset
   126
          session_background.info.parent match {
362bf802013e clarified modules;
wenzelm
parents: 77465
diff changeset
   127
            case None => Nil
362bf802013e clarified modules;
wenzelm
parents: 77465
diff changeset
   128
            case Some(logic) => ML_Process.session_heaps(store, session_background, logic = logic)
362bf802013e clarified modules;
wenzelm
parents: 77465
diff changeset
   129
          }
362bf802013e clarified modules;
wenzelm
parents: 77465
diff changeset
   130
77414
0d5994eef9e6 clarified signature: allow to provide session_heaps by different means, e.g. from tmp directory or alternative session structure;
wenzelm
parents: 77410
diff changeset
   131
        val use_prelude = if (session_heaps.isEmpty) Thy_Header.ml_roots.map(_._1) else Nil
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   132
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   133
        val eval_store =
77463
4e8bec105ce5 tuned signature;
wenzelm
parents: 77460
diff changeset
   134
          if (store_heap) {
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   135
            (if (info.theories.nonEmpty) List("ML_Heap.share_common_data ()") else Nil) :::
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   136
            List("ML_Heap.save_child " +
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   137
              ML_Syntax.print_string_bytes(File.platform_path(store.output_heap(session_name))))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   138
          }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   139
          else Nil
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   140
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   141
        def session_blobs(node_name: Document.Node.Name): List[(Command.Blob, Document.Blobs.Item)] =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   142
          session_background.base.theory_load_commands.get(node_name.theory) match {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   143
            case None => Nil
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   144
            case Some(spans) =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   145
              val syntax = session_background.base.theory_syntax(node_name)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   146
              val master_dir = Path.explode(node_name.master_dir)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   147
              for (span <- spans; file <- span.loaded_files(syntax).files)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   148
                yield {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   149
                  val src_path = Path.explode(file)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   150
                  val blob_name = Document.Node.Name(File.symbolic_path(master_dir + src_path))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   151
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   152
                  val bytes = session_sources(blob_name.node).bytes
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   153
                  val text = bytes.text
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   154
                  val chunk = Symbol.Text_Chunk(text)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   155
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   156
                  Command.Blob(blob_name, src_path, Some((SHA1.digest(bytes), chunk))) ->
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   157
                    Document.Blobs.Item(bytes, text, chunk, changed = false)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   158
                }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   159
          }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   160
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   161
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   162
        /* session */
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   163
77473
362bf802013e clarified modules;
wenzelm
parents: 77465
diff changeset
   164
        val resources =
77505
7ee426daafa3 support progress backed by database;
wenzelm
parents: 77496
diff changeset
   165
          new Resources(session_background, log = log,
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
   166
            command_timings =
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
   167
              Properties.uncompress(session_context.old_command_timings_blob, cache = store.cache))
77473
362bf802013e clarified modules;
wenzelm
parents: 77465
diff changeset
   168
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   169
        val session =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   170
          new Session(options, resources) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   171
            override val cache: Term.Cache = store.cache
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   172
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   173
            override def build_blobs_info(node_name: Document.Node.Name): Command.Blobs_Info =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   174
              Command.Blobs_Info.make(session_blobs(node_name))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   175
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   176
            override def build_blobs(node_name: Document.Node.Name): Document.Blobs =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   177
              Document.Blobs.make(session_blobs(node_name))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   178
          }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   179
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   180
        object Build_Session_Errors {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   181
          private val promise: Promise[List[String]] = Future.promise
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   182
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   183
          def result: Exn.Result[List[String]] = promise.join_result
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   184
          def cancel(): Unit = promise.cancel()
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   185
          def apply(errs: List[String]): Unit = {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   186
            try { promise.fulfill(errs) }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   187
            catch { case _: IllegalStateException => }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   188
          }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   189
        }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   190
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   191
        val export_consumer =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   192
          Export.consumer(store.open_database(session_name, output = true), store.cache,
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   193
            progress = progress)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   194
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   195
        val stdout = new StringBuilder(1000)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   196
        val stderr = new StringBuilder(1000)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   197
        val command_timings = new mutable.ListBuffer[Properties.T]
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   198
        val theory_timings = new mutable.ListBuffer[Properties.T]
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   199
        val session_timings = new mutable.ListBuffer[Properties.T]
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   200
        val runtime_statistics = new mutable.ListBuffer[Properties.T]
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   201
        val task_statistics = new mutable.ListBuffer[Properties.T]
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   202
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   203
        def fun(
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   204
          name: String,
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   205
          acc: mutable.ListBuffer[Properties.T],
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   206
          unapply: Properties.T => Option[Properties.T]
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   207
        ): (String, Session.Protocol_Function) = {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   208
          name -> ((msg: Prover.Protocol_Output) =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   209
            unapply(msg.properties) match {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   210
              case Some(props) => acc += props; true
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   211
              case _ => false
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   212
            })
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   213
        }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   214
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   215
        session.init_protocol_handler(new Session.Protocol_Handler {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   216
            override def exit(): Unit = Build_Session_Errors.cancel()
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   217
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   218
            private def build_session_finished(msg: Prover.Protocol_Output): Boolean = {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   219
              val (rc, errors) =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   220
                try {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   221
                  val (rc, errs) = {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   222
                    import XML.Decode._
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   223
                    pair(int, list(x => x))(Symbol.decode_yxml(msg.text))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   224
                  }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   225
                  val errors =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   226
                    for (err <- errs) yield {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   227
                      val prt = Protocol_Message.expose_no_reports(err)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   228
                      Pretty.string_of(prt, metric = Symbol.Metric)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   229
                    }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   230
                  (rc, errors)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   231
                }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   232
                catch { case ERROR(err) => (Process_Result.RC.failure, List(err)) }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   233
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   234
              session.protocol_command("Prover.stop", rc.toString)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   235
              Build_Session_Errors(errors)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   236
              true
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   237
            }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   238
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   239
            private def loading_theory(msg: Prover.Protocol_Output): Boolean =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   240
              msg.properties match {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   241
                case Markup.Loading_Theory(Markup.Name(name)) =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   242
                  progress.theory(Progress.Theory(name, session = session_name))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   243
                  false
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   244
                case _ => false
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   245
              }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   246
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   247
            private def export_(msg: Prover.Protocol_Output): Boolean =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   248
              msg.properties match {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   249
                case Protocol.Export(args) =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   250
                  export_consumer.make_entry(session_name, args, msg.chunk)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   251
                  true
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   252
                case _ => false
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   253
              }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   254
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   255
            override val functions: Session.Protocol_Functions =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   256
              List(
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   257
                Markup.Build_Session_Finished.name -> build_session_finished,
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   258
                Markup.Loading_Theory.name -> loading_theory,
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   259
                Markup.EXPORT -> export_,
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   260
                fun(Markup.Theory_Timing.name, theory_timings, Markup.Theory_Timing.unapply),
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   261
                fun(Markup.Session_Timing.name, session_timings, Markup.Session_Timing.unapply),
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   262
                fun(Markup.Task_Statistics.name, task_statistics, Markup.Task_Statistics.unapply))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   263
          })
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   264
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   265
        session.command_timings += Session.Consumer("command_timings") {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   266
          case Session.Command_Timing(props) =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   267
            for {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   268
              elapsed <- Markup.Elapsed.unapply(props)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   269
              elapsed_time = Time.seconds(elapsed)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   270
              if elapsed_time.is_relevant && elapsed_time >= options.seconds("command_timing_threshold")
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   271
            } command_timings += props.filter(Markup.command_timing_property)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   272
        }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   273
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   274
        session.runtime_statistics += Session.Consumer("ML_statistics") {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   275
          case Session.Runtime_Statistics(props) => runtime_statistics += props
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   276
        }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   277
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   278
        session.finished_theories += Session.Consumer[Document.Snapshot]("finished_theories") {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   279
          case snapshot =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   280
            if (!progress.stopped) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   281
              def export_(name: String, xml: XML.Body, compress: Boolean = true): Unit = {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   282
                if (!progress.stopped) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   283
                  val theory_name = snapshot.node_name.theory
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   284
                  val args =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   285
                    Protocol.Export.Args(theory_name = theory_name, name = name, compress = compress)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   286
                  val body = Bytes(Symbol.encode(YXML.string_of_body(xml)))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   287
                  export_consumer.make_entry(session_name, args, body)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   288
                }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   289
              }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   290
              def export_text(name: String, text: String, compress: Boolean = true): Unit =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   291
                export_(name, List(XML.Text(text)), compress = compress)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   292
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   293
              for (command <- snapshot.snippet_command) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   294
                export_text(Export.DOCUMENT_ID, command.id.toString, compress = false)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   295
              }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   296
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   297
              export_text(Export.FILES,
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   298
                cat_lines(snapshot.node_files.map(name => File.symbolic_path(name.path))),
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   299
                compress = false)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   300
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   301
              for ((blob_name, i) <- snapshot.node_files.tail.zipWithIndex) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   302
                val xml = snapshot.switch(blob_name).xml_markup()
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   303
                export_(Export.MARKUP + (i + 1), xml)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   304
              }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   305
              export_(Export.MARKUP, snapshot.xml_markup())
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   306
              export_(Export.MESSAGES, snapshot.messages.map(_._1))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   307
            }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   308
        }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   309
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   310
        session.all_messages += Session.Consumer[Any]("build_session_output") {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   311
          case msg: Prover.Output =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   312
            val message = msg.message
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   313
            if (msg.is_system) resources.log(Protocol.message_text(message))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   314
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   315
            if (msg.is_stdout) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   316
              stdout ++= Symbol.encode(XML.content(message))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   317
            }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   318
            else if (msg.is_stderr) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   319
              stderr ++= Symbol.encode(XML.content(message))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   320
            }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   321
            else if (msg.is_exit) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   322
              val err =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   323
                "Prover terminated" +
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   324
                  (msg.properties match {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   325
                    case Markup.Process_Result(result) => ": " + result.print_rc
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   326
                    case _ => ""
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   327
                  })
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   328
              Build_Session_Errors(List(err))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   329
            }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   330
          case _ =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   331
        }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   332
77455
ce53c1ce8536 tuned signature;
wenzelm
parents: 77454
diff changeset
   333
        build_context.session_setup(session_name, session)
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   334
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   335
        val eval_main = Command_Line.ML_tool("Isabelle_Process.init_build ()" :: eval_store)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   336
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   337
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   338
        /* process */
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   339
77485
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   340
        val process =
77414
0d5994eef9e6 clarified signature: allow to provide session_heaps by different means, e.g. from tmp directory or alternative session structure;
wenzelm
parents: 77410
diff changeset
   341
          Isabelle_Process.start(options, session, session_background, session_heaps,
0d5994eef9e6 clarified signature: allow to provide session_heaps by different means, e.g. from tmp directory or alternative session structure;
wenzelm
parents: 77410
diff changeset
   342
            use_prelude = use_prelude, eval_main = eval_main, cwd = info.dir.file, env = env)
77485
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   343
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   344
        val timeout_request: Option[Event_Timer.Request] =
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   345
          if (info.timeout_ignored) None
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   346
          else Some(Event_Timer.request(Time.now() + info.timeout) { process.terminate() })
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   347
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   348
        val build_errors =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   349
          Isabelle_Thread.interrupt_handler(_ => process.terminate()) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   350
            Exn.capture { process.await_startup() } match {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   351
              case Exn.Res(_) =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   352
                val resources_yxml = resources.init_session_yxml
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   353
                val encode_options: XML.Encode.T[Options] =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   354
                  options => session.prover_options(options).encode
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   355
                val args_yxml =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   356
                  YXML.string_of_body(
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   357
                    {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   358
                      import XML.Encode._
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   359
                      pair(string, list(pair(encode_options, list(pair(string, properties)))))(
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   360
                        (session_name, info.theories))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   361
                    })
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   362
                session.protocol_command("build_session", resources_yxml, args_yxml)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   363
                Build_Session_Errors.result
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   364
              case Exn.Exn(exn) => Exn.Res(List(Exn.message(exn)))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   365
            }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   366
          }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   367
77484
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   368
        val result0 =
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   369
          Isabelle_Thread.interrupt_handler(_ => process.terminate()) { process.await_shutdown() }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   370
77485
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   371
        val was_timeout =
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   372
          timeout_request match {
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   373
            case None => false
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   374
            case Some(request) => !request.cancel()
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   375
          }
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   376
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   377
        session.stop()
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   378
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   379
        val export_errors =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   380
          export_consumer.shutdown(close = true).map(Output.error_message_text)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   381
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   382
        val (document_output, document_errors) =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   383
          try {
77484
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   384
            if (build_errors.isInstanceOf[Exn.Res[_]] && result0.ok && info.documents.nonEmpty) {
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   385
              using(Export.open_database_context(store)) { database_context =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   386
                val documents =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   387
                  using(database_context.open_session(session_background)) {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   388
                    session_context =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   389
                      Document_Build.build_documents(
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   390
                        Document_Build.context(session_context, progress = progress),
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   391
                        output_sources = info.document_output,
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   392
                        output_pdf = info.document_output)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   393
                  }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   394
                using(database_context.open_database(session_name, output = true))(session_database =>
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   395
                  documents.foreach(_.write(session_database.db, session_name)))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   396
                (documents.flatMap(_.log_lines), Nil)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   397
              }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   398
            }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   399
            else (Nil, Nil)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   400
          }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   401
          catch {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   402
            case exn: Document_Build.Build_Error => (exn.log_lines, exn.log_errors)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   403
            case Exn.Interrupt.ERROR(msg) => (Nil, List(msg))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   404
          }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   405
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   406
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   407
        /* process result */
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   408
77484
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   409
        val result1 = {
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   410
          val theory_timing =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   411
            theory_timings.iterator.flatMap(
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   412
              {
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   413
                case props @ Markup.Name(name) => Some(name -> props)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   414
                case _ => None
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   415
              }).toMap
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   416
          val used_theory_timings =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   417
            for { (name, _) <- session_background.base.used_theories }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   418
              yield theory_timing.getOrElse(name.theory, Markup.Name(name.theory))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   419
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   420
          val more_output =
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   421
            Library.trim_line(stdout.toString) ::
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   422
              command_timings.toList.map(Protocol.Command_Timing_Marker.apply) :::
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   423
              used_theory_timings.map(Protocol.Theory_Timing_Marker.apply) :::
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   424
              session_timings.toList.map(Protocol.Session_Timing_Marker.apply) :::
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   425
              runtime_statistics.toList.map(Protocol.ML_Statistics_Marker.apply) :::
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   426
              task_statistics.toList.map(Protocol.Task_Statistics_Marker.apply) :::
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   427
              document_output
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   428
77484
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   429
          result0.output(more_output)
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   430
            .error(Library.trim_line(stderr.toString))
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   431
            .errors_rc(export_errors ::: document_errors)
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   432
        }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   433
77484
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   434
        val result2 =
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   435
          build_errors match {
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   436
            case Exn.Res(build_errs) =>
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   437
              val errs = build_errs ::: document_errors
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   438
              if (errs.nonEmpty) {
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   439
                result1.error_rc.output(
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   440
                  errs.flatMap(s => split_lines(Output.error_message_text(s))) :::
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   441
                    errs.map(Protocol.Error_Message_Marker.apply))
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   442
              }
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   443
              else if (progress.stopped && result1.ok) result1.copy(rc = Process_Result.RC.interrupt)
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   444
              else result1
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   445
            case Exn.Exn(Exn.Interrupt()) =>
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   446
              if (result1.ok) result1.copy(rc = Process_Result.RC.interrupt)
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   447
              else result1
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   448
            case Exn.Exn(exn) => throw exn
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   449
          }
7ba474a01249 tuned names;
wenzelm
parents: 77477
diff changeset
   450
77485
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   451
        val process_result =
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   452
          if (result2.ok) result2
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   453
          else if (was_timeout) result2.error(Output.error_message_text("Timeout")).timeout_rc
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   454
          else if (result2.interrupted) result2.error(Output.error_message_text("Interrupt"))
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   455
          else result2
911d3dbf2033 clarified timeout: closer to actual process;
wenzelm
parents: 77484
diff changeset
   456
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   457
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   458
        /* output heap */
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   459
78184
wenzelm
parents: 78183
diff changeset
   460
        val output_shasum = {
wenzelm
parents: 78183
diff changeset
   461
          val heap = store.output_heap(session_name)
wenzelm
parents: 78183
diff changeset
   462
          if (process_result.ok && store_heap && heap.is_file) {
78188
fd68b98de1f6 prefer system option;
wenzelm
parents: 78184
diff changeset
   463
            val slice = Space.MiB(options.real("build_database_slice")).bytes
78213
fd0430a7b7a4 avoid repeated open_database_server: synchronized transaction_lock;
wenzelm
parents: 78205
diff changeset
   464
            val digest = ML_Heap.store(database_server, session_name, heap, slice)
78188
fd68b98de1f6 prefer system option;
wenzelm
parents: 78184
diff changeset
   465
            SHA1.shasum(digest, session_name)
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   466
          }
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   467
          else SHA1.no_shasum
78184
wenzelm
parents: 78183
diff changeset
   468
        }
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   469
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   470
        val log_lines = process_result.out_lines.filterNot(Protocol_Message.Marker.test)
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   471
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   472
        val build_log =
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   473
          Build_Log.Log_File(session_name, process_result.out_lines).
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   474
            parse_session_info(
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   475
              command_timings = true,
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   476
              theory_timings = true,
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   477
              ml_statistics = true,
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   478
              task_statistics = true)
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   479
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   480
        // write log file
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   481
        if (process_result.ok) {
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   482
          File.write_gzip(store.output_log_gz(session_name), terminate_lines(log_lines))
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   483
        }
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   484
        else File.write(store.output_log(session_name), terminate_lines(log_lines))
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   485
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   486
        // write database
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   487
        using(store.open_database(session_name, output = true))(db =>
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   488
          store.write_session_info(db, session_name, session_sources,
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   489
            build_log =
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   490
              if (process_result.timeout) build_log.error("Timeout") else build_log,
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   491
            build =
78178
a177f71dc79f clarified modules;
wenzelm
parents: 77652
diff changeset
   492
              Store.Build_Info(
78237
c2c59de57df9 clarified static Build_Process.Context vs. dynamic Build_Process.State;
wenzelm
parents: 78213
diff changeset
   493
                sources = sources_shasum,
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   494
                input_heaps = input_shasum,
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   495
                output_heap = output_shasum,
77529
40ccee0fe19a separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents: 77521
diff changeset
   496
                process_result.rc,
40ccee0fe19a separate static build_uuid from dynamic worker_uuid, to allow multiple worker processes participate in one build process;
wenzelm
parents: 77521
diff changeset
   497
                build_context.build_uuid)))
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   498
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   499
        // messages
77509
3bc49507bae5 clarified treatment of "verbose" messages, e.g. Progress.theory();
wenzelm
parents: 77505
diff changeset
   500
        process_result.err_lines.foreach(progress.echo(_))
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   501
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   502
        if (process_result.ok) {
77521
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77509
diff changeset
   503
          val props = build_log.session_timing
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77509
diff changeset
   504
          val threads = Markup.Session_Timing.Threads.unapply(props) getOrElse 1
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77509
diff changeset
   505
          val timing = Markup.Timing_Properties.get(props)
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77509
diff changeset
   506
          progress.echo(
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77509
diff changeset
   507
            "Timing " + session_name + " (" + threads + " threads, " + timing.message_factor + ")",
5642de4d225d clarified signature: manage "verbose" flag via "progress";
wenzelm
parents: 77509
diff changeset
   508
            verbose = true)
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   509
          progress.echo(
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   510
            "Finished " + session_name + " (" + process_result.timing.message_resources + ")")
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   511
        }
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   512
        else {
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   513
          progress.echo(
77563
cbb49fe8e5a2 renamed "isabelle log" to "isabelle build_log";
wenzelm
parents: 77553
diff changeset
   514
            session_name + " FAILED (see also \"isabelle build_log -H Error " + session_name + "\")")
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   515
          if (!process_result.interrupted) {
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   516
            val tail = info.options.int("process_output_tail")
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   517
            val suffix = if (tail == 0) log_lines else log_lines.drop(log_lines.length - tail max 0)
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   518
            val prefix = if (log_lines.length == suffix.length) Nil else List("...")
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   519
            progress.echo(Library.trim_line(cat_lines(prefix ::: suffix)))
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   520
          }
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   521
        }
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   522
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   523
        (process_result.copy(out_lines = log_lines), output_shasum)
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   524
      }
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   525
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   526
    override def cancel(): Unit = future_result.cancel()
77298
39c7d79ace34 clarified signature defaults;
wenzelm
parents: 77297
diff changeset
   527
    override def is_finished: Boolean = future_result.is_finished
77486
032c76e04475 clarified execution context: main work happens within Future.thread;
wenzelm
parents: 77485
diff changeset
   528
    override def join: (Process_Result, SHA1.Shasum) = future_result.join
77297
226a880d0423 clarified types: support a variety of Build_Job instances;
wenzelm
parents: 77294
diff changeset
   529
  }
72848
d5d0e36eda16 read theory with PIDE markup from session database;
wenzelm
parents: 72844
diff changeset
   530
}