author | wenzelm |
Mon, 27 Feb 2023 14:57:39 +0100 | |
changeset 77396 | f184fbac99bc |
parent 77372 | 44fe9fe96130 |
child 77397 | f7e14f567adf |
permissions | -rw-r--r-- |
72662 | 1 |
/* Title: Pure/Tools/build_job.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Build job running prover process, with rudimentary PIDE session. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
10 |
import scala.collection.mutable |
|
76087 | 11 |
import scala.util.matching.Regex |
72662 | 12 |
|
13 |
||
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
14 |
trait Build_Job { |
77349
5a84de89170d
more operations to support management of jobs, e.g. from external database;
wenzelm
parents:
77298
diff
changeset
|
15 |
def job_name: String |
77372 | 16 |
def node_info: Build_Job.Node_Info |
77298 | 17 |
def start(): Unit = () |
18 |
def terminate(): Unit = () |
|
19 |
def is_finished: Boolean = false |
|
77396 | 20 |
def finish: (Process_Result, SHA1.Shasum) = (Process_Result.undefined, SHA1.no_shasum) |
77372 | 21 |
def make_abstract: Build_Job.Abstract = Build_Job.Abstract(job_name, node_info) |
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
22 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
23 |
|
75393 | 24 |
object Build_Job { |
77372 | 25 |
object Node_Info { def none: Node_Info = Node_Info("", None) } |
26 |
sealed case class Node_Info(hostname: String, numa_node: Option[Int]) |
|
27 |
||
28 |
sealed case class Result(node_info: Node_Info, process_result: Process_Result) { |
|
29 |
def ok: Boolean = process_result.ok |
|
30 |
} |
|
31 |
||
77371 | 32 |
sealed case class Abstract( |
77349
5a84de89170d
more operations to support management of jobs, e.g. from external database;
wenzelm
parents:
77298
diff
changeset
|
33 |
override val job_name: String, |
77372 | 34 |
override val node_info: Node_Info |
77349
5a84de89170d
more operations to support management of jobs, e.g. from external database;
wenzelm
parents:
77298
diff
changeset
|
35 |
) extends Build_Job { |
5a84de89170d
more operations to support management of jobs, e.g. from external database;
wenzelm
parents:
77298
diff
changeset
|
36 |
override def make_abstract: Abstract = this |
5a84de89170d
more operations to support management of jobs, e.g. from external database;
wenzelm
parents:
77298
diff
changeset
|
37 |
} |
5a84de89170d
more operations to support management of jobs, e.g. from external database;
wenzelm
parents:
77298
diff
changeset
|
38 |
|
77396 | 39 |
|
40 |
/* build session */ |
|
41 |
||
42 |
def session_finished(session_name: String, timing: Timing): String = |
|
43 |
"Finished " + session_name + " (" + timing.message_resources + ")" |
|
44 |
||
45 |
def session_timing(session_name: String, props: Properties.T): String = { |
|
46 |
val threads = Markup.Session_Timing.Threads.unapply(props) getOrElse 1 |
|
47 |
val timing = Markup.Timing_Properties.get(props) |
|
48 |
"Timing " + session_name + " (" + threads + " threads, " + timing.message_factor + ")" |
|
49 |
} |
|
50 |
||
51 |
class Build_Session( |
|
52 |
progress: Progress, |
|
53 |
verbose: Boolean, |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
54 |
session_background: Sessions.Background, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
55 |
store: Sessions.Store, |
77396 | 56 |
do_store: Boolean, |
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
57 |
resources: Resources, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
58 |
session_setup: (String, Session) => Unit, |
77396 | 59 |
sources_shasum: SHA1.Shasum, |
60 |
input_heaps: SHA1.Shasum, |
|
77372 | 61 |
override val node_info: Node_Info |
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
62 |
) extends Build_Job { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
63 |
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
|
64 |
def job_name: String = session_name |
5a84de89170d
more operations to support management of jobs, e.g. from external database;
wenzelm
parents:
77298
diff
changeset
|
65 |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
66 |
val info: Sessions.Info = session_background.sessions_structure(session_name) |
77372 | 67 |
val options: Options = NUMA.policy_options(info.options, node_info.numa_node) |
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
68 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
69 |
val session_sources: Sessions.Sources = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
70 |
Sessions.Sources.load(session_background.base, cache = store.cache.compress) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
71 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
72 |
private lazy val future_result: Future[Process_Result] = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
73 |
Future.thread("build", uninterruptible = true) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
74 |
val parent = info.parent.getOrElse("") |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
75 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
76 |
val env = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
77 |
Isabelle_System.settings( |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
78 |
List("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
79 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
80 |
val is_pure = Sessions.is_pure(session_name) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
81 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
82 |
val use_prelude = if (is_pure) Thy_Header.ml_roots.map(_._1) else Nil |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
83 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
84 |
val eval_store = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
85 |
if (do_store) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
86 |
(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
|
87 |
List("ML_Heap.save_child " + |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
88 |
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
|
89 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
90 |
else Nil |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
91 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
case None => Nil |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
95 |
case Some(spans) => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
96 |
val syntax = session_background.base.theory_syntax(node_name) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
97 |
val master_dir = Path.explode(node_name.master_dir) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
98 |
for (span <- spans; file <- span.loaded_files(syntax).files) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
99 |
yield { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
100 |
val src_path = Path.explode(file) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
101 |
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
|
102 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
103 |
val bytes = session_sources(blob_name.node).bytes |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
104 |
val text = bytes.text |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
105 |
val chunk = Symbol.Text_Chunk(text) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
106 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
107 |
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
|
108 |
Document.Blobs.Item(bytes, text, chunk, changed = false) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
109 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
110 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
111 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
112 |
val session = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
113 |
new Session(options, resources) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
114 |
override val cache: Term.Cache = store.cache |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
115 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
116 |
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
|
117 |
Command.Blobs_Info.make(session_blobs(node_name)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
118 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
119 |
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
|
120 |
Document.Blobs.make(session_blobs(node_name)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
121 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
122 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
123 |
object Build_Session_Errors { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
124 |
private val promise: Promise[List[String]] = Future.promise |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
125 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
126 |
def result: Exn.Result[List[String]] = promise.join_result |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
127 |
def cancel(): Unit = promise.cancel() |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
128 |
def apply(errs: List[String]): Unit = { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
129 |
try { promise.fulfill(errs) } |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
130 |
catch { case _: IllegalStateException => } |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
131 |
} |
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 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
134 |
val export_consumer = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
135 |
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
|
136 |
progress = progress) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
137 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
138 |
val stdout = new StringBuilder(1000) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
139 |
val stderr = new StringBuilder(1000) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
140 |
val command_timings = new mutable.ListBuffer[Properties.T] |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
141 |
val theory_timings = new mutable.ListBuffer[Properties.T] |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
142 |
val session_timings = new mutable.ListBuffer[Properties.T] |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
143 |
val runtime_statistics = new mutable.ListBuffer[Properties.T] |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
144 |
val task_statistics = new mutable.ListBuffer[Properties.T] |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
145 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
146 |
def fun( |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
147 |
name: String, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
148 |
acc: mutable.ListBuffer[Properties.T], |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
149 |
unapply: Properties.T => Option[Properties.T] |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
150 |
): (String, Session.Protocol_Function) = { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
151 |
name -> ((msg: Prover.Protocol_Output) => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
152 |
unapply(msg.properties) match { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
153 |
case Some(props) => acc += props; true |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
154 |
case _ => false |
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 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
157 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
158 |
session.init_protocol_handler(new Session.Protocol_Handler { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
159 |
override def exit(): Unit = Build_Session_Errors.cancel() |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
160 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
161 |
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
|
162 |
val (rc, errors) = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
163 |
try { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
164 |
val (rc, errs) = { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
165 |
import XML.Decode._ |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
166 |
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
|
167 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
168 |
val errors = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
169 |
for (err <- errs) yield { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
170 |
val prt = Protocol_Message.expose_no_reports(err) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
171 |
Pretty.string_of(prt, metric = Symbol.Metric) |
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 |
(rc, errors) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
174 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
175 |
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
|
176 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
177 |
session.protocol_command("Prover.stop", rc.toString) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
178 |
Build_Session_Errors(errors) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
179 |
true |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
180 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
181 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
182 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
183 |
msg.properties match { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
184 |
case Markup.Loading_Theory(Markup.Name(name)) => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
185 |
progress.theory(Progress.Theory(name, session = session_name)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
186 |
false |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
187 |
case _ => false |
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 |
private def export_(msg: Prover.Protocol_Output): Boolean = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
191 |
msg.properties match { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
192 |
case Protocol.Export(args) => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
193 |
export_consumer.make_entry(session_name, args, msg.chunk) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
194 |
true |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
195 |
case _ => false |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
196 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
197 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
198 |
override val functions: Session.Protocol_Functions = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
199 |
List( |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
200 |
Markup.Build_Session_Finished.name -> build_session_finished, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
201 |
Markup.Loading_Theory.name -> loading_theory, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
202 |
Markup.EXPORT -> export_, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
}) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
207 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
208 |
session.command_timings += Session.Consumer("command_timings") { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
209 |
case Session.Command_Timing(props) => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
210 |
for { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
211 |
elapsed <- Markup.Elapsed.unapply(props) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
212 |
elapsed_time = Time.seconds(elapsed) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
213 |
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
|
214 |
} command_timings += props.filter(Markup.command_timing_property) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
215 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
216 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
217 |
session.runtime_statistics += Session.Consumer("ML_statistics") { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
218 |
case Session.Runtime_Statistics(props) => runtime_statistics += props |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
219 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
220 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
221 |
session.finished_theories += Session.Consumer[Document.Snapshot]("finished_theories") { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
222 |
case snapshot => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
223 |
if (!progress.stopped) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
224 |
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
|
225 |
if (!progress.stopped) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
226 |
val theory_name = snapshot.node_name.theory |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
227 |
val args = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
228 |
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
|
229 |
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
|
230 |
export_consumer.make_entry(session_name, args, body) |
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 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
233 |
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
|
234 |
export_(name, List(XML.Text(text)), compress = compress) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
235 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
236 |
for (command <- snapshot.snippet_command) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
237 |
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
|
238 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
239 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
240 |
export_text(Export.FILES, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
241 |
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
|
242 |
compress = false) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
243 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
244 |
for ((blob_name, i) <- snapshot.node_files.tail.zipWithIndex) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
245 |
val xml = snapshot.switch(blob_name).xml_markup() |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
246 |
export_(Export.MARKUP + (i + 1), xml) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
247 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
248 |
export_(Export.MARKUP, snapshot.xml_markup()) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
249 |
export_(Export.MESSAGES, snapshot.messages.map(_._1)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
250 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
251 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
252 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
253 |
session.all_messages += Session.Consumer[Any]("build_session_output") { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
254 |
case msg: Prover.Output => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
255 |
val message = msg.message |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
256 |
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
|
257 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
258 |
if (msg.is_stdout) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
259 |
stdout ++= Symbol.encode(XML.content(message)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
260 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
261 |
else if (msg.is_stderr) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
262 |
stderr ++= Symbol.encode(XML.content(message)) |
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 |
else if (msg.is_exit) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
265 |
val err = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
266 |
"Prover terminated" + |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
267 |
(msg.properties match { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
268 |
case Markup.Process_Result(result) => ": " + result.print_rc |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
269 |
case _ => "" |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
270 |
}) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
271 |
Build_Session_Errors(List(err)) |
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 |
case _ => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
274 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
275 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
276 |
session_setup(session_name, session) |
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 |
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
|
279 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
280 |
val process = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
281 |
Isabelle_Process.start(store, options, session, session_background, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
282 |
logic = parent, raw_ml_system = is_pure, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
283 |
use_prelude = use_prelude, eval_main = eval_main, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
284 |
cwd = info.dir.file, env = env) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
285 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
286 |
val build_errors = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
287 |
Isabelle_Thread.interrupt_handler(_ => process.terminate()) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
288 |
Exn.capture { process.await_startup() } match { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
289 |
case Exn.Res(_) => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
290 |
val resources_yxml = resources.init_session_yxml |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
291 |
val encode_options: XML.Encode.T[Options] = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
292 |
options => session.prover_options(options).encode |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
293 |
val args_yxml = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
294 |
YXML.string_of_body( |
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 |
import XML.Encode._ |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
297 |
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
|
298 |
(session_name, info.theories)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
299 |
}) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
300 |
session.protocol_command("build_session", resources_yxml, args_yxml) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
301 |
Build_Session_Errors.result |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
302 |
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
|
303 |
} |
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 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
306 |
val process_result = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
307 |
Isabelle_Thread.interrupt_handler(_ => process.terminate()) { process.await_shutdown() } |
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 |
session.stop() |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
310 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
311 |
val export_errors = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
312 |
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
|
313 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
314 |
val (document_output, document_errors) = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
315 |
try { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
316 |
if (build_errors.isInstanceOf[Exn.Res[_]] && process_result.ok && info.documents.nonEmpty) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
317 |
using(Export.open_database_context(store)) { database_context => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
318 |
val documents = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
319 |
using(database_context.open_session(session_background)) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
320 |
session_context => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
321 |
Document_Build.build_documents( |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
322 |
Document_Build.context(session_context, progress = progress), |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
323 |
output_sources = info.document_output, |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
324 |
output_pdf = info.document_output) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
325 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
326 |
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
|
327 |
documents.foreach(_.write(session_database.db, session_name))) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
328 |
(documents.flatMap(_.log_lines), Nil) |
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 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
331 |
else (Nil, Nil) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
332 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
333 |
catch { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
334 |
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
|
335 |
case Exn.Interrupt.ERROR(msg) => (Nil, List(msg)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
336 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
337 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
338 |
val result = { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
339 |
val theory_timing = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
340 |
theory_timings.iterator.flatMap( |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
341 |
{ |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
342 |
case props @ Markup.Name(name) => Some(name -> props) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
343 |
case _ => None |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
344 |
}).toMap |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
345 |
val used_theory_timings = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
346 |
for { (name, _) <- session_background.base.used_theories } |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
347 |
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
|
348 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
349 |
val more_output = |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
350 |
Library.trim_line(stdout.toString) :: |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
351 |
command_timings.toList.map(Protocol.Command_Timing_Marker.apply) ::: |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
352 |
used_theory_timings.map(Protocol.Theory_Timing_Marker.apply) ::: |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
353 |
session_timings.toList.map(Protocol.Session_Timing_Marker.apply) ::: |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
354 |
runtime_statistics.toList.map(Protocol.ML_Statistics_Marker.apply) ::: |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
355 |
task_statistics.toList.map(Protocol.Task_Statistics_Marker.apply) ::: |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
356 |
document_output |
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 |
process_result.output(more_output) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
359 |
.error(Library.trim_line(stderr.toString)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
360 |
.errors_rc(export_errors ::: document_errors) |
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 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
363 |
build_errors match { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
364 |
case Exn.Res(build_errs) => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
365 |
val errs = build_errs ::: document_errors |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
366 |
if (errs.nonEmpty) { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
367 |
result.error_rc.output( |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
368 |
errs.flatMap(s => split_lines(Output.error_message_text(s))) ::: |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
369 |
errs.map(Protocol.Error_Message_Marker.apply)) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
370 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
371 |
else if (progress.stopped && result.ok) result.copy(rc = Process_Result.RC.interrupt) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
372 |
else result |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
373 |
case Exn.Exn(Exn.Interrupt()) => |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
374 |
if (result.ok) result.copy(rc = Process_Result.RC.interrupt) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
375 |
else result |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
376 |
case Exn.Exn(exn) => throw exn |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
377 |
} |
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 |
|
77298 | 380 |
override def start(): Unit = future_result |
381 |
override def terminate(): Unit = future_result.cancel() |
|
382 |
override def is_finished: Boolean = future_result.is_finished |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
383 |
|
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
384 |
private val timeout_request: Option[Event_Timer.Request] = { |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
385 |
if (info.timeout_ignored) None |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
386 |
else Some(Event_Timer.request(Time.now() + info.timeout) { terminate() }) |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
387 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
388 |
|
77396 | 389 |
override lazy val finish: (Process_Result, SHA1.Shasum) = { |
390 |
val process_result = { |
|
391 |
val result = future_result.join |
|
392 |
||
393 |
val was_timeout = |
|
394 |
timeout_request match { |
|
395 |
case None => false |
|
396 |
case Some(request) => !request.cancel() |
|
397 |
} |
|
398 |
||
399 |
if (result.ok) result |
|
400 |
else if (was_timeout) result.error(Output.error_message_text("Timeout")).timeout_rc |
|
401 |
else if (result.interrupted) result.error(Output.error_message_text("Interrupt")) |
|
402 |
else result |
|
403 |
} |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
404 |
|
77396 | 405 |
val output_heap = |
406 |
if (process_result.ok && do_store && store.output_heap(session_name).is_file) { |
|
407 |
SHA1.shasum(ML_Heap.write_digest(store.output_heap(session_name)), session_name) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
408 |
} |
77396 | 409 |
else SHA1.no_shasum |
410 |
||
411 |
val log_lines = process_result.out_lines.filterNot(Protocol_Message.Marker.test) |
|
412 |
||
413 |
val build_log = |
|
414 |
Build_Log.Log_File(session_name, process_result.out_lines). |
|
415 |
parse_session_info( |
|
416 |
command_timings = true, |
|
417 |
theory_timings = true, |
|
418 |
ml_statistics = true, |
|
419 |
task_statistics = true) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
420 |
|
77396 | 421 |
// write log file |
422 |
if (process_result.ok) { |
|
423 |
File.write_gzip(store.output_log_gz(session_name), terminate_lines(log_lines)) |
|
424 |
} |
|
425 |
else File.write(store.output_log(session_name), terminate_lines(log_lines)) |
|
426 |
||
427 |
// write database |
|
428 |
using(store.open_database(session_name, output = true))(db => |
|
429 |
store.write_session_info(db, session_name, session_sources, |
|
430 |
build_log = |
|
431 |
if (process_result.timeout) build_log.error("Timeout") else build_log, |
|
432 |
build = |
|
433 |
Sessions.Build_Info(sources_shasum, input_heaps, output_heap, |
|
434 |
process_result.rc, UUID.random().toString))) |
|
435 |
||
436 |
// messages |
|
437 |
process_result.err_lines.foreach(progress.echo) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
438 |
|
77396 | 439 |
if (process_result.ok) { |
440 |
if (verbose) { |
|
441 |
progress.echo(Build_Job.session_timing(session_name, build_log.session_timing)) |
|
442 |
} |
|
443 |
progress.echo(Build_Job.session_finished(session_name, process_result.timing)) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
444 |
} |
77396 | 445 |
else { |
446 |
progress.echo( |
|
447 |
session_name + " FAILED (see also \"isabelle log -H Error " + session_name + "\")") |
|
448 |
if (!process_result.interrupted) { |
|
449 |
val tail = info.options.int("process_output_tail") |
|
450 |
val suffix = if (tail == 0) log_lines else log_lines.drop(log_lines.length - tail max 0) |
|
451 |
val prefix = if (log_lines.length == suffix.length) Nil else List("...") |
|
452 |
progress.echo(Library.trim_line(cat_lines(prefix ::: suffix))) |
|
453 |
} |
|
454 |
} |
|
455 |
||
456 |
(process_result.copy(out_lines = log_lines), output_heap) |
|
77297
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
457 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
458 |
} |
226a880d0423
clarified types: support a variety of Build_Job instances;
wenzelm
parents:
77294
diff
changeset
|
459 |
|
77396 | 460 |
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
461 |
/* theory markup/messages from session database */ |
72854 | 462 |
|
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
463 |
def read_theory( |
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
464 |
theory_context: Export.Theory_Context, |
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
465 |
unicode_symbols: Boolean = false |
76205 | 466 |
): Option[Document.Snapshot] = { |
76936 | 467 |
def decode_bytes(bytes: Bytes): String = |
468 |
Symbol.output(unicode_symbols, UTF8.decode_permissive(bytes)) |
|
469 |
||
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
470 |
def read(name: String): Export.Entry = theory_context(name, permissive = true) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
471 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
472 |
def read_xml(name: String): XML.Body = |
76936 | 473 |
YXML.parse_body(decode_bytes(read(name).bytes), cache = theory_context.cache) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
474 |
|
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
475 |
def read_source_file(name: String): Sessions.Source_File = |
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
476 |
theory_context.session_context.source_file(name) |
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
477 |
|
75733 | 478 |
for { |
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
479 |
id <- theory_context.document_id() |
75903 | 480 |
(thy_file, blobs_files) <- theory_context.files(permissive = true) |
75733 | 481 |
} |
482 |
yield { |
|
76881
b59118d11a46
clarified master_dir: avoid somewhat fragile Document.Node.Name.master_dir_path;
wenzelm
parents:
76879
diff
changeset
|
483 |
val master_dir = |
b59118d11a46
clarified master_dir: avoid somewhat fragile Document.Node.Name.master_dir_path;
wenzelm
parents:
76879
diff
changeset
|
484 |
Path.explode(Url.strip_base_name(thy_file).getOrElse( |
b59118d11a46
clarified master_dir: avoid somewhat fragile Document.Node.Name.master_dir_path;
wenzelm
parents:
76879
diff
changeset
|
485 |
error("Cannot determine theory master directory: " + quote(thy_file)))) |
b59118d11a46
clarified master_dir: avoid somewhat fragile Document.Node.Name.master_dir_path;
wenzelm
parents:
76879
diff
changeset
|
486 |
|
75733 | 487 |
val blobs = |
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
488 |
blobs_files.map { name => |
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
489 |
val path = Path.explode(name) |
76881
b59118d11a46
clarified master_dir: avoid somewhat fragile Document.Node.Name.master_dir_path;
wenzelm
parents:
76879
diff
changeset
|
490 |
val src_path = File.relative_path(master_dir, path).getOrElse(path) |
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
491 |
|
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
492 |
val file = read_source_file(name) |
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
493 |
val bytes = file.bytes |
76936 | 494 |
val text = decode_bytes(bytes) |
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
495 |
val chunk = Symbol.Text_Chunk(text) |
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
496 |
|
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
497 |
Command.Blob(Document.Node.Name(name), src_path, Some((file.digest, chunk))) -> |
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
498 |
Document.Blobs.Item(bytes, text, chunk, changed = false) |
75733 | 499 |
} |
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
500 |
|
76936 | 501 |
val thy_source = decode_bytes(read_source_file(thy_file).bytes) |
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
502 |
val thy_xml = read_xml(Export.MARKUP) |
75733 | 503 |
val blobs_xml = |
504 |
for (i <- (1 to blobs.length).toList) |
|
505 |
yield read_xml(Export.MARKUP + i) |
|
72865
ebf72a3b8daa
clarified file sources: take from build database instead of file-system;
wenzelm
parents:
72864
diff
changeset
|
506 |
|
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
507 |
val markups_index = Command.Markup_Index.make(blobs.map(_._1)) |
75733 | 508 |
val markups = |
509 |
Command.Markups.make( |
|
510 |
for ((index, xml) <- markups_index.zip(thy_xml :: blobs_xml)) |
|
511 |
yield index -> Markup_Tree.from_XML(xml)) |
|
512 |
||
76911 | 513 |
val results = |
514 |
Command.Results.make( |
|
515 |
for (elem @ XML.Elem(Markup(_, Markup.Serial(i)), _) <- read_xml(Export.MESSAGES)) |
|
516 |
yield i -> elem) |
|
517 |
||
76205 | 518 |
val command = |
76881
b59118d11a46
clarified master_dir: avoid somewhat fragile Document.Node.Name.master_dir_path;
wenzelm
parents:
76879
diff
changeset
|
519 |
Command.unparsed(thy_source, theory = true, id = id, |
b59118d11a46
clarified master_dir: avoid somewhat fragile Document.Node.Name.master_dir_path;
wenzelm
parents:
76879
diff
changeset
|
520 |
node_name = Document.Node.Name(thy_file, theory = theory_context.theory), |
76913 | 521 |
blobs_info = Command.Blobs_Info.make(blobs), |
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
522 |
markups = markups, results = results) |
76205 | 523 |
|
76913 | 524 |
val doc_blobs = Document.Blobs.make(blobs) |
76912
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
525 |
|
ca872f20cf5b
clarified session sources: theory and blobs are read from database, instead of physical file-system;
wenzelm
parents:
76911
diff
changeset
|
526 |
Document.State.init.snippet(command, doc_blobs) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
527 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
528 |
} |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
529 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
530 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
531 |
/* print messages */ |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
532 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
533 |
def print_log( |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
534 |
options: Options, |
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
535 |
sessions: List[String], |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
536 |
theories: List[String] = Nil, |
76087 | 537 |
message_head: List[Regex] = Nil, |
538 |
message_body: List[Regex] = Nil, |
|
72878 | 539 |
verbose: Boolean = false, |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
540 |
progress: Progress = new Progress, |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
541 |
margin: Double = Pretty.default_margin, |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
542 |
breakgain: Double = Pretty.default_breakgain, |
72873 | 543 |
metric: Pretty.Metric = Symbol.Metric, |
75393 | 544 |
unicode_symbols: Boolean = false |
545 |
): Unit = { |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
546 |
val store = Sessions.store(options) |
76654 | 547 |
val session = new Session(options, Resources.bootstrap) |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
548 |
|
76087 | 549 |
def check(filter: List[Regex], make_string: => String): Boolean = |
550 |
filter.isEmpty || { |
|
551 |
val s = Output.clean_yxml(make_string) |
|
552 |
filter.forall(r => r.findFirstIn(Output.clean_yxml(s)).nonEmpty) |
|
553 |
} |
|
554 |
||
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
555 |
def print(session_name: String): Unit = { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
556 |
using(Export.open_session_context0(store, session_name)) { session_context => |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
557 |
val result = |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
558 |
for { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
559 |
db <- session_context.session_db() |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
560 |
theories = store.read_theories(db, session_name) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
561 |
errors = store.read_errors(db, session_name) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
562 |
info <- store.read_build(db, session_name) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
563 |
} yield (theories, errors, info.return_code) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
564 |
result match { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
565 |
case None => store.error_database(session_name) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
566 |
case Some((used_theories, errors, rc)) => |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
567 |
theories.filterNot(used_theories.toSet) match { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
568 |
case Nil => |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
569 |
case bad => error("Unknown theories " + commas_quote(bad)) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
570 |
} |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
571 |
val print_theories = |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
572 |
if (theories.isEmpty) used_theories else used_theories.filter(theories.toSet) |
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
573 |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
574 |
for (thy <- print_theories) { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
575 |
val thy_heading = "\nTheory " + quote(thy) + " (in " + session_name + ")" + ":" |
75778
d18c96b9b955
prefer Export.Context/Session_Context/Theory_Context over Sessions.Database_Context;
wenzelm
parents:
75762
diff
changeset
|
576 |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
577 |
read_theory(session_context.theory(thy), unicode_symbols = unicode_symbols) match { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
578 |
case None => progress.echo(thy_heading + " MISSING") |
76205 | 579 |
case Some(snapshot) => |
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
580 |
val rendering = new Rendering(snapshot, options, session) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
581 |
val messages = |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
582 |
rendering.text_messages(Text.Range.full) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
583 |
.filter(message => verbose || Protocol.is_exported(message.info)) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
584 |
if (messages.nonEmpty) { |
76933 | 585 |
val line_document = Line.Document(snapshot.node.source) |
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
586 |
val buffer = new mutable.ListBuffer[String] |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
587 |
for (Text.Info(range, elem) <- messages) { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
588 |
val line = line_document.position(range.start).line1 |
76205 | 589 |
val pos = Position.Line_File(line, snapshot.node_name.node) |
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
590 |
def message_text: String = |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
591 |
Protocol.message_text(elem, heading = true, pos = pos, |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
592 |
margin = margin, breakgain = breakgain, metric = metric) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
593 |
val ok = |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
594 |
check(message_head, Protocol.message_heading(elem, pos)) && |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
595 |
check(message_body, XML.content(Pretty.unformatted(List(elem)))) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
596 |
if (ok) buffer += message_text |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
597 |
} |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
598 |
if (buffer.nonEmpty) { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
599 |
progress.echo(thy_heading) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
600 |
buffer.foreach(progress.echo) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
601 |
} |
76087 | 602 |
} |
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
603 |
} |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
604 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
605 |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
606 |
if (errors.nonEmpty) { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
607 |
val msg = Symbol.output(unicode_symbols, cat_lines(errors)) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
608 |
progress.echo("\nBuild errors:\n" + Output.error_message_text(msg)) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
609 |
} |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
610 |
if (rc != Process_Result.RC.ok) { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
611 |
progress.echo("\n" + Process_Result.RC.print_long(rc)) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
612 |
} |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
613 |
} |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
614 |
} |
75394 | 615 |
} |
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
616 |
|
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
617 |
val errors = new mutable.ListBuffer[String] |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
618 |
for (session_name <- sessions) { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
619 |
Exn.interruptible_capture(print(session_name)) match { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
620 |
case Exn.Res(_) => |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
621 |
case Exn.Exn(exn) => errors += Exn.message(exn) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
622 |
} |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
623 |
} |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
624 |
if (errors.nonEmpty) error(cat_lines(errors.toList)) |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
625 |
} |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
626 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
627 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
628 |
/* Isabelle tool wrapper */ |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
629 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
630 |
val isabelle_tool = Isabelle_Tool("log", "print messages from build database", |
75394 | 631 |
Scala_Project.here, |
632 |
{ args => |
|
633 |
/* arguments */ |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
634 |
|
76087 | 635 |
var message_head = List.empty[Regex] |
636 |
var message_body = List.empty[Regex] |
|
75394 | 637 |
var unicode_symbols = false |
638 |
var theories: List[String] = Nil |
|
639 |
var margin = Pretty.default_margin |
|
640 |
var options = Options.init() |
|
641 |
var verbose = false |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
642 |
|
75394 | 643 |
val getopts = Getopts(""" |
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
644 |
Usage: isabelle log [OPTIONS] [SESSIONS ...] |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
645 |
|
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
646 |
Options are: |
76087 | 647 |
-H REGEX filter messages by matching against head |
648 |
-M REGEX filter messages by matching against body |
|
72876 | 649 |
-T NAME restrict to given theories (multiple options possible) |
72867 | 650 |
-U output Unicode symbols |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
651 |
-m MARGIN margin for pretty printing (default: """ + margin + """) |
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
652 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
73837
f72335f6a9ed
clarified documentation: tracing messages are not shown here;
wenzelm
parents:
73835
diff
changeset
|
653 |
-v print all messages, including information etc. |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
654 |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
655 |
Print messages from the build database of the given sessions, without any |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
656 |
checks against current sources nor session structure: results from old |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
657 |
sessions or failed builds can be printed as well. |
76087 | 658 |
|
659 |
Multiple options -H and -M are conjunctive: all given patterns need to |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
660 |
match. Patterns match any substring, but ^ or $ may be used to match the |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
661 |
start or end explicitly. |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
662 |
""", |
76087 | 663 |
"H:" -> (arg => message_head = message_head ::: List(arg.r)), |
664 |
"M:" -> (arg => message_body = message_body ::: List(arg.r)), |
|
75394 | 665 |
"T:" -> (arg => theories = theories ::: List(arg)), |
666 |
"U" -> (_ => unicode_symbols = true), |
|
667 |
"m:" -> (arg => margin = Value.Double.parse(arg)), |
|
668 |
"o:" -> (arg => options = options + arg), |
|
669 |
"v" -> (_ => verbose = true)) |
|
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
670 |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
671 |
val sessions = getopts(args) |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
672 |
|
75394 | 673 |
val progress = new Console_Progress() |
72858
cb0c407fbc6e
added "isabelle log": print messages from build database;
wenzelm
parents:
72857
diff
changeset
|
674 |
|
76088
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
675 |
if (sessions.isEmpty) progress.echo_warning("No sessions to print") |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
676 |
else { |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
677 |
print_log(options, sessions, theories = theories, message_head = message_head, |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
678 |
message_body = message_body, verbose = verbose, margin = margin, progress = progress, |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
679 |
unicode_symbols = unicode_symbols) |
bec8677d0e5b
support multiple sessions, with cumulative errors;
wenzelm
parents:
76087
diff
changeset
|
680 |
} |
75394 | 681 |
}) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
682 |
} |