author | wenzelm |
Wed, 09 Dec 2020 15:53:45 +0100 | |
changeset 72857 | a9e091ccd450 |
parent 72856 | 3a27e6f83ce1 |
child 72858 | cb0c407fbc6e |
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 |
|
11 |
||
12 |
||
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
13 |
object Build_Job |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
14 |
{ |
72854 | 15 |
/* theory markup/messages from database */ |
16 |
||
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
17 |
def read_theory( |
72857 | 18 |
db_context: Sessions.Database_Context, |
19 |
resources: Resources, |
|
20 |
session: String, |
|
21 |
theory: String): Option[Command] = |
|
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
22 |
{ |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
23 |
def read(name: String): Export.Entry = |
72854 | 24 |
db_context.get_export(List(session), theory, name) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
25 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
26 |
def read_xml(name: String): XML.Body = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
27 |
db_context.xml_cache.body( |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
28 |
YXML.parse_body(Symbol.decode(UTF8.decode_permissive(read(name).uncompressed)))) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
29 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
30 |
(read(Export.DOCUMENT_ID).text, split_lines(read(Export.FILES).text)) match { |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
31 |
case (Value.Long(id), thy_file :: blobs_files) => |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
32 |
val thy_path = Path.explode(thy_file) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
33 |
val thy_source = Symbol.decode(File.read(thy_path)) |
72857 | 34 |
val node_name = resources.file_node(thy_path, theory = theory) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
35 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
36 |
val blobs = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
37 |
blobs_files.map(file => |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
38 |
{ |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
39 |
val path = Path.explode(file) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
40 |
val src_path = File.relative_path(thy_path, path).getOrElse(path) |
72857 | 41 |
Command.Blob.read_file(resources.file_node(path), src_path) |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
42 |
}) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
43 |
val blobs_info = Command.Blobs_Info(blobs.map(Exn.Res(_))) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
44 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
45 |
val results = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
46 |
Command.Results.make( |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
47 |
for { |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
48 |
tree @ XML.Elem(markup, _) <- read_xml(Export.MESSAGES) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
49 |
i <- Markup.Serial.unapply(markup.properties) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
50 |
} yield i -> tree) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
51 |
|
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
52 |
val markup_index_blobs = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
53 |
Command.Markup_Index.markup :: blobs.map(Command.Markup_Index.blob) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
54 |
val markups = |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
55 |
Command.Markups.make( |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
56 |
for ((index, i) <- markup_index_blobs.zipWithIndex) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
57 |
yield { |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
58 |
val xml = read_xml(Export.MARKUP + (if (i == 0) "" else i.toString)) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
59 |
index -> Markup_Tree.from_XML(xml) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
60 |
}) |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
61 |
|
72853
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
62 |
val command = |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
63 |
Command.unparsed(thy_source, theory = true, id = id, node_name = node_name, |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
64 |
blobs_info = blobs_info, results = results, markups = markups) |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
65 |
Some(command) |
d0038b553e0e
clarified signature: name according to db model without Sessions.Structure/Deps;
wenzelm
parents:
72849
diff
changeset
|
66 |
case _ => None |
72848
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
67 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
68 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
69 |
} |
d5d0e36eda16
read theory with PIDE markup from session database;
wenzelm
parents:
72844
diff
changeset
|
70 |
|
72662 | 71 |
class Build_Job(progress: Progress, |
72 |
session_name: String, |
|
73 |
val info: Sessions.Info, |
|
74 |
deps: Sessions.Deps, |
|
75 |
store: Sessions.Store, |
|
76 |
do_store: Boolean, |
|
77 |
verbose: Boolean, |
|
78 |
val numa_node: Option[Int], |
|
79 |
command_timings0: List[Properties.T]) |
|
80 |
{ |
|
81 |
val options: Options = NUMA.policy_options(info.options, numa_node) |
|
82 |
||
83 |
private val sessions_structure = deps.sessions_structure |
|
84 |
||
85 |
private val future_result: Future[Process_Result] = |
|
86 |
Future.thread("build", uninterruptible = true) { |
|
87 |
val parent = info.parent.getOrElse("") |
|
88 |
val base = deps(parent) |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
89 |
val result_base = deps(session_name) |
72662 | 90 |
|
91 |
val env = |
|
92 |
Isabelle_System.settings() + |
|
93 |
("ISABELLE_ML_DEBUGGER" -> options.bool("ML_debugger").toString) |
|
94 |
||
95 |
val is_pure = Sessions.is_pure(session_name) |
|
96 |
||
97 |
val use_prelude = if (is_pure) Thy_Header.ml_roots.map(_._1) else Nil |
|
98 |
||
99 |
val eval_store = |
|
100 |
if (do_store) { |
|
101 |
(if (info.theories.nonEmpty) List("ML_Heap.share_common_data ()") else Nil) ::: |
|
102 |
List("ML_Heap.save_child " + |
|
103 |
ML_Syntax.print_string_bytes(File.platform_path(store.output_heap(session_name)))) |
|
104 |
} |
|
105 |
else Nil |
|
106 |
||
107 |
val resources = new Resources(sessions_structure, base, command_timings = command_timings0) |
|
108 |
val session = |
|
109 |
new Session(options, resources) { |
|
110 |
override val xml_cache: XML.Cache = store.xml_cache |
|
111 |
override val xz_cache: XZ.Cache = store.xz_cache |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
112 |
|
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
113 |
override def build_blobs_info(name: Document.Node.Name): Command.Blobs_Info = |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
114 |
{ |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
115 |
result_base.load_commands.get(name.expand) match { |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
116 |
case Some(spans) => |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
117 |
val syntax = result_base.theory_syntax(name) |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
118 |
Command.build_blobs_info(syntax, name, spans) |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
119 |
case None => Command.Blobs_Info.none |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
120 |
} |
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
121 |
} |
72662 | 122 |
} |
123 |
||
124 |
object Build_Session_Errors |
|
125 |
{ |
|
126 |
private val promise: Promise[List[String]] = Future.promise |
|
127 |
||
128 |
def result: Exn.Result[List[String]] = promise.join_result |
|
129 |
def cancel: Unit = promise.cancel |
|
130 |
def apply(errs: List[String]) |
|
131 |
{ |
|
132 |
try { promise.fulfill(errs) } |
|
133 |
catch { case _: IllegalStateException => } |
|
134 |
} |
|
135 |
} |
|
136 |
||
137 |
val export_consumer = |
|
72849 | 138 |
Export.consumer(store.open_database(session_name, output = true), store.xz_cache) |
72662 | 139 |
|
140 |
val stdout = new StringBuilder(1000) |
|
141 |
val stderr = new StringBuilder(1000) |
|
142 |
val messages = new mutable.ListBuffer[XML.Elem] |
|
143 |
val command_timings = new mutable.ListBuffer[Properties.T] |
|
144 |
val theory_timings = new mutable.ListBuffer[Properties.T] |
|
145 |
val session_timings = new mutable.ListBuffer[Properties.T] |
|
146 |
val runtime_statistics = new mutable.ListBuffer[Properties.T] |
|
147 |
val task_statistics = new mutable.ListBuffer[Properties.T] |
|
148 |
||
149 |
def fun( |
|
150 |
name: String, |
|
151 |
acc: mutable.ListBuffer[Properties.T], |
|
152 |
unapply: Properties.T => Option[Properties.T]): (String, Session.Protocol_Function) = |
|
153 |
{ |
|
154 |
name -> ((msg: Prover.Protocol_Output) => |
|
155 |
unapply(msg.properties) match { |
|
156 |
case Some(props) => acc += props; true |
|
157 |
case _ => false |
|
158 |
}) |
|
159 |
} |
|
160 |
||
161 |
session.init_protocol_handler(new Session.Protocol_Handler |
|
162 |
{ |
|
163 |
override def exit() { Build_Session_Errors.cancel } |
|
164 |
||
165 |
private def build_session_finished(msg: Prover.Protocol_Output): Boolean = |
|
166 |
{ |
|
167 |
val (rc, errors) = |
|
168 |
try { |
|
169 |
val (rc, errs) = |
|
170 |
{ |
|
171 |
import XML.Decode._ |
|
172 |
pair(int, list(x => x))(Symbol.decode_yxml(msg.text)) |
|
173 |
} |
|
174 |
val errors = |
|
175 |
for (err <- errs) yield { |
|
176 |
val prt = Protocol_Message.expose_no_reports(err) |
|
177 |
Pretty.string_of(prt, metric = Symbol.Metric) |
|
178 |
} |
|
179 |
(rc, errors) |
|
180 |
} |
|
181 |
catch { case ERROR(err) => (2, List(err)) } |
|
182 |
||
183 |
session.protocol_command("Prover.stop", rc.toString) |
|
184 |
Build_Session_Errors(errors) |
|
185 |
true |
|
186 |
} |
|
187 |
||
188 |
private def loading_theory(msg: Prover.Protocol_Output): Boolean = |
|
189 |
msg.properties match { |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
190 |
case Markup.Loading_Theory(Markup.Name(name)) => |
72662 | 191 |
progress.theory(Progress.Theory(name, session = session_name)) |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
192 |
false |
72662 | 193 |
case _ => false |
194 |
} |
|
195 |
||
196 |
private def export(msg: Prover.Protocol_Output): Boolean = |
|
197 |
msg.properties match { |
|
198 |
case Protocol.Export(args) => |
|
199 |
export_consumer(session_name, args, msg.bytes) |
|
200 |
true |
|
201 |
case _ => false |
|
202 |
} |
|
203 |
||
204 |
override val functions = |
|
205 |
List( |
|
206 |
Markup.Build_Session_Finished.name -> build_session_finished, |
|
207 |
Markup.Loading_Theory.name -> loading_theory, |
|
208 |
Markup.EXPORT -> export, |
|
209 |
fun(Markup.Theory_Timing.name, theory_timings, Markup.Theory_Timing.unapply), |
|
210 |
fun(Markup.Session_Timing.name, session_timings, Markup.Session_Timing.unapply), |
|
211 |
fun(Markup.Task_Statistics.name, task_statistics, Markup.Task_Statistics.unapply)) |
|
212 |
}) |
|
213 |
||
72711 | 214 |
session.command_timings += Session.Consumer("command_timings") |
215 |
{ |
|
216 |
case Session.Command_Timing(props) => |
|
217 |
for { |
|
218 |
elapsed <- Markup.Elapsed.unapply(props) |
|
219 |
elapsed_time = Time.seconds(elapsed) |
|
220 |
if elapsed_time.is_relevant && elapsed_time >= options.seconds("command_timing_threshold") |
|
221 |
} command_timings += props.filter(Markup.command_timing_property) |
|
222 |
} |
|
223 |
||
72662 | 224 |
session.runtime_statistics += Session.Consumer("ML_statistics") |
225 |
{ |
|
226 |
case Session.Runtime_Statistics(props) => runtime_statistics += props |
|
227 |
} |
|
228 |
||
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
229 |
session.finished_theories += Session.Consumer[Document.Snapshot]("finished_theories") |
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
230 |
{ |
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
231 |
case snapshot => |
72856 | 232 |
val rendering = new Rendering(snapshot, options, session) |
72730 | 233 |
|
72844 | 234 |
def export(name: String, xml: XML.Body, compress: Boolean = true) |
72717 | 235 |
{ |
72721
79f5e843e5ec
clarified signature: prefer high-level Snapshot over low-level Command.State;
wenzelm
parents:
72717
diff
changeset
|
236 |
val theory_name = snapshot.node_name.theory |
72844 | 237 |
val args = |
238 |
Protocol.Export.Args(theory_name = theory_name, name = name, compress = compress) |
|
72783 | 239 |
val bytes = Bytes(Symbol.encode(YXML.string_of_body(xml))) |
72730 | 240 |
if (!bytes.is_empty) export_consumer(session_name, args, bytes) |
72717 | 241 |
} |
72844 | 242 |
def export_text(name: String, text: String, compress: Boolean = true): Unit = |
243 |
export(name, List(XML.Text(text)), compress = compress) |
|
72730 | 244 |
|
72844 | 245 |
for (command <- snapshot.snippet_command) { |
246 |
export_text(Export.DOCUMENT_ID, command.id.toString, compress = false) |
|
247 |
} |
|
248 |
||
249 |
export_text(Export.FILES, |
|
250 |
cat_lines(snapshot.node_files.map(_.symbolic.node)), compress = false) |
|
72816
ea4f86914cb2
support for PIDE markup for auxiliary files ("blobs");
wenzelm
parents:
72783
diff
changeset
|
251 |
|
72817
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
252 |
for ((xml, i) <- snapshot.xml_markup_blobs().zipWithIndex) { |
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
253 |
export(Export.MARKUP + (i + 1), xml) |
1c378ab75d48
clarified signature, notably access to blob files;
wenzelm
parents:
72816
diff
changeset
|
254 |
} |
72723 | 255 |
export(Export.MARKUP, snapshot.xml_markup()) |
72725 | 256 |
export(Export.MESSAGES, snapshot.messages.map(_._1)) |
72730 | 257 |
|
258 |
val citations = Library.distinct(rendering.citations(Text.Range.full).map(_.info)) |
|
259 |
export_text(Export.CITATIONS, cat_lines(citations)) |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
260 |
} |
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72683
diff
changeset
|
261 |
|
72662 | 262 |
session.all_messages += Session.Consumer[Any]("build_session_output") |
263 |
{ |
|
264 |
case msg: Prover.Output => |
|
265 |
val message = msg.message |
|
266 |
if (msg.is_stdout) { |
|
267 |
stdout ++= Symbol.encode(XML.content(message)) |
|
268 |
} |
|
269 |
else if (msg.is_stderr) { |
|
270 |
stderr ++= Symbol.encode(XML.content(message)) |
|
271 |
} |
|
272 |
else if (Protocol.is_exported(message)) { |
|
273 |
messages += message |
|
274 |
} |
|
275 |
else if (msg.is_exit) { |
|
276 |
val err = |
|
277 |
"Prover terminated" + |
|
278 |
(msg.properties match { |
|
279 |
case Markup.Process_Result(result) => ": " + result.print_rc |
|
280 |
case _ => "" |
|
281 |
}) |
|
282 |
Build_Session_Errors(List(err)) |
|
283 |
} |
|
284 |
case _ => |
|
285 |
} |
|
286 |
||
287 |
val eval_main = Command_Line.ML_tool("Isabelle_Process.init_build ()" :: eval_store) |
|
288 |
||
289 |
val process = |
|
290 |
Isabelle_Process(session, options, sessions_structure, store, |
|
291 |
logic = parent, raw_ml_system = is_pure, |
|
292 |
use_prelude = use_prelude, eval_main = eval_main, |
|
293 |
cwd = info.dir.file, env = env) |
|
294 |
||
295 |
val build_errors = |
|
296 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { |
|
297 |
Exn.capture { process.await_startup } match { |
|
298 |
case Exn.Res(_) => |
|
299 |
val resources_yxml = resources.init_session_yxml |
|
300 |
val args_yxml = |
|
301 |
YXML.string_of_body( |
|
302 |
{ |
|
303 |
import XML.Encode._ |
|
304 |
pair(string, list(pair(Options.encode, list(pair(string, properties)))))( |
|
305 |
(session_name, info.theories)) |
|
306 |
}) |
|
307 |
session.protocol_command("build_session", resources_yxml, args_yxml) |
|
308 |
Build_Session_Errors.result |
|
309 |
case Exn.Exn(exn) => Exn.Res(List(Exn.message(exn))) |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
val process_result = |
|
314 |
Isabelle_Thread.interrupt_handler(_ => process.terminate) { process.await_shutdown } |
|
315 |
||
72697 | 316 |
session.stop() |
317 |
||
72662 | 318 |
val export_errors = |
319 |
export_consumer.shutdown(close = true).map(Output.error_message_text) |
|
320 |
||
72699 | 321 |
val (document_output, document_errors) = |
72662 | 322 |
try { |
72675 | 323 |
if (build_errors.isInstanceOf[Exn.Res[_]] && process_result.ok && info.documents.nonEmpty) |
324 |
{ |
|
72854 | 325 |
using(store.open_database_context())(db_context => |
72715
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
326 |
{ |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
327 |
val documents = |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
328 |
Presentation.build_documents(session_name, deps, db_context, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
329 |
output_sources = info.document_output, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
330 |
output_pdf = info.document_output, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
331 |
progress = progress, |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
332 |
verbose = verbose) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
333 |
db_context.output_database(session_name)(db => |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
334 |
documents.foreach(_.write(db, session_name))) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
335 |
(documents.flatMap(_.log_lines), Nil) |
2615b8c05337
clarified signature --- avoid repeated open_database on server;
wenzelm
parents:
72711
diff
changeset
|
336 |
}) |
72662 | 337 |
} |
72699 | 338 |
(Nil, Nil) |
72662 | 339 |
} |
72699 | 340 |
catch { case Exn.Interrupt.ERROR(msg) => (Nil, List(msg)) } |
72662 | 341 |
|
342 |
val result = |
|
343 |
{ |
|
72738
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
344 |
val theory_timing = |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
345 |
theory_timings.iterator.map( |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
346 |
{ case props @ Markup.Name(name) => name -> props }).toMap |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
347 |
val used_theory_timings = |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
348 |
for { (name, _) <- deps(session_name).used_theories } |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
349 |
yield theory_timing.getOrElse(name.theory, Markup.Name(name.theory)) |
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
350 |
|
72662 | 351 |
val more_output = |
352 |
Library.trim_line(stdout.toString) :: |
|
353 |
messages.toList.map(message => |
|
354 |
Symbol.encode(Protocol.message_text(List(message), metric = Symbol.Metric))) ::: |
|
355 |
command_timings.toList.map(Protocol.Command_Timing_Marker.apply) ::: |
|
72738
a4d7da18ac5c
store timings for used_theories in canonical order, with reconstructed store.read_theories;
wenzelm
parents:
72730
diff
changeset
|
356 |
used_theory_timings.map(Protocol.Theory_Timing_Marker.apply) ::: |
72662 | 357 |
session_timings.toList.map(Protocol.Session_Timing_Marker.apply) ::: |
358 |
runtime_statistics.toList.map(Protocol.ML_Statistics_Marker.apply) ::: |
|
359 |
task_statistics.toList.map(Protocol.Task_Statistics_Marker.apply) ::: |
|
72699 | 360 |
document_output |
72662 | 361 |
|
72726
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
362 |
process_result.output(more_output) |
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
363 |
.error(Library.trim_line(stderr.toString)) |
ec6a27bbdab8
proper return code for more errors (amending d892f6d66402);
wenzelm
parents:
72725
diff
changeset
|
364 |
.errors_rc(export_errors ::: document_errors) |
72662 | 365 |
} |
366 |
||
367 |
build_errors match { |
|
368 |
case Exn.Res(build_errs) => |
|
369 |
val errs = build_errs ::: document_errors |
|
370 |
if (errs.isEmpty) result |
|
371 |
else { |
|
372 |
result.error_rc.output( |
|
373 |
errs.flatMap(s => split_lines(Output.error_message_text(s))) ::: |
|
374 |
errs.map(Protocol.Error_Message_Marker.apply)) |
|
375 |
} |
|
376 |
case Exn.Exn(Exn.Interrupt()) => |
|
377 |
if (result.ok) result.copy(rc = Exn.Interrupt.return_code) else result |
|
378 |
case Exn.Exn(exn) => throw exn |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
def terminate: Unit = future_result.cancel |
|
383 |
def is_finished: Boolean = future_result.is_finished |
|
384 |
||
385 |
private val timeout_request: Option[Event_Timer.Request] = |
|
386 |
{ |
|
387 |
if (info.timeout > Time.zero) |
|
388 |
Some(Event_Timer.request(Time.now() + info.timeout) { terminate }) |
|
389 |
else None |
|
390 |
} |
|
391 |
||
392 |
def join: (Process_Result, Option[String]) = |
|
393 |
{ |
|
394 |
val result1 = future_result.join |
|
395 |
||
396 |
val was_timeout = |
|
397 |
timeout_request match { |
|
398 |
case None => false |
|
399 |
case Some(request) => !request.cancel |
|
400 |
} |
|
401 |
||
402 |
val result2 = |
|
403 |
if (result1.interrupted) { |
|
404 |
if (was_timeout) result1.error(Output.error_message_text("Timeout")).was_timeout |
|
405 |
else result1.error(Output.error_message_text("Interrupt")) |
|
406 |
} |
|
407 |
else result1 |
|
408 |
||
409 |
val heap_digest = |
|
410 |
if (result2.ok && do_store && store.output_heap(session_name).is_file) |
|
411 |
Some(Sessions.write_heap_digest(store.output_heap(session_name))) |
|
412 |
else None |
|
413 |
||
414 |
(result2, heap_digest) |
|
415 |
} |
|
416 |
} |